Esempio n. 1
0
        public async Task <BaseResponseModel> UpdateAsync(OrderModel orderModel)
        {
            BaseResponseModel report    = new BaseResponseModel();
            Order             order     = new Order();
            OrderItem         orderItem = new OrderItem();

            order.CreationDate = order.Date = DateTime.Now;
            order.IsRemoved    = false;
            order.Description  = orderModel.Description;
            order.User         = await _userManager.FindByEmailAsync(orderModel.UserName.ToString());

            order = await _orderRepository.UpdateAsync(order);

            orderItem.CreationDate    = DateTime.Now;
            orderItem.IsRemoved       = false;
            orderItem.PrintingEdition = await _printingEditionsRepository.GetByIdAsync(orderModel.PrintingEdition.Last().PrintingEditionId);

            orderItem.Count    = orderModel.PrintingEdition.Last().PrintingEditionCount;
            orderItem.Currency = orderModel.Currency;
            orderItem.Amount   = orderItem.PrintingEdition.Price * orderItem.Count;
            orderItem.Order    = order;
            await _orderItemRepository.UpdateAsync(orderItem);

            return(report);
        }
Esempio n. 2
0
        public async Task <BaseResponseModel> CreateAsync(OrderModel orderModel)
        {
            BaseResponseModel report       = new BaseResponseModel();
            PaymentModel      paymentModel = new PaymentModel();
            Order             order        = new Order();

            order.OrderItem = new List <OrderItem>();
            order.Payment   = new Payment();

            paymentModel.Amount      = orderModel.Amount;
            paymentModel.Currency    = orderModel.Currency;
            paymentModel.Description = orderModel.Description;
            paymentModel.Email       = orderModel.PaymentEmail;
            paymentModel.Source      = orderModel.PaymentSource;

            order.Payment.TransactionId = _paymentService.Pay(paymentModel);
            order.Payment.CreationDate  = DateTime.Now;

            order.CreationDate = order.Date = DateTime.Now;
            order.IsRemoved    = false;
            order.Description  = orderModel.Description;
            order.User         = await _userManager.FindByEmailAsync(orderModel.UserName.ToString());

            foreach (var item in orderModel.PrintingEdition)
            {
                OrderItem orderItem = new OrderItem();
                orderItem.CreationDate    = DateTime.Now;
                orderItem.IsRemoved       = false;
                orderItem.PrintingEdition = await _printingEditionsRepository.GetByIdAsync(item.PrintingEditionId);

                orderItem.Count    = item.PrintingEditionCount;
                orderItem.Currency = item.PrintingEditionCurrency;
                orderItem.Amount   = item.PrintingEditionPrice * item.PrintingEditionCount;
                orderItem.Order    = order;

                order.OrderItem.Add(orderItem);
            }

            await _orderRepository.CreateAsync(order);

            return(report);
        }