public IActionResult UpdateMealHour(int id) { var mealhourVm = _context.MealHour.AsNoTracking() .Where(t => t.MealHourId == id).FirstOrDefault(); MealHourVm m = new MealHourVm() { MealHourId = mealhourVm.MealHourId, MealHourTitle = mealhourVm.MealHourTitle }; return(View(m)); }
public IActionResult MealHourInfo() { var s = _context.MealHour.AsNoTracking().ToList(); var a = new List <MealHourVm>(); int c = 1; foreach (var item in s) { MealHourVm sp = new MealHourVm() { Serial = c, MealHourId = item.MealHourId, MealHourTitle = item.MealHourTitle }; a.Add(sp); c++; } return(View(a)); }
public IActionResult SetMealHour(MealHourVm mealHourVm) { var valid = _context.MealHour.AsNoTracking(). Where(t => t.MealHourTitle == mealHourVm.MealHourTitle).FirstOrDefault(); if (valid != null) { ViewBag.Validation = "You have already added " + mealHourVm.MealHourTitle + "."; return(View()); } MealHour m = new MealHour() { MealHourId = 0, MealHourTitle = mealHourVm.MealHourTitle }; _context.MealHour.Add(m); _context.SaveChanges(); ViewBag.Success = "You have succesfully added " + mealHourVm.MealHourTitle + "."; ModelState.Clear(); return(View()); }
public IActionResult UpdateMealHour(MealHourVm mealHourVm) { var valid = _context.MealHour.AsNoTracking(). Where(t => t.MealHourTitle == mealHourVm.MealHourTitle).FirstOrDefault(); if (valid != null) { ViewBag.Validation = "You have already added."; return(View()); } MealHour m = new MealHour() { MealHourId = mealHourVm.MealHourId, MealHourTitle = mealHourVm.MealHourTitle }; _context.MealHour.Update(m); _context.SaveChanges(); ModelState.Clear(); //ViewBag.Success = "You have succesfully updated."; return(RedirectToAction("MealHourInfo")); }