Beispiel #1
0
        public async Task <int> CreateOrder(OrderViewModel model)
        {
            Order order                 = _mapper.Map <Order>(model);
            var   printingEditions      = new List <PrintingEdition>();
            var   printEditionsInOrders = new List <PrintingEditionsInOrders>();

            order.DatePurchase = DateTime.UtcNow;

            await _orderRepository.Create(order);

            foreach (AuthorsInPrintingEditionsViewModel printEd in model.Products)
            {
                printingEditions.Add(await _printEditRepository.Get(printEd.PrtintingEditionId));
            }

            foreach (PrintingEdition print in printingEditions)
            {
                printEditionsInOrders.Add(new PrintingEditionsInOrders
                {
                    PrintingEditionId    = print.Id,
                    OrderId              = order.Id,
                    OrderAmount          = model.OrderAmount,
                    PrintEditionQuantity = model.Products.Find(x => x.PrtintingEditionId == print.Id).PrintinEditionQuantityForOrder
                });
            }

            _printEditInOrdersRepository.AddPrintingEditionInOrders(printEditionsInOrders);

            return(order.Id);
        }
Beispiel #2
0
        public async Task <OrderViewModel> GetOrderById(int id)
        {
            Order order = await _orderRepository.Get(id);

            var model = _mapper.Map <OrderViewModel>(order);

            return(model);
        }
Beispiel #3
0
        public async Task UpdateInformationAboutOrder(OrderViewModel model)
        {
            Order orderData = await _orderRepository.Get(model.Id);

            if (orderData != null)
            {
                orderData = _mapper.Map <Order>(model);

                await _orderRepository.Update(orderData);
            }
        }