コード例 #1
0
ファイル: InvoiceAppService.cs プロジェクト: MRebati/Eron
        public async Task <InvoiceDto> CreateInvoiceByCart()
        {
            var userId    = HttpContext.Current.User.Identity.GetUserId();
            var cartItems = await UnitOfWork.CartRepository.GetUserUnpaidCartList(userId);

            var invoice = new Eron.Core.Entities.Financial.Base.Invoice()
            {
                ExpireDateTime = DateTime.Now.AddDays(1),
                InvoiceNumber  = GenerateNewInvoiceId(),
                UserId         = userId,
                InvoiceStatus  = InvoiceStatusType.WaitingForPayment,
                Type           = InvoiceType.Cart
            };

            invoice.CheckProgress();

            foreach (var item in cartItems)
            {
                var invoiceItem = new InvoiceItem()
                {
                    Count          = item.Count,
                    CartItemId     = item.Id,
                    ProductPriceId = (await UnitOfWork.ProductPriceRepository.GetActiveForProduct(item.ProductId)).Id
                };

                invoice.InvoiceItems.Add(invoiceItem);
            }

            var entityCreated = UnitOfWork.InvoiceRepository.Create(invoice);
            await UnitOfWork.SaveAsync();

            var result = entityCreated.MapTo <InvoiceDto>();

            return(result);
        }
コード例 #2
0
ファイル: InvoiceAppService.cs プロジェクト: MRebati/Eron
        public async Task <InvoiceDto> CreateInvoiceByOrders(List <string> orderNumbers)
        {
            var orders = await UnitOfWork.OrderRepository.GetOrderListByNumberListAsync(orderNumbers);

            var userId  = HttpContext.Current.User.Identity.GetUserId();
            var invoice = new Eron.Core.Entities.Financial.Base.Invoice()
            {
                ExpireDateTime = DateTime.Now.AddDays(1),
                InvoiceNumber  = GenerateNewInvoiceId(),
                UserId         = userId,
                InvoiceStatus  = InvoiceStatusType.WaitingForPayment,
                Type           = InvoiceType.Order
            };

            invoice.CheckProgress();

            foreach (var item in orders.Where(x => x.OrderStatus == OrderStatusType.NeedInvoice))
            {
                var invoiceItem = new InvoiceItem()
                {
                    Count         = 1,
                    Description   = item.Description,
                    OrderId       = item.Id,
                    TariffPriceId = UnitOfWork.TariffPriceRepository.GetValidByTariffId(item.TariffId).Id
                };

                invoice.InvoiceItems.Add(invoiceItem);
            }

            using (var unitOfWork = UnitOfWork.Begin())
            {
                var entityCreated = UnitOfWork.InvoiceRepository.Create(invoice);
                await UnitOfWork.OrderRepository.ChangeStateOfOrderListAsync(
                    orderNumbers,
                    OrderStatusType.NeedInvoice,
                    OrderStatusType.WaitingForPayment,
                    userId);

                await UnitOfWork.SaveAsync();

                var result = entityCreated.MapTo <InvoiceDto>();
                unitOfWork.Complete();
                return(result);
            }
        }