Skip to content

Instantly share code, notes, and snippets.

@yreynhout
Created August 29, 2012 17:07
Show Gist options
  • Save yreynhout/3515704 to your computer and use it in GitHub Desktop.
Save yreynhout/3515704 to your computer and use it in GitHub Desktop.
Sample 1 - before
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