예제 #1
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();
     }
 }
예제 #2
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);
         }
     }
 }