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

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