Esempio n. 1
0
        public async void CreateMenuItem(string name, string description, double parsedPrice, int parsedWaitTime, string ingredients, int parsedCalories, bool parsedHalal, int parsedCatID, string resUsername, IFormFile file)
        {
            int redID = RestaurantController.GetResByUsername(resUsername).ID;

            string fileName = await ImageController.UploadImage(name, file);

            using (RestaurantContext context = new RestaurantContext())
            {
                MenuItem newMenuItem = new MenuItem()
                {
                    Name         = Regex.Escape(name),
                    Description  = Regex.Escape(description),
                    Price        = parsedPrice,
                    WaitTimeMins = parsedWaitTime,
                    Ingredients  = Regex.Escape(ingredients),
                    Calories     = parsedCalories,
                    Halal        = parsedHalal,
                    CategoryID   = parsedCatID,
                    RestaurantID = redID,
                    ImageName    = fileName
                };
                context.MenuItems.Add(newMenuItem);
                context.SaveChanges();
            }
        }
Esempio n. 2
0
        // UPDATE
        public async void UpdateMenuItem(string menuID, string name, string description, string price, string waitTimeMins, string ingredients, string calories, string halal, string catID, IFormFile file, IWebHostEnvironment hostEnvironment)
        {
            using (RestaurantContext context = new RestaurantContext())
            {
                MenuItem menuItem = context.MenuItems.Where(m => m.ID == int.Parse(menuID)).SingleOrDefault();
                if (!string.IsNullOrWhiteSpace(name))
                {
                    menuItem.Name = Regex.Escape(name).Trim();
                }

                if (file != null)
                {
                    new ImageController(hostEnvironment).DeleteImageByName(menuItem.ImageName);
                    await ImageController.UploadImage(menuItem.Name, file);
                }
                if (!string.IsNullOrWhiteSpace(description))
                {
                    menuItem.Description = Regex.Escape(description).Trim();
                }

                if (!string.IsNullOrWhiteSpace(price))
                {
                    menuItem.Price = double.Parse(price);
                }

                if (!string.IsNullOrWhiteSpace(waitTimeMins))
                {
                    menuItem.WaitTimeMins = int.Parse(waitTimeMins);
                }

                if (!string.IsNullOrWhiteSpace(ingredients))
                {
                    menuItem.Ingredients = Regex.Escape(ingredients).Trim();
                }

                if (!string.IsNullOrWhiteSpace(calories))
                {
                    menuItem.Calories = int.Parse(calories);
                }

                if (!string.IsNullOrWhiteSpace(halal))
                {
                    menuItem.Halal = bool.Parse(halal);
                }

                if (!string.IsNullOrWhiteSpace(catID))
                {
                    menuItem.CategoryID = int.Parse(catID);
                }

                context.SaveChanges();
            }
        }