Created
August 29, 2012 17:07
-
-
Save yreynhout/3515704 to your computer and use it in GitHub Desktop.
Sample 1 - before
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class CurrentPortfolioProjection : | |
IHandle<AddedRealtyToPortfolio>, | |
IHandle<RemovedRealtyFromPortfolio> { | |
Func<PortfolioContext> _contextFactory; | |
public CurrentPortfolioProjection(Func<PortfolioContext> contextFactory) { | |
_contextFactory = contextFactory; | |
} | |
public void Handle(AddedRealtyToPortfolio @event) { | |
using(var context = _contextFactory()) { | |
context.CurrentPortfolioEntry.Add( | |
new CurrentPortfolioEntry( | |
@event.PortfolioId, @event.RealtyId, | |
@event.RealtySummary, @event.RealtySlideshowUrl, | |
@event.RealtyPropertySheetUrl, @event.RealtyFloorPlanUrl)); | |
context.SaveChanges(); | |
} | |
} | |
public void Handle(RemovedRealtyFromPortfolio @event) { | |
using(var context = _contextFactory()) { | |
var currentPortfolioEntry = | |
context.CurrentPortfolioEntry.Single( | |
entry => | |
entry.PortfolioId == @event.PortfolioId && | |
entry.RealtyId == @event.RealtyId); | |
context.CurrentPortfolioEntry.Remove(currentPortfolioEntry); | |
context.SaveChanges(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment