public async Task UpdateAsync(FoodEdit dto) { var food = await GetByIdAsync(dto.Id); if (food is null) { throw new EntityNotFoundException <Food>(); } mapper.Map(dto, food); await UpdateAsync(food); }
public ActionResult Edit(int id) { var service = CreateFoodService(); var detail = service.GetFoodById(id); var model = new FoodEdit { FoodId = detail.FoodId, Name = detail.Name, Amount = detail.Amount, Calories = detail.Calories }; return(View(model)); }
public IHttpActionResult Put(FoodEdit food) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var service = CreateFoodService(); if (!service.UpdateFoods(food)) { return(InternalServerError()); } return(Ok()); }
public bool UpdateFood(FoodEdit model) { using (var ctx = new ApplicationDbContext()) { var entity = ctx .Foods .Single(e => e.FoodId == model.FoodId && e.OwnerId == _userId); entity.Name = model.Name; entity.Amount = model.Amount; entity.Calories = model.Calories; return(ctx.SaveChanges() == 1); } }
public ActionResult Edit(int id) { var service = CreateFoodService(); var detail = service.GetFoodById(id); var model = new FoodEdit { FoodId = detail.FoodId, Name = detail.Name, Species = detail.Species, //ServingSize = detail.ServingSize, PurchaseLink = detail.PurchaseLink }; return(View(model)); }
public bool UpdateFood(FoodEdit model) { using (var ctx = new ApplicationDbContext()) { var entity = ctx .Foods .Single(e => e.FoodId == model.FoodId && e.OwnerId == _userId); entity.FoodName = model.FoodName; entity.Ingredients = model.Ingredients; entity.Instructions = model.Instructions; entity.FoodServingSize = model.FoodServingSize; return(ctx.SaveChanges() == 1); } }
public bool UpdateFood(FoodEdit model) { using (var ctx = new ApplicationDbContext()) { var entity = ctx .Foods .Single(e => e.FoodId == model.FoodId && e.OwnerId == _userId); entity.Name = model.Name; entity.Species = model.Species; //entity.ServingSize = model.ServingSize; entity.PurchaseLink = model.PurchaseLink; return(ctx.SaveChanges() == 1); } }
public async Task <IActionResult> UpdateAsync([FromBody] FoodEdit dto) { try { await foodService.UpdateAsync(dto); return(Ok()); } catch (EntityNotFoundException <Food> ) { return(NoContent()); } catch (Exception) { return(BadRequest()); } }
public ActionResult Edit(int id) { var service = CreateFoodService(); var detail = service.GetFoodById(id); var model = new FoodEdit { FoodId = detail.FoodId, Name = detail.Name, Description = detail.Description, Ingredients = detail.Ingredients, Cost = detail.Cost, Allergens = detail.Allergens, Servings = detail.Servings, }; return(View(model)); }
public bool UpdateFoods(FoodEdit model) { using (var ctx = new ApplicationDbContext()) { var entity = ctx .Foods .Single(e => e.FoodId == model.FoodId && e.OwnerId == _userId); entity.Name = model.Name; entity.Description = model.Description; entity.Ingrediants = model.Ingredients; entity.Cost = model.Cost; entity.Allergens = model.Allergens; entity.Servings = model.Servings; return(ctx.SaveChanges() == 1); } }
public ActionResult Edit(int id, FoodEdit model) { if (!ModelState.IsValid) { return(View(model)); } if (model.FoodId != id) { ModelState.AddModelError("", "Id Mismatch"); return(View(model)); } var service = CreateFoodService(); if (service.UpdateFoods(model)) { TempData["SaveResult"] = " Your food was updated."; return(RedirectToAction("Index")); } ModelState.AddModelError("", "Your food could not be updated"); return(View(model)); }