Example #1
0
 public static Func <Task> GetHandler(
     IAsyncDocumentSession session,
     object @event)
 {
     return(@event switch
     {
         Events.V1.ClassifiedAdCreated e =>
         () => Create(e.Id, e.OwnerId),
         Events.V1.ClassifiedAdTitleChanged e =>
         () => Update(e.Id, ad => ad.Title = e.Title),
         Events.V1.ClassifiedAdTextUpdated e =>
         () => Update(e.Id, ad => ad.Description = e.AdText),
         Events.V1.ClassifiedAdPriceUpdated e =>
         () => Update(e.Id,
                      ad =>
         {
             ad.Price = e.Price;
             ad.CurrencyCode = e.CurrencyCode;
         }),
         Events.V1.PictureAddedToAClassifiedAd e =>
         () => Update(e.ClassifiedAdId,
                      ad => ad.PhotoUrls.Add(e.Url)),
         Events.V1.ClassifiedAdDeleted e =>
         () => Delete(e.Id),
         _ => (Func <Task>)null
     });
Example #2
0
        public static Func <Task> GetHandler(
            IAsyncDocumentSession session,
            object @event)
        {
            Func <Guid, string> getDbId = ReadModels.MyClassifiedAds.GetDatabaseId;

            return(@event switch
            {
                Events.V1.ClassifiedAdCreated e =>
                () => CreateOrUpdate(e.OwnerId,
                                     myAds => myAds.MyAds.Add(
                                         new ReadModels.MyClassifiedAds.MyAd {
                    Id = e.Id
                }
                                         ),
                                     () => new ReadModels.MyClassifiedAds
                {
                    Id = getDbId(e.OwnerId),
                    MyAds = new List <ReadModels.MyClassifiedAds.MyAd>()
                }),
                Events.V1.ClassifiedAdTitleChanged e =>
                () => UpdateOneAd(e.OwnerId, e.Id,
                                  myAd => myAd.Title = e.Title),
                Events.V1.ClassifiedAdTextUpdated e =>
                () => UpdateOneAd(e.OwnerId, e.Id,
                                  myAd => myAd.Description = e.AdText),
                Events.V1.ClassifiedAdPriceUpdated e =>
                () => UpdateOneAd(e.OwnerId, e.Id,
                                  myAd => myAd.Price = e.Price),
                Events.V1.PictureAddedToAClassifiedAd e =>
                () => UpdateOneAd(e.OwnerId, e.ClassifiedAdId,
                                  myAd => myAd.PhotoUrls.Add(e.Url)),
                Events.V1.ClassifiedAdDeleted e =>
                () => Update(e.OwnerId,
                             myAd => myAd.MyAds
                             .RemoveAll(x => x.Id == e.Id)),
                _ => (Func <Task>)null
            });