예제 #1
0
        public Advert Update(Advert advert, AdvertDto fromDto)
        {
            var resultingAdvert = BuildNew(fromDto);

            resultingAdvert.Status = advert.Status;
            resultingAdvert.Update();
            return(resultingAdvert);
        }
예제 #2
0
 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();
     }
 }
예제 #3
0
 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.");
     }
 }
예제 #4
0
        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);
        }
예제 #5
0
 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);
         }
     }
 }
예제 #6
0
 protected void SaveEvents(Advert advert)
 {
     Repository.Save(advert);
 }
예제 #7
0
 internal void DeleteAdvert(Advert advert)
 {
     _readModel.Adverts.Attach(advert);
     _readModel.Entry(advert).State = EntityState.Deleted;
     _readModel.SaveChanges();
 }
예제 #8
0
 internal void SaveAdvert(Advert advert)
 {
     _readModel.Adverts.Add(advert);
     _readModel.SaveChanges();
 }