//[HttpPost] public async Task <ActionResult> CountFood(string name) { var result = db.countFoodRequirement(name); Food food = db.Foods.Where(x => x.name.Equals(name)).FirstOrDefault(); db.Entry(food).State = EntityState.Modified; food.requirement = result; await db.SaveChangesAsync(); return(RedirectToAction("Details", new { id = food.id })); }
public async Task <ActionResult> CountFoodRequirement(string name) { try { var result = db.countFoodRequirement(name); Food food = db.Foods.Where(x => x.name == name).SingleOrDefault(); db.Entry(food).State = EntityState.Modified; food.requirement = result; } catch (Exception e) { return(RedirectToAction("Index", new { message = "Wystąpił błąd, spróbuj ponownie." })); }; return(RedirectToAction("Index")); }