Example #1
0
        // GET: DishTypes/Edit/5
        public async Task <IActionResult> Edit(int?id)
        {
            var dishTypesViewModel = new DishTypesViewModel();

            if (id == null)
            {
                return(NotFound());
            }

            var dishType = await repo.GetDishTypeID(id);

            await repo.GetIngredients();

            if (dishType == null)
            {
                return(NotFound());
            }

            var ingredientType = await repo.GetIngredientTypes();

            var subDishType = await repo.GetSubDishTypesList();

            dishTypesViewModel.Dish        = dishType;
            dishTypesViewModel.Ingredients = ingredientType;
            dishTypesViewModel.SubTypeList = subDishType;

            return(View("Edit", dishTypesViewModel));
        }
Example #2
0
        public async Task <IActionResult> Create([Bind("Dish, Dish.Name, Dish.Course, Ingredients, Dish.DishTypeID, SubTypeID, Dish.Recipe, Dish.Price")] DishTypesViewModel dishTypeViewModel)
        {
            //HEAD
            if (ModelState.IsValid)
            {
                // Create new Dishtype and assign properties
                DishType model = new DishType
                {
                    Name   = dishTypeViewModel.Dish.Name,
                    Course = dishTypeViewModel.Dish.Course,
                    Recipe = dishTypeViewModel.Dish.Recipe,
                    Price  = dishTypeViewModel.Dish.Price
                };

                var sdt = await repo.GetSubDishTypeID(dishTypeViewModel);


                if (sdt == null)
                {
                    return(NotFound());
                }

                model.SubDishType = sdt;
                repo.InsertDishType(model);
                await repo.Save();

                int id = model.DishTypeID;
                return(RedirectToAction(nameof(Edit), new { id }));
            }

            return(View(dishTypeViewModel));
        }
Example #3
0
        // GET: DishTypes/Details/5
        public async Task <IActionResult> Details(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            var model = await repo.GetDishTypeID(id);

            var model2 = await repo.GetIngredientTypes();

            if (model == null)
            {
                return(NotFound());
            }
            await repo.GetSubDishTypesList();

            DishTypesViewModel a = new DishTypesViewModel()
            {
                Dish        = model,
                Ingredients = model2
            };



            return(View(a));
        }
Example #4
0
        public async Task <SubDishType> GetSubDishTypeID(DishTypesViewModel dishTypesViewModel)
        {
            DbSet <SubDishType> subDishTypes = GetSubDishTypes();
            var sdt = subDishTypes.Where(s => dishTypesViewModel.SubTypeID == s.SubDishTypeID).FirstOrDefaultAsync();

            return(await sdt);
        }
Example #5
0
        // GET: DishTypes/Create
        public async Task <IActionResult> Create()
        {
            DishTypesViewModel model = new DishTypesViewModel
            {
                SubTypeList = await repo.GetSubDishTypesList()
            };

            return(View(model));
        }
Example #6
0
 public async Task <IActionResult> Edit(DishTypesViewModel dishType)
 {
     if (ModelState.IsValid)
     {
         try
         {
             repo.UpdateDish(dishType);
             await repo.Save();
         }
         catch (DbUpdateConcurrencyException)
         {
             if (!DishTypeExists(dishType.Dish.DishTypeID))
             {
                 return(NotFound());
             }
             else
             {
                 throw;
             }
         }
         return(RedirectToAction(nameof(Index)));
     }
     return(View(dishType));
 }
Example #7
0
 public void UpdateDish(DishTypesViewModel dishType)
 {
     _context.Update(dishType.Dish);
 }