private OrderDto GetMyCurrentOrder(int[] ids) { if (MenuDto.GetMenuLunchOrSupper() != MenuTypeEnum.None) { // 获得预订了对应的套餐 var factory = new OrderViewFactory(); var critria = new Criteria { WhereClause = $"UserGuid = '{_authorizedUser.ID}'", OrderClause = "PlaceTime DESC", PagingSize = 0 }; var order = factory.Query(critria).Find(x => ids.Any(id => id == x.Menu.ID)); if (order != null) { var mapper = OrderDto.ConfigMapper().CreateMapper(); return(mapper.Map <OrderDto>(order)); } } return(null); }
// GET: Console/ExportReports public ActionResult ExportReports() { IViewerFactory <ReportView> factory = new ReportViewFactory(); var list = factory.Query(new Criteria(new { MenuDate = DateTime.Today, MenuType = (int)MenuDto.GetMenuLunchOrSupper(0, false) })); if (list != null && list.Count > 0) { var mapper = ReportDto.ConfigMapper().CreateMapper(); var reports = mapper.Map <IEnumerable <ReportDto> >(list.AsEnumerable()).ToList(); var book = ExcelManager.BuildReportWorkbook(reports); byte[] file; using (var ms = new MemoryStream()) { book.Write(ms); file = ms.GetBuffer(); } return(File(file, "application/vnd.ms-excel", $@"今日订餐统计表-{DateTime.Today:yyyyMMdd}.xls")); } return(RedirectToAction("Index", "Home")); }
// GET: Console/OrderManagementCanteen public ActionResult OrderManagementCanteen() { var model = new ConsoleModels.OrderManagementDto(); IViewerFactory <OrderView> factory = new OrderViewFactory(); var list = factory.Query(new Criteria(new { MenuDate = DateTime.Today, MenuType = (int)MenuDto.GetMenuLunchOrSupper(0, false) })); if (list != null && list.Count > 0) { var mapper = OrderDto.ConfigMapper().CreateMapper(); model.Orders = mapper.Map <IEnumerable <OrderDto> >(list.AsEnumerable()).ToList(); // 查找今日的菜单,判断是否大班长确认过 var currentMenus = Entities.Menu.Cache.MenuListActiveToday.FindAll(x => x.MenuType.Equals(MenuDto.GetMenuLunchOrSupper(0, false))); model.IsMenuApproved = currentMenus.Exists(x => x.IsApproved); model.ApproverInfo = model.IsMenuApproved ? currentMenus[0].Remark : string.Empty; } model.DeliveryZones = Delivery.Cache.DeliveryZoneList; return(View(model)); }
// GET: Reservation/ExportOrders public ActionResult ExportOrders() { IViewerFactory <OrderView> factory = new OrderViewFactory(); var list = factory.Query(new Criteria(new { MenuDate = DateTime.Today, MenuType = (int)MenuDto.GetMenuLunchOrSupper(0, false) })); if (list != null && list.Count > 0) { var mapper = OrderDto.ConfigMapper().CreateMapper(); var orders = mapper.Map <IEnumerable <OrderDto> >(list.AsEnumerable()).ToList(); var book = ExcelManager.BuildOrderWorkbook(orders); byte[] file; using (var ms = new MemoryStream()) { book.Write(ms); file = ms.GetBuffer(); } return(File(file, "application/vnd.ms-excel", $@"今日订餐记录表-{DateTime.Today.ToString("yyyyMMdd")}.xls")); //return File(file, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", // $"今日订餐记录表-{DateTime.Today.ToString("yyyyMMdd")}.xlsx"); } return(RedirectToAction("TodayOrders", "Reservation")); }
public ActionResult Index() { var model = new ConsoleModels.IndexDto(); IViewerFactory <ReportView> factory = new ReportViewFactory(); var list = factory.Query(new Criteria(new { MenuDate = DateTime.Today, MenuType = (int)MenuDto.GetMenuLunchOrSupper(0, false) })); if (list != null && list.Count > 0) { var mapper = ReportDto.ConfigMapper().CreateMapper(); model.Reports = mapper.Map <IEnumerable <ReportDto> >(list.AsEnumerable()).ToList(); // 查找今日的菜单,判断是否大班长确认过 var currentMenus = Menu.Cache.MenuListActiveToday.FindAll(x => x.MenuType.Equals(MenuDto.GetMenuLunchOrSupper(0, false))); model.ApproverInfo = currentMenus.Exists(x => x.IsApproved) ? currentMenus[0].Remark : string.Empty; } return(View(model)); }
private bool CanReserveNow(int[] ids) { if (MenuDto.GetMenuLunchOrSupper() != MenuTypeEnum.None) { // 已经预订了对应的套餐 return(!_repo.Query <Order>(x => x.UserGuid == _authorizedUser.ID).FindAll(x => x.IsActive) .Any(x => ids.Any(id => id == x.MenuID))); } return(false); }
// GET: Reservation/History public ActionResult History() { var model = new ReservationModels.HistoryDto { MenuDate = DateTime.Today, // 设置当前是否在订餐时间内,不判断是否有菜单 CanReserveNow = MenuDto.GetMenuLunchOrSupper() != MenuTypeEnum.None }; // 获取所有历史订单 (7天内) IViewerFactory <OrderView> factory = new OrderViewFactory(); var criteria = new Criteria { WhereClause = $@"(PlaceTime >= '{DateTime.Today.AddDays(-7)}') AND UserGuid = '{_authorizedUser.ID}'", PagingSize = 0 }; var query = factory.Query(criteria); if (query.Any()) { var mapper = OrderDto.ConfigMapper().CreateMapper(); model.MyHistroyOrders = mapper.Map <IEnumerable <OrderDto> >(query.AsEnumerable()).ToList(); // 今天的午餐订单 model.MyOrderLunch = model.MyHistroyOrders.Find(x => x.MenuDate == model.MenuDate && x.MenuType == MenuTypeEnum.Lunch); // 设置可取消 if (model.MyOrderLunch != null && CanCancelNow(model.MyOrderLunch.MenuID)) { model.MyOrderLunch.CanCancelNow = true; } // 今天的夜宵订单 model.MyOrderSupper = model.MyHistroyOrders.Find(x => x.MenuDate == model.MenuDate && x.MenuType == MenuTypeEnum.Supper); // 设置可取消 if (model.MyOrderSupper != null && CanCancelNow(model.MyOrderSupper.MenuID)) { model.MyOrderSupper.CanCancelNow = true; } } return(View(model)); }
private bool CanCancelNow(int id) { var menuType = MenuDto.GetMenuLunchOrSupper(); if (menuType != MenuTypeEnum.None) { // 判断是否今天当前订餐时间段里菜单,是可取消,不是则不可取消 var todayMenus = _repo.Query <Menu>(x => x.MenuDate == DateTime.Today && x.MenuType == menuType); if (todayMenus.Count > 0) { return(todayMenus.Exists(x => x.ID == id)); } } return(false); }
public ActionResult ApproveTodayMenus() { var menus = Menu.Cache.MenuListActiveToday.FindAll(x => x.MenuType.Equals(MenuDto.GetMenuLunchOrSupper(0, false))); if (menus.Count > 0) { foreach (var m in menus) { m.IsApproved = true; m.Remark = $"【{_authorizedUser.EmployeeName}({_authorizedUser.EmployeeNo})】于【{DateTime.Now.ToString("yyyy-MM-dd HH:mm")}】确认"; _repo.Update(m); } Menu.Cache.RefreshCache(); } return(Json(menus.Count)); }
// GET: Console/OrderManagement public ActionResult OrderManagement(string date) { var model = new ConsoleModels.OrderManagementDto(); IViewerFactory <OrderView> factory = new OrderViewFactory(); DateTime menuDate; List <OrderView> list; if (!string.IsNullOrEmpty(date) && DateTime.TryParse(date, out menuDate)) { list = factory.Query(new Criteria(new { MenuDate = menuDate })); model.MenuDate = menuDate; // 查找今日的菜单,判断是否大班长确认过 var currentMenus = Entities.Menu.Cache.MenuListActive.FindAll(x => x.MenuDate.Equals(menuDate) && x.MenuType.Equals(MenuDto.GetMenuLunchOrSupper(0, false))); model.ApproverInfo = currentMenus.Exists(x => x.IsApproved) ? currentMenus[0].Remark : string.Empty; } else { // 为避免数据量过大,只显示7天内的订餐记录 list = factory.Query(new Criteria { WhereClause = "MenuDate >= DATEADD(DAY,-7,GETDATE())", PagingSize = 0 }); list.Sort((x1, x2) => x2.Menu.MenuDate.CompareTo(x1.Menu.MenuDate)); } if (list != null && list.Count > 0) { var mapper = OrderDto.ConfigMapper().CreateMapper(); model.Orders = mapper.Map <IEnumerable <OrderDto> >(list.AsEnumerable()).ToList(); } model.DeliveryZones = Delivery.Cache.DeliveryZoneList; return(View(model)); }
// GET: Reservation public ActionResult Index() { var model = new ReservationModels.IndexDto(); var menuType = MenuDto.GetMenuLunchOrSupper(); var menuA = Menu.Cache.MenuListActiveToday.Find(x => x.MenuType == menuType && x.MenuFlag == "A"); var menuB = Menu.Cache.MenuListActiveToday.Find(x => x.MenuType == menuType && x.MenuFlag == "B"); var mapper = MenuDto.ConfigMapper().CreateMapper(); if (menuA != null) { model.MenuA = mapper.Map <MenuDto>(menuA); } if (menuB != null) { model.MenuB = mapper.Map <MenuDto>(menuB); } // 可以订餐,无相关订餐历史记录 if (menuA != null && menuB != null && CanReserveNow(new[] { menuA.ID, menuB.ID })) { model.MenuDate = DateTime.Today; model.DeliveryZones = Delivery.Cache.DeliveryZoneList; // 设置当前用户的默认送餐区域,先判断用户的职务,再判断用户的班组 if (_authorizedUser != null) { var rela = _repo.Single <RelationTeamPositionDelivery>(x => x.Position == _authorizedUser.Position) ?? _repo.Single <RelationTeamPositionDelivery>(x => x.Team == _authorizedUser.Team); if (rela != null) { model.MyDefaultDeliveryZone = Delivery.Cache.Load(rela.DeliveryGuid); } } if (menuType.Equals(MenuTypeEnum.Lunch)) { model.MenuStyle = "green"; } else if (menuType.Equals(MenuTypeEnum.Supper)) { model.MenuStyle = "purple"; } model.CanReserveNow = true; } else { model.CanReserveNow = false; } // 获取今天最新订餐记录 if (menuA != null && menuB != null) { model.MyCurrentOrder = GetMyCurrentOrder(new[] { menuA.ID, menuB.ID }); } return(View(model)); }