public async Task Handle(Events.Drafted e, IMessageHandlerContext ctx) { var day = e.Stamp.FromUnix().Date; // get all items in basket var itemIds = await ctx.Service <Basket.Basket.Entities.Item.Services.ItemsInBasket, string[]>(x => { x.BasketId = e.BasketId; }) .ConfigureAwait(false); var items = await itemIds.SelectAsync(id => { return(ctx.UoW().Get <Basket.Basket.Entities.Item.Models.BasketItemIndex>(id)); }).ConfigureAwait(false); var existing = await ctx.UoW().TryGet <Models.SalesWeekOverWeek>(IdGenerator(day)).ConfigureAwait(false); if (existing == null) { existing = new Models.SalesWeekOverWeek { Id = IdGenerator(day), Relevancy = day.StartOfWeek().ToUnix(), DayOfWeek = day.DayOfWeek.ToString(), Value = items.Sum(x => x.SubTotal) }; await ctx.UoW().Add(existing.Id, existing).ConfigureAwait(false); } else { // todo: add additional fees when additional fees exist existing.Value += items.Sum(x => x.SubTotal); await ctx.UoW().Update(existing.Id, existing).ConfigureAwait(false); } }
public async Task Handle(Events.Drafted e, IMessageHandlerContext ctx) { var basket = await ctx.UoW().Get <Basket.Basket.Models.BasketIndex>(e.OrderId) .ConfigureAwait(false); var buyer = await ctx.UoW().Get <Buyer.Models.OrderingBuyerIndex>(e.UserName) .ConfigureAwait(false); var shipping = await ctx.UoW().Get <Buyer.Entities.Address.Models.Address>(e.ShippingAddressId).ConfigureAwait(false); var billing = await ctx.UoW().Get <Buyer.Entities.Address.Models.Address>(e.BillingAddressId).ConfigureAwait(false); var method = await ctx.UoW().Get <Buyer.Entities.PaymentMethod.Models.PaymentMethod>(e.PaymentMethodId).ConfigureAwait(false); // get all items in basket var itemIds = await ctx.Service <Basket.Basket.Entities.Item.Services.ItemsInBasket, string[]>(x => { x.BasketId = e.BasketId; }) .ConfigureAwait(false); var items = await itemIds.SelectAsync(id => { return(ctx.UoW().Get <Basket.Basket.Entities.Item.Models.BasketItemIndex>(id)); }).ConfigureAwait(false); var model = new Models.OrderingOrderIndex { Id = e.OrderId, UserName = buyer.Id, BuyerName = buyer.GivenName, Status = Status.Submitted.Value, StatusDescription = Status.Submitted.Description, ShippingAddressId = shipping.Id, ShippingAddress = shipping.Street, ShippingCity = shipping.City, ShippingState = shipping.State, ShippingZipCode = shipping.ZipCode, ShippingCountry = shipping.Country, BillingAddressId = billing.Id, BillingAddress = billing.Street, BillingCity = shipping.City, BillingState = shipping.State, BillingZipCode = billing.ZipCode, BillingCountry = billing.Country, PaymentMethodId = method.Id, PaymentMethod = Buyer.Entities.PaymentMethod.CardType.FromValue(method.CardType).Value, TotalItems = items.Count(), SubTotal = items.Sum(x => x.SubTotal), TotalQuantity = items.Sum(x => x.Quantity), Created = e.Stamp, Updated = e.Stamp }; await ctx.UoW().Add(e.OrderId, model).ConfigureAwait(false); }
public async Task Handle(Events.Drafted e, IMessageHandlerContext ctx) { var day = e.Stamp.FromUnix().Date; var month = new DateTime(day.Year, day.Month, 1); var address = await ctx.UoW().Get <Buyer.Entities.Address.Models.Address>(e.ShippingAddressId).ConfigureAwait(false); // get all items in basket var itemIds = await ctx.Service <Basket.Basket.Entities.Item.Services.ItemsInBasket, string[]>(x => { x.BasketId = e.BasketId; }) .ConfigureAwait(false); var items = await itemIds.SelectAsync(id => { return(ctx.UoW().Get <Basket.Basket.Entities.Item.Models.BasketItemIndex>(id)); }).ConfigureAwait(false); var existing = await ctx.UoW().TryGet <Models.SalesByState>(IdGenerator(month, address.State)).ConfigureAwait(false); if (existing == null) { existing = new Models.SalesByState { Id = IdGenerator(month, address.State), Relevancy = month.ToUnix(), State = address.State, Value = items.Sum(x => x.SubTotal) }; await ctx.UoW().Add(existing.Id, existing).ConfigureAwait(false); } else { // todo: add additional fees when additional fees exist existing.Value += items.Sum(x => x.SubTotal); await ctx.UoW().Update(existing.Id, existing).ConfigureAwait(false); } }
public async Task Handle(Events.Drafted e, IMessageHandlerContext ctx) { var basket = await ctx.UoW().Get <Basket.Basket.Models.Basket>(e.OrderId) .ConfigureAwait(false); var buyer = await ctx.UoW().Get <Buyer.Models.OrderingBuyer>(e.UserName) .ConfigureAwait(false); var billing = await ctx.UoW().Get <Buyer.Entities.Address.Models.Address>(e.BillingAddressId).ConfigureAwait(false); var shipping = await ctx.UoW().Get <Buyer.Entities.Address.Models.Address>(e.ShippingAddressId).ConfigureAwait(false); var method = await ctx.UoW().Get <Buyer.Entities.PaymentMethod.Models.PaymentMethod>(e.PaymentMethodId).ConfigureAwait(false); // get all items in basket var itemIds = await ctx.Service <Basket.Basket.Entities.Item.Services.ItemsInBasket, string[]>(x => { x.BasketId = e.BasketId; }) .ConfigureAwait(false); var items = await itemIds.SelectAsync(id => { return(ctx.UoW().Get <Basket.Basket.Entities.Item.Models.BasketItem>(id)); }).ConfigureAwait(false); var model = new Models.OrderingOrder { Id = e.OrderId, UserName = buyer.Id, BuyerName = buyer.GivenName, Status = Status.Submitted.Value, StatusDescription = Status.Submitted.Description, ShippingAddressId = shipping.Id, ShippingAddress = shipping.Street, ShippingCityState = $"{shipping.City}, {shipping.State}", ShippingZipCode = shipping.ZipCode, ShippingCountry = shipping.Country, BillingAddressId = billing.Id, BillingAddress = billing.Street, BillingCityState = $"{billing.City}, {billing.State}", BillingZipCode = billing.ZipCode, BillingCountry = billing.Country, PaymentMethodId = method.Id, PaymentMethod = Buyer.Entities.PaymentMethod.CardType.FromValue(method.CardType).Value, Created = e.Stamp, Updated = e.Stamp, Items = items.Select(x => new Entities.Item.Models.OrderingOrderItem { Id = x.Id, OrderId = e.OrderId, ProductId = x.ProductId, ProductName = x.ProductName, ProductDescription = x.ProductDescription, ProductPictureContents = x.ProductPictureContents, ProductPictureContentType = x.ProductPictureContentType, ProductPrice = x.ProductPrice, Quantity = x.Quantity }).ToArray() }; await ctx.UoW().Add(e.OrderId, model).ConfigureAwait(false); }
private void Handle(Events.Drafted e) { UserName = e.UserName; }