public async Task <ActionResult> OrderListPartial(int?pageNumber, OrderStatusViewEnum status = OrderStatusViewEnum.ALL) { _logger.Info("PARTIAL VIEW > Orders List"); ViewBag.OrderStatus = status; try { var page = pageNumber ?? 1; _logger.Info($"Getting orders for admin, page {page}, status {status.ToString()}."); var ordersModel = await _iOrderLogic.GetOrders(page, status); int pageSize = Convert.ToInt32(ConfigurationManager.AppSettings["AdminOrdersPerPage"]); var pagedListModel = new StaticPagedList <OrderViewModel>(ordersModel.Orders, page, pageSize, ordersModel.TotalCount); _logger.Info("Successfully got orders list for admin."); return(PartialView("_OrderListPartial", pagedListModel)); } catch (Exception ex) { _logger.Error($"Failed to retrive orders for status {status.ToString()}. Exception: {ex.Message}"); return(View("Error")); } }
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; } }
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); }
public static OrderStatus ToDbEnum(this OrderStatusViewEnum orderStatusViewEnum) { switch (orderStatusViewEnum) { case OrderStatusViewEnum.REGISTRED: return(OrderStatus.REGISTRED); case OrderStatusViewEnum.CONFIRMED: return(OrderStatus.CONFIRMED); case OrderStatusViewEnum.SHIPPED: return(OrderStatus.SHIPPED); case OrderStatusViewEnum.COMPLETE: return(OrderStatus.COMPLETE); default: return(OrderStatus.UNIDENTIFIED); } }