Esempio n. 1
0
        /// <summary>
        /// Get the paged new orders
        /// </summary>
        /// <returns>返回用户获取新订单的结果View</returns>
        public ActionResult New(int?id)
        {
            int pi         = id ?? 0; //表示页索引
            int totalCount = 0;

            List <OrderItem>      orderList = OrderManager.GetPagedOrders(OrderStatus.Ordered, pi, 10, out totalCount);
            OrderManagerViewModel model     = new OrderManagerViewModel();

            model.OrderList      = orderList;
            model.PageIndex      = pi;
            model.TotalPageCount = (totalCount + 9) / 10;
            return(View("Index", model));
        }
        public IActionResult OrderManager()
        {
            OrderManagerState ordersState = HttpContext.Session.Get <OrderManagerState>("orderManagerState");

            if (ordersState == null)
            {
                ordersState = new OrderManagerState();
                SaveOrderManagerState(ordersState);
            }

            var AllOrderViewModel = new List <OrderViewModel>();

            foreach (var order in _orderService.GetOrdersToOrderManagerPage(ordersState))   //две обязанности...   изменяет состояние otderstate
            {
                AllOrderViewModel.Add(_mapperToViewModel.Map(order));
            }

            SaveOrderManagerState(ordersState);
            var orderManagerViewModel = new OrderManagerViewModel
            {
                orderViewModels = AllOrderViewModel,
                state           = ordersState
            };

            var managers = _managerService.GetManagers();

            if (managers != null)
            {
                var managerList = new SelectList(managers, "Id", "Name");
                ViewBag.managers = managerList.SetSelectedItemByValue(ordersState.FilterState.ValueOfFilterByManagerId.ToString());
            }

            var shipSpecialists = _shipmentSpecialistService.GetShipmentSpecialists();

            if (shipSpecialists != null)
            {
                var shipSpecialistsList = new SelectList(shipSpecialists, "Id", "Specialist");
                ViewBag.shipmentSpecialists = shipSpecialistsList.SetSelectedItemByValue(ordersState.FilterState.ValueOfFilterByShipmentSpecId.ToString());
            }

            var shipDestinations = _shipmentDestinationService.GetShipmentDestinations();

            if (shipDestinations != null)
            {
                var shipSpecialistsList = new SelectList(shipDestinations, "Id", "Destination");
                ViewBag.shipDest = shipSpecialistsList.SetSelectedItemByValue(ordersState.FilterState.ValueOfFilterByShipmentDestId.ToString());
            }
            return(View(orderManagerViewModel));
        }
Esempio n. 3
0
        public async Task <IActionResult> OrderManager(string KeyWord, int page = 1, int pageSize = 10)
        {
            if (string.IsNullOrEmpty(KeyWord))
            {
                KeyWord = string.Empty;
            }
            var ENVIRONMENT_USER_ID = await userManager.GetUserAsync(User);

            if (ENVIRONMENT_USER_ID == null)
            {
                return(RedirectToAction("SignIn", "Login"));
            }
            var role      = userManager.GetRolesAsync(ENVIRONMENT_USER_ID).Result;
            var isShipper = false;

            if (role.Contains("Shipper"))
            {
                isShipper = true;
            }

            List <Order> model = new List <Order>();

            var userList = await userManager.Users
                           .ToAsyncEnumerable()
                           .Where(user => user.HoTen.ToLower().Contains(KeyWord.ToLower()))
                           .Select(user => user.Id)
                           .ToList();

            if (isShipper)

            {   // Đăng nhập là shipper
                model = orderService.GetListForShipper(ENVIRONMENT_USER_ID.Id, userList, KeyWord).ToList();
            }
            else
            {   // Đăng nhập là Admin
                model = orderService.GetList(userList, KeyWord).ToList();
            }
            OrderManagerViewModel        viewModel = new OrderManagerViewModel();
            IEnumerable <OrderViewModel> orderDTO  = MappingViewModel(model);

            viewModel.PagedOrderModel = new PagedList <OrderViewModel>(orderDTO.AsQueryable(), page, pageSize);
            viewModel.Keyword         = KeyWord;
            return(View(viewModel));
        }