public ActionResult RestaurantOptions() { var service = ServiceCreator.GetManagerService(User.Identity.Name); var rests = service.GetAllRestaurants(); if (rests != null && rests.Any()) { rests.Add(new Restaurant { Name = "Все", Id = Guid.Empty }); var model = new RestOptionsViewModel { AvailableRests = rests }; var restCookie = Request.Cookies.Get("CurRest"); if (restCookie != null) { var curRest = restCookie.Value; var rest = service.GetRestaurant(Guid.Parse(curRest)); if (rest == null) { restCookie.Value = Guid.Empty.ToString(); Response.Cookies.Set(restCookie); model.CurrentRest = Guid.Empty; } else { model.CurrentRest = rest.Id; } } return(View(model)); } else { var model = new RestOptionsViewModel { AvailableRests = new List <Restaurant> { new Restaurant { Name = "Все", Id = Guid.Empty } } }; return(View(model)); } }
public ActionResult UpdateTables() { var service = ServiceCreator.GetManagerService(User.Identity.Name); var rests = service.GetAllRestaurants(); var restCookie = Request.Cookies.Get("CurRest"); string restOptionsView = ""; string tablesView = ""; var restsModel = new RestOptionsViewModel { AvailableRests = new List <Restaurant> { new Restaurant { Name = "Все", Id = Guid.Empty } } }; if (rests != null && rests.Any()) { restsModel.AvailableRests.AddRange(rests); if (restCookie != null) { var curRest = restCookie.Value; var rest = service.GetRestaurant(Guid.Parse(curRest)); if (rest == null) { restCookie.Value = Guid.Empty.ToString(); Response.Cookies.Set(restCookie); restsModel.CurrentRest = Guid.Empty; } else { restsModel.CurrentRest = rest.Id; } } } restOptionsView = RenderPartialViewToString("RestaurantOptions", restsModel); var activeTables = new List <Table>(); var inActiveTables = new List <Table>(); if (restCookie != null) { var curRest = Guid.Parse(restCookie.Value); if (curRest != Guid.Empty) { activeTables = service.GetManagerTables(curRest).OrderByDescending(o => o.OrderPlaced).ToList(); inActiveTables = service.GetInActiveTables(curRest).OrderByDescending(o => o.OrderPlaced).Take(20).ToList(); } else { activeTables = service.GetManagerTables().OrderByDescending(o => o.OrderPlaced).ToList(); inActiveTables = service.GetInActiveTables().OrderByDescending(o => o.OrderPlaced).Take(20).ToList(); } } else { activeTables = service.GetManagerTables().OrderByDescending(o => o.OrderPlaced).ToList(); inActiveTables = service.GetInActiveTables().OrderByDescending(o => o.OrderPlaced).Take(20).ToList(); } var newTables = activeTables.Where(o => !o.OrderProcessed).Any(); var tablesModel = new AllTablesViewModel { ActiveTables = Mapper.Map <List <TableCardViewModel> >(activeTables), InActiveTables = Mapper.Map <List <TableCardViewModel> >(inActiveTables) }; tablesView = RenderPartialViewToString("TableCardList", tablesModel); return(Json(new { isAuthorized = true, isSuccess = true, tablesView = tablesView, restOptionsView = restOptionsView, newTables = newTables }, JsonRequestBehavior.AllowGet)); }