Esempio n. 1
0
        public Advert Update(Advert advert, AdvertDto fromDto)
        {
            var resultingAdvert = BuildNew(fromDto);

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