Example #1
0
        public ActionResult EditMods(Guid dishId, List <int> allActiveMods)
        {
            try
            {
                var service = ServiceCreator.GetManagerService(User.Identity.Name);
                var curDish = service.GetDish(dishId);
                var allMods = service.GetAllModificators();
                if (curDish != null && allMods != null)
                {
                    if (allActiveMods != null)
                    {
                        var modsForCurDish = allMods.Where(o => allActiveMods.Contains(o.Id)).Select(o => o.Id).ToList();
                        curDish.ModIds = modsForCurDish;
                    }
                    else
                    {
                        curDish.ModIds = new List <int>();
                    }

                    service.UpdateDish(curDish);
                }
                else
                {
                    throw new ArgumentNullException("Dish or list of dishes not found!");
                }

                return(Json(new { isAuthorized = true, isSuccess = true }));
            }
            catch (Exception ex)
            {
                return(Json(new { isAuthorized = true, isSuccess = false, error = ex.Message }));
            }
        }
Example #2
0
        public JsonResult EditMenuDishes(Guid menuId, List <Guid> allActiveDishes)
        {
            try
            {
                var service   = ServiceCreator.GetManagerService(User.Identity.Name);
                var curMenu   = service.GetMenu(menuId);
                var allDishes = service.GetAllDishes();
                if (curMenu != null && allDishes != null)
                {
                    if (allActiveDishes != null)
                    {
                        var dishesForCurmenu = allActiveDishes.Select(o => allDishes.Where(a => a.Id == o).FirstOrDefault()).ToList();
                        //var dishesForCurmenu = allDishes.Where(o => allActiveDishes.Contains(o.Id)).ToList();
                        curMenu.DishList = dishesForCurmenu;
                    }
                    else
                    {
                        curMenu.DishList = new List <Dish>();
                    }

                    service.UpdateMenu(curMenu);
                }
                else
                {
                    throw new ArgumentNullException("Menu or list of dishes not found!");
                }

                return(Json(new { isAuthorized = true, isSuccess = true }));
            }
            catch (Exception ex)
            {
                return(Json(new { isAuthorized = true, isSuccess = false, error = ex.Message }));
            }
        }
Example #3
0
        public ActionResult AllMenus()
        {
            var service = ServiceCreator.GetManagerService(User.Identity.Name);
            var menus   = service.GetAllMenus();

            var model = Mapper.Map <List <MenuViewModel> >(menus);

            model.ForEach(o =>
            {
                var rest = service.GetRestaurantByMenu(o.Id);

                if (rest != null)
                {
                    o.AttachedRestaurantName = rest.Name;
                }

                if (o.DishList != null && o.DishList.Any())
                {
                    var groupedDishes = o.DishList.GroupBy(d => d.Category).Select(d => new DishListViewModel {
                        Category = d.Key, Dishes = Mapper.Map <List <DishViewModel> >(d.ToList())
                    }).ToList();
                    o.GroupedDishes = new List <DishListViewModel>();

                    foreach (var category in o.CategoriesSorted)
                    {
                        o.GroupedDishes.AddRange(groupedDishes.Where(g => g.Category == category));
                    }
                }
                else
                {
                    o.GroupedDishes = new List <DishListViewModel>();
                }
            });
            return(View("MenuCardList", model));
        }
Example #4
0
        public ActionResult TableSetProccesed(Guid tableId, bool value)
        {
            try
            {
                var service = ServiceCreator.GetManagerService(User.Identity.Name);
                var config  = new RegistrationService().FindConfiguration(User.Identity.Name);

                var table = service.GetTable(tableId);
                if (table != null)
                {
                    table.OrderProcessed = value;
                    service.UpdateTable(table);

                    //if (value)
                    //{
                    //    new BotClient(config.TelegramBotLocation).SendNotification(table.ChatId, "Ваш заказ принят!");
                    //}
                }
                else
                {
                    throw new ArgumentNullException("Table not found!");
                }

                return(Json(new { isAuthorized = true, isSuccess = true }));
            }
            catch (Exception ex)
            {
                return(Json(new { isAuthorized = true, isSuccess = false, error = ex.Message }));
            }
        }
Example #5
0
        public ActionResult EditDish(Guid dishId)
        {
            try
            {
                var service = ServiceCreator.GetManagerService(User.Identity.Name);

                var dish = service.GetDish(dishId);
                if (dish != null)
                {
                    var model = Mapper.Map <DishViewModel>(dish);

                    var allDishes = service.GetAllDishes();
                    if (allDishes != null && allDishes.Any())
                    {
                        model.AvailableCategories = allDishes.Where(o => !string.IsNullOrEmpty(o.Category)).Select(o => o.Category).Distinct().ToList();
                    }

                    return(View("DishCardEdditable", model));
                }
                else
                {
                    throw new Exception("Dish not found!");
                }
            }
            catch (Exception ex)
            {
                return(Json(new { isAuthorized = true, isSuccess = false, error = ex.Message }));
            }
        }
Example #6
0
        public ActionResult EditDish(Dish dish)
        {
            try
            {
                if (string.IsNullOrEmpty(dish.ShortName))
                {
                    dish.ShortName = dish.Name;
                }
                var service = ServiceCreator.GetManagerService(User.Identity.Name);
                if (dish.Id == Guid.Empty)
                {
                    service.CreateNewDish(dish);
                }
                else
                {
                    service.UpdateDish(dish);
                }

                return(Json(new { isAuthorized = true, isSuccess = true }));
            }
            catch (Exception ex)
            {
                return(Json(new { isAuthorized = true, isSuccess = false, error = ex.Message }));
            }
        }
Example #7
0
        public ActionResult AllTables()
        {
            var service = ServiceCreator.GetManagerService(User.Identity.Name);

            var activeTables   = new List <Table>();
            var inActiveTables = new List <Table>();

            var restCookie = Request.Cookies.Get("CurRest");

            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 model = new AllTablesViewModel {
                ActiveTables = Mapper.Map <List <TableCardViewModel> >(activeTables), InActiveTables = Mapper.Map <List <TableCardViewModel> >(inActiveTables)
            };

            return(View("TableCardList", model));
        }
        public ActionResult AllModificators()
        {
            var service = ServiceCreator.GetManagerService(User.Identity.Name);
            var mods    = Mapper.Map <List <ModificatorViewModel> >(service.GetAllModificators());

            return(View("ModificatorCardList", mods));
        }
Example #9
0
        public ActionResult EditCatList(Guid menuId, List <string> sortedCat)
        {
            try
            {
                var service = ServiceCreator.GetManagerService(User.Identity.Name);

                var categories = new List <string>();
                foreach (var cat in sortedCat)
                {
                    if (cat == "")
                    {
                        categories.Add(null);
                    }
                    else
                    {
                        categories.Add(cat);
                    }
                }

                service.UpdateMenuCategories(menuId, categories);
                return(Json(new { isAuthorized = true, isSuccess = true }));
            }
            catch (Exception ex)
            {
                return(Json(new { isAuthorized = true, isSuccess = false, error = ex.Message }));
            }
        }
Example #10
0
        public ActionResult MenuCatList(Guid menuid)
        {
            var service = ServiceCreator.GetManagerService(User.Identity.Name);
            var curMenu = service.GetMenu(menuid);

            var model = curMenu.CategoriesSorted;

            return(View(model));
        }
Example #11
0
        public ActionResult AllCheques()
        {
            var service = ServiceCreator.GetManagerService(User.Identity.Name);
            var cheques = service.GetAllCheques().OrderByDescending(o => o.Date);

            var model = Mapper.Map <List <ChequeViewModel> >(cheques).ToList();

            return(View("ChequeCardList", model));
        }
Example #12
0
        public ActionResult AllFeedbacks()
        {
            var service   = ServiceCreator.GetManagerService(User.Identity.Name);
            var feedbacks = service.GetAllFeedbacks().OrderByDescending(o => o.Date);

            var model = Mapper.Map <List <FeedbackViewModel> >(feedbacks).ToList();

            return(View("FeedbackCardList", model));
        }
        public ActionResult AllRestaurants()
        {
            var service = ServiceCreator.GetManagerService(User.Identity.Name);
            var rests   = service.GetAllRestaurants();

            var model = Mapper.Map <List <RestaurantViewModel> >(rests);

            return(View("RestaurantCardList", model));
        }
Example #14
0
        public ActionResult Add(CardTypes activeSection)
        {
            try
            {
                var service = ServiceCreator.GetManagerService(User.Identity.Name);
                switch (activeSection)
                {
                case CardTypes.Dish:
                {
                    var model = new DishViewModel();

                    var allDishes = service.GetAllDishes();
                    if (allDishes != null && allDishes.Any())
                    {
                        model.AvailableCategories = allDishes.Where(o => !string.IsNullOrEmpty(o.Category)).Select(o => o.Category).Distinct().ToList();
                    }
                    return(View("DishCardEdditable", model));
                }

                case CardTypes.Menu:
                {
                    var model = new MenuViewModel();

                    var rests = service.GetAllRestaurants();
                    if (rests != null && rests.Any())
                    {
                        model.AvailableRests = Mapper.Map <List <RestaurantDropDown> >(rests);
                    }

                    return(View("MenuCardEdditable", model));
                }

                case CardTypes.Restaurant:
                {
                    return(View("RestaurantCardEdditable", new RestaurantViewModel()));
                }

                case CardTypes.Dispatch:
                {
                    return(View("DispatchCardEdditable", new DispatchViewModel()));
                }

                case CardTypes.Mod:
                {
                    return(View("ModificatorsCardEdditable", new ModificatorViewModel()));
                }

                default:
                    throw new Exception("No active section");
                }
            }
            catch (Exception ex)
            {
                return(Json(new { isAuthorized = true, isSuccess = false, error = ex.Message }));
            }
        }
Example #15
0
        public ActionResult AllDishes()
        {
            var service = ServiceCreator.GetManagerService(User.Identity.Name);
            var dishes  = service.GetAllDishes();

            var model = dishes.GroupBy(o => o.Category).Select(o => new DishListViewModel {
                Category = o.Key, Dishes = Mapper.Map <List <DishViewModel> >(o.ToList())
            }).ToList();

            return(View("DishCardList", model));
        }
Example #16
0
        public ActionResult AllBookings()
        {
            var service  = ServiceCreator.GetManagerService(User.Identity.Name);
            var bookings = service.GetAllBookings();

            var activeBookings = Mapper.Map <List <BookingViewModel> >(bookings.Where(o => o.State == BookingState.Active));
            var closedBookings = Mapper.Map <List <BookingViewModel> >(bookings.Where(o => o.State == BookingState.Closed));

            var model = new BookingListViewModel {
                ActiveBookings = activeBookings, ClosedBookings = closedBookings
            };

            return(View("BookingCardList", model));
        }
Example #17
0
        public ActionResult DeleteItem(string itemId, CardTypes itemType)
        {
            try
            {
                var service = ServiceCreator.GetManagerService(User.Identity.Name);

                switch (itemType)
                {
                case CardTypes.Dish:
                {
                    service.DeleteDish(Guid.Parse(itemId));
                    break;
                }

                case CardTypes.Menu:
                {
                    service.DeleteMenu(Guid.Parse(itemId));
                    break;
                }

                case CardTypes.Table:
                {
                    service.DeleteTable(Guid.Parse(itemId));
                    break;
                }

                case CardTypes.Restaurant:
                {
                    service.DeleteRestaraunt(Guid.Parse(itemId));
                    break;
                }

                case CardTypes.Mod:
                {
                    service.DeleteModificator(Int32.Parse(itemId));
                    break;
                }

                default:
                    break;
                }

                return(Json(new { isAuthorized = true, isSuccess = true }));
            }
            catch (Exception ex)
            {
                return(Json(new { isAuthorized = true, isSuccess = false, error = ex.Message }));
            }
        }
Example #18
0
        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 EditRest(RestaurantViewModel RestModel)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    var service = ServiceCreator.GetManagerService(User.Identity.Name);
                    var rest    = new Restaurant
                    {
                        Address     = RestModel.Address,
                        Code        = RestModel.Code,
                        QueueNumber = RestModel.QueueNumber,
                        Description = RestModel.Description,
                        Id          = RestModel.Id,
                        Latitude    = RestModel.Latitude,
                        Longitude   = RestModel.Longitude,
                        Name        = RestModel.Name,
                        Menu        = RestModel.Menu,
                        TimeZoneId  = RestModel.TimeZoneId
                    };

                    if (rest.Id == Guid.Empty)
                    {
                        service.CreateRestaurant(rest);
                    }
                    else
                    {
                        service.UpdateRestaurant(rest);
                    }

                    return(Json(new { isAuthorized = true, isSuccess = true }));
                }
                else
                {
                    return(Json(new { isAuthorized = true, isSuccess = false }));
                }
            }
            catch (Exception ex)
            {
                return(Json(new { isAuthorized = true, isSuccess = false, error = ex.Message }));
            }
        }
Example #20
0
 public ActionResult CloseTable(Guid tableId)
 {
     try
     {
         if (tableId != Guid.Empty)
         {
             var service = ServiceCreator.GetManagerService(User.Identity.Name);
             service.CloseTable(tableId);
             return(Json(new { isAuthorized = true, isSuccess = false }));
         }
         else
         {
             return(Json(new { isAuthorized = true, isSuccess = true }));
         }
     }
     catch (Exception ex)
     {
         return(Json(new { isAuthorized = true, isSuccess = false, error = ex.Message }));
     }
 }
Example #21
0
        public ActionResult UpdateBookings()
        {
            try
            {
                var service  = ServiceCreator.GetManagerService(User.Identity.Name);
                var bookings = service.GetAllBookings();

                var activeBookings = bookings.Where(o => o.State == BookingState.Active);
                if (activeBookings.Any())
                {
                    return(Json(new { isAuthorized = true, isSuccess = true, newBookings = true }, JsonRequestBehavior.AllowGet));
                }
                else
                {
                    return(Json(new { isAuthorized = true, isSuccess = true, newBookings = false }, JsonRequestBehavior.AllowGet));
                }
            }
            catch (Exception ex)
            {
                return(Json(new { isAuthorized = true, isSuccess = false, error = ex.Message }, JsonRequestBehavior.AllowGet));
            }
        }
        public ActionResult EditModificator(Modificator mod)
        {
            try
            {
                var service = ServiceCreator.GetManagerService(User.Identity.Name);

                if (mod.Id == 0)
                {
                    service.CreateNewModificator(mod);
                }
                else
                {
                    service.UpdateModificator(mod);
                }

                return(Json(new { isAuthorized = true, isSuccess = true }));
            }
            catch (Exception ex)
            {
                return(Json(new { isAuthorized = true, isSuccess = false, error = ex.Message }));
            }
        }
Example #23
0
        public ActionResult EditMenu(Guid menuId, string name, bool defaultMenu, Guid rest)
        {
            try
            {
                var service    = ServiceCreator.GetManagerService(User.Identity.Name);
                var restaurant = service.GetRestaurant(rest);

                if (menuId == Guid.Empty)
                {
                    var menu = new Menu {
                        MenuName = name, DefaultMenu = defaultMenu, DishList = new List <Dish>(), CategoriesSorted = new List <string>()
                    };
                    var newMenu = service.CreateNewMenu(menu);
                    restaurant.Menu = newMenu;
                    service.UpdateRestaurant(restaurant);
                }
                else
                {
                    var curMenu = service.GetMenu(menuId);
                    curMenu.MenuName    = name;
                    curMenu.DefaultMenu = defaultMenu;
                    service.UpdateMenu(curMenu);
                    restaurant.Menu = curMenu.Id;
                    service.UpdateRestaurant(restaurant);
                }

                if (defaultMenu == true)
                {
                    service.SetDefaultMenu(menuId);
                }

                return(Json(new { isAuthorized = true, isSuccess = true }));
            }
            catch (Exception ex)
            {
                return(Json(new { isAuthorized = true, isSuccess = false, error = ex.Message }));
            }
        }
        public ActionResult EditRest(Guid restId)
        {
            try
            {
                var service = ServiceCreator.GetManagerService(User.Identity.Name);

                var rest = service.GetRestaurant(restId);
                if (rest != null)
                {
                    var model = Mapper.Map <RestaurantViewModel>(rest);

                    return(View("RestaurantCardEdditable", model));
                }
                else
                {
                    throw new Exception("Restaraunt not found!");
                }
            }
            catch (Exception ex)
            {
                return(Json(new { isAuthorized = true, isSuccess = false, error = ex.Message }));
            }
        }
Example #25
0
        public ActionResult TableSetCheck(Guid tableId, bool value)
        {
            try
            {
                var service = ServiceCreator.GetManagerService(User.Identity.Name);
                var table   = service.GetTable(tableId);
                if (table != null)
                {
                    table.CheckNeeded = value;
                    service.UpdateTable(table);
                }
                else
                {
                    throw new ArgumentNullException("Table not found!");
                }

                return(Json(new { isAuthorized = true, isSuccess = true }));
            }
            catch (Exception ex)
            {
                return(Json(new { isAuthorized = true, isSuccess = false, error = ex.Message }));
            }
        }
        public ActionResult EditModificator(int modId)
        {
            try
            {
                var service = ServiceCreator.GetManagerService(User.Identity.Name);

                var mod = service.GetModificator(modId);
                if (mod != null)
                {
                    var model = Mapper.Map <ModificatorViewModel>(mod);

                    return(View("ModificatorsCardEdditable", model));
                }
                else
                {
                    throw new Exception("Modificator not found!");
                }
            }
            catch (Exception ex)
            {
                return(Json(new { isAuthorized = true, isSuccess = false, error = ex.Message }));
            }
        }
Example #27
0
        public ActionResult MenuMoreDishes(string menuid)
        {
            var service = ServiceCreator.GetManagerService(User.Identity.Name);

            var allDishes      = service.GetAllDishes();
            var selectedDishes = Mapper.Map <List <SelectedDishViewModel> >(allDishes);

            var currentMenuDishes = service.GetMenu(Guid.Parse(menuid)).DishList.Select(o => o.Id);

            foreach (var dish in selectedDishes)
            {
                if (currentMenuDishes.Contains(dish.Id))
                {
                    dish.Selected = true;
                }
            }

            var model = selectedDishes.GroupBy(o => o.Category).Select(o => new SelectedDishListViewModel {
                Category = o.Key, Dishes = o.ToList()
            }).ToList();

            return(View(model));
        }
Example #28
0
        public ActionResult EditDisp(DispatchViewModel dispatchModel)
        {
            try
            {
                var regService  = new RegistrationService();
                var service     = ServiceCreator.GetManagerService(User.Identity.Name);
                var dispService = ServiceCreator.GetDispatchesService();

                var config = regService.FindConfiguration(User.Identity.Name);
                var dispId = Guid.NewGuid();
                var disp   = new Dispatch {
                    Host = config.TelegramBotLocation, Id = dispId, Message = dispatchModel.Message, Name = dispatchModel.Name, AccountId = config.AccountId, Done = false
                };
                dispService.CreateDispatch(disp);

                var allTables = service.GetInActiveTables();
                var allChats  = new List <long>();
                allTables.ForEach(o => { if (!allChats.Contains(o.ChatId))
                                         {
                                             allChats.Add(o.ChatId);
                                         }
                                  });
                foreach (var chat in allChats)
                {
                    var dispMes = new DispatchMessage {
                        DispatchId = dispId, ChatId = chat, Id = Guid.NewGuid(), Send = false
                    };
                    dispService.CreateDispatchMessage(dispMes);
                }

                return(Json(new { isAuthorized = true, isSuccess = true }));
            }
            catch (Exception ex)
            {
                return(Json(new { isAuthorized = true, isSuccess = false, error = ex.Message }));
            }
        }
Example #29
0
        public ActionResult EditMods(string dishid)
        {
            var service = ServiceCreator.GetManagerService(User.Identity.Name);

            var allMods      = service.GetAllModificators();
            var selectedMods = Mapper.Map <List <SelectedModViewModel> >(allMods);

            var currentDishMods = service.GetDish(Guid.Parse(dishid)).ModIds;

            if (currentDishMods == null)
            {
                currentDishMods = new List <int>();
            }

            foreach (var mod in selectedMods)
            {
                if (currentDishMods.Contains(mod.Id))
                {
                    mod.Selected = true;
                }
            }

            return(View(selectedMods));
        }
Example #30
0
        public ActionResult EditMenu(Guid menuId)
        {
            try
            {
                var service = ServiceCreator.GetManagerService(User.Identity.Name);

                var menu = service.GetMenu(menuId);
                if (menu != null)
                {
                    var model = Mapper.Map <MenuViewModel>(menu);

                    var rests = service.GetAllRestaurants();
                    if (rests != null && rests.Any())
                    {
                        model.AvailableRests = Mapper.Map <List <RestaurantDropDown> >(rests);

                        var rest = service.GetRestaurantByMenu(model.Id);

                        if (rest != null)
                        {
                            model.AttachedRestaurantName = rest.Name;
                        }
                    }

                    return(View("MenuCardEdditable", model));
                }
                else
                {
                    throw new Exception("Menu not found!");
                }
            }
            catch (Exception ex)
            {
                return(Json(new { isAuthorized = true, isSuccess = false, error = ex.Message }));
            }
        }