Exemple #1
0
 public MvcConfiguration()
 {
     _configuration = new MvcServiceConfiguration();
     _menuItems     = new MenuItemContents();
     InitializeTemplates();
     InitializeLayout();
 }
        public async Task <MenuItems> UpdateMenuItemAsync(long ownerId, long restaurantId, long menuItemId, Dictionary <long, string> itemName, Dictionary <long, string> itemDescription, Dictionary <long, string> itemWarnings, Dictionary <long, float> itemPrice)
        {
            CheckTheLoggedInPerson();

            EmployersRestaurants connection = await CheckEmployerRestaurantAsync(ownerId, restaurantId);

            Menus currentMenu = await CheckMenuExistanceAsync(restaurantId);

            MenuItems menuItem = await CheckMenuItemExistance(menuItemId);

            List <MenuLanguages> menuLanguages = await MenuLanguagesRepo.GetItemsByMenuId(currentMenu.Id);

            List <MenuItemContents> itemContents = await MenuItemContentRepo.GetByMenuItemId(menuItem.Id);

            foreach (var menuLang in menuLanguages)
            {
                bool checkName        = itemName.TryGetValue(menuLang.Id, out string name);
                bool checkDescription = itemDescription.TryGetValue(menuLang.Id, out string description);
                itemWarnings.TryGetValue(menuLang.Id, out string warning);

                if (!checkName)
                {
                    name = "<< no name >>";
                }
                if (!checkDescription)
                {
                    description = "<< no description >>";
                }

                MenuItemContents contents = itemContents.Where(x => x.MenuLanguageId == menuLang.Id).SingleOrDefault();
                if (contents == null)
                {
                    contents = new MenuItemContents
                    {
                        ItemName        = name,
                        ItemDescription = description,
                        ItemWarnings    = warning,
                        MenuItemId      = menuItem.Id,
                        MenuLanguageId  = menuLang.Id
                    };
                    itemContents.Add(contents);
                    await MenuItemContentRepo.AddAsync(contents, this.ModifierId);
                }
                else
                {
                    contents.ItemName        = name;
                    contents.ItemDescription = description;
                    contents.ItemWarnings    = warning;
                    await MenuItemContentRepo.UpdateAsync(contents, this.ModifierId);
                }
            }

            List <MenuCurrencies> menuCurrencies = await MenuCurrencyRepo.GetItemsByMenuId(currentMenu.Id);

            List <MenuItemValues> itemValues = await MenuItemValueRepo.GetByMenuItemId(menuItem.Id);

            foreach (var currency in menuCurrencies)
            {
                bool checkValue = itemPrice.TryGetValue(currency.Id, out float price);

                if (!checkValue)
                {
                    price = 0F;
                }

                MenuItemValues value = itemValues.Where(x => x.MenuCurrencyId == currency.Id).SingleOrDefault();
                if (value == null)
                {
                    value = new MenuItemValues
                    {
                        Price          = price,
                        MenuCurrencyId = currency.Id,
                        MenuItemId     = menuItem.Id
                    };
                    itemValues.Add(value);
                    await MenuItemValueRepo.AddAsync(value, this.ModifierId);
                }
                else
                {
                    value.Price = price;
                    await MenuItemValueRepo.UpdateAsync(value, this.ModifierId);
                }
            }

            return(menuItem);
        }
        public async Task <MenuItems> AddMenuItemAsync(long ownerId, long restaurantId, long menuCategoryId, Dictionary <long, string> itemName, Dictionary <long, string> itemDescription, Dictionary <long, string> itemWarnings, Dictionary <long, float> itemPrice)
        {
            CheckTheLoggedInPerson();

            EmployersRestaurants connection = await CheckEmployerRestaurantAsync(ownerId, restaurantId);

            Menus currentMenu = await CheckMenuExistanceAsync(restaurantId);

            MenuCategories category = await CheckMenuCategoryExistance(menuCategoryId);

            MenuItems menuItem = new MenuItems
            {
                MenuId         = currentMenu.Id,
                MenuCategoryId = category.Id,
            };
            await MenuItemRepo.AddAsync(menuItem, this.ModifierId);

            List <MenuLanguages> menuLanguages = await MenuLanguagesRepo.GetItemsByMenuId(currentMenu.Id);

            foreach (var menuLang in menuLanguages)
            {
                bool checkName        = itemName.TryGetValue(menuLang.Id, out string name);
                bool checkDescription = itemDescription.TryGetValue(menuLang.Id, out string description);
                itemWarnings.TryGetValue(menuLang.Id, out string warning);

                if (!checkName)
                {
                    name = "<< no name >>";
                }
                if (!checkDescription)
                {
                    description = "<< no description >>";
                }

                MenuItemContents contents = new MenuItemContents
                {
                    ItemName        = name,
                    ItemDescription = description,
                    ItemWarnings    = warning,
                    MenuItemId      = menuItem.Id,
                    MenuLanguageId  = menuLang.Id
                };

                await MenuItemContentRepo.AddAsync(contents, this.ModifierId);
            }

            List <MenuCurrencies> menuCurrencies = await MenuCurrencyRepo.GetItemsByMenuId(currentMenu.Id);

            foreach (var currency in menuCurrencies)
            {
                bool checkValue = itemPrice.TryGetValue(currency.Id, out float price);

                if (!checkValue)
                {
                    price = 0F;
                }

                MenuItemValues value = new MenuItemValues
                {
                    Price          = price,
                    MenuCurrencyId = currency.Id,
                    MenuItemId     = menuItem.Id
                };

                await MenuItemValueRepo.AddAsync(value, this.ModifierId);
            }

            return(menuItem);
        }