Пример #1
0
        public async Task <OrderSearchViewResult> GetOrders(int pageNumber, OrderStatusViewEnum status)
        {
            var itemsPerPage = Convert.ToInt32(ConfigurationManager.AppSettings["AdminOrdersPerPage"]);
            var itemsToSkip  = (pageNumber - 1) * itemsPerPage;
            var dbStatus     = status.ToDbEnum();

            OrderSearchResult result = null;

            if (status == OrderStatusViewEnum.ALL)
            {
                result = await _iOrderRepository.GetAllOrders(itemsPerPage, itemsToSkip);
            }
            else
            {
                result = await _iOrderRepository.GetOrdersByStatus(itemsPerPage, itemsToSkip, dbStatus);
            }

            if (result != null)
            {
                var orderSearchViewResult = new OrderSearchViewResult
                {
                    TotalCount = result.TotalCount,
                    Orders     = result.Orders.Select(x => x.ToViewModel())
                };

                return(orderSearchViewResult);
            }

            return(null);
        }
Пример #2
0
        public async Task ChangeOrderStatus(int orderNumber, OrderStatusViewEnum newOrderStatus, string deliveryTime)
        {
            var order = await _iOrderRepository.GetOrderByOrderNumber(orderNumber);

            if (order == null)
            {
                throw new Exception("Order could not be found.");
            }

            order.OrderStatus = newOrderStatus.ToDbEnum();

            await _iOrderRepository.UpdateOrder(order);

            switch (newOrderStatus)
            {
            case OrderStatusViewEnum.CONFIRMED:
                await _iEmailLogic.SendConfirmationOrderEmail(order);

                break;

            case OrderStatusViewEnum.SHIPPED:
                await _iEmailLogic.SendShippedOrderEmail(order, deliveryTime);

                break;
            }
        }