public Advert Update(Advert advert, AdvertDto fromDto) { var resultingAdvert = BuildNew(fromDto); resultingAdvert.Status = advert.Status; resultingAdvert.Update(); return(resultingAdvert); }
internal void Save(Advert item) { foreach (var e in item.GetChanges()) { var p = Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(e)); var ev = new EventData(Guid.NewGuid(), e.GetType().Name, true, p, null); _writeModel.AppendToStreamAsync($"Advert-{item.Id}", ExpectedVersion.Any, ev).Wait(); } }
protected void SendEventNotifications(Advert advert) { if (_messageBroker != null) { _messageBroker.SendMessagesFor(advert); } else { throw new InvalidOperationException("An Attempt was made to send messages with no instance of a Message Handler."); } }
public Advert BuildNew(AdvertDto buildData) { ValidateInput(buildData); var resultingAdvert = new Advert( buildData.Id, LookupItem.GetFromCache <CatchType>(_cache, (int)buildData.CatchTypeId), (double)buildData.Price, LookupItem.GetFromCache <Advertiser>(_cache, (int)buildData.AdvertiserId)); resultingAdvert.Pitch = buildData.Pitch; resultingAdvert.FishingMethod = (FishingMethod)(buildData.FishingMethod ?? (int)FishingMethod.Unknown); return(resultingAdvert); }
protected void RefreshReadModel(Advert advert) { foreach (var item in advert.GetChanges()) { if (item.GetType().Name == "AdvertCreatedEvent") { Repository.SaveCreatedAdvert(advert); } if (item.GetType().Name == "AdvertUpdatedEvent" || item.GetType().Name == "StockLevelChangedEvent") { Repository.UpdateAdvert(advert); } if (item.GetType().Name == "AdvertPostedEvent" || item.GetType().Name == "AdvertPublishedEvent" || item.GetType().Name == "AdvertWithdrawnEvent") { Repository.DeleteAdvert(advert); Repository.SaveAdvert(advert); } } }
protected void SaveEvents(Advert advert) { Repository.Save(advert); }
internal void DeleteAdvert(Advert advert) { _readModel.Adverts.Attach(advert); _readModel.Entry(advert).State = EntityState.Deleted; _readModel.SaveChanges(); }
internal void SaveAdvert(Advert advert) { _readModel.Adverts.Add(advert); _readModel.SaveChanges(); }