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

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