public static Func <Task> GetHandler( IAsyncDocumentSession session, object @event ) { return(@event switch { V1.OrderCreated e => () => session.Create(e.FromCreated), V1.ServiceActivated e => () => UpdateActiveServices( e.ClassifiedAdId, services => services.Add( new AdActiveServices.Service { ServiceType = e.ServiceType } ) ), V1.ServiceDeactivated e => () => UpdateActiveServices( e.ClassifiedAdId, services => services.RemoveAll( x => x.ServiceType == e.ServiceType ) ), _ => (Func <Task>)null });
public static Func <Task> GetHandler( IAsyncDocumentSession session, object @event ) { return(@event switch { V1.OrderCreated e => () => session.Create <OrderDraft>( x => { x.Id = DbId(e.OrderId); x.CustomerId = e.CustomerId.ToString(); x.ClassifiedAdId = e.ClassifiedAdId.ToString(); x.Services = new List <OrderDraft.Service>(); } ), V1.ServiceAddedToOrder e => () => session.Update <OrderDraft>( DbId(e.OrderId), x => x.Services.Add( new OrderDraft.Service { Type = e.ServiceType, Description = e.Description, Price = e.Price } ) ), V1.ServiceRemovedFromOrder e => () => session.Update <OrderDraft>( DbId(e.OrderId), x => x.Services.RemoveAll(s => s.Type == e.ServiceType) ), V1.OrderFulfilled e => () => session.Del(DbId(e.OrderId)), V1.OrderDeleted e => () => session.Del(DbId(e.OrderId)), _ => (Func <Task>)null });