public bool EditTasting(TastingEdit model) { using (var ctx = new ApplicationDbContext()) { var entity = ctx.Tastings.FirstOrDefault(p => p.TastingID == model.TastingID); entity.Rating = model.Rating; entity.Comment = model.Comment; entity.DateOfTasting = model.DateOfTasting; return(ctx.SaveChanges() == 1); } }
public ActionResult Edit(int id) { var service = CreateTastingService(); var detail = service.GetTastingById(id); var model = new TastingEdit { OwnerId = detail.OwnerId, TastingId = detail.TastingId, TastingDate = detail.TastingDate, Title = detail.Title, Host = detail.Host }; return(View(model)); }
public bool UpdateTasting(TastingEdit model) { using (var ctx = new ApplicationDbContext()) { var entity = ctx.Tastings .Single(e => e.TastingId == model.TastingId && e.OwnerId == _userId); entity.OwnerId = model.OwnerId; entity.TastingId = model.TastingId; entity.TastingDate = model.TastingDate; entity.Title = model.Title; entity.Host = model.Host; entity.ModifiedUtc = DateTimeOffset.Now; return(ctx.SaveChanges() == 1); } }
public ActionResult Edit(int id, TastingEdit model) { if (!ModelState.IsValid) { return(View(model)); } if (model.TastingId != id) { ModelState.AddModelError("", "Id Mistmatch"); return(View(model)); } var service = CreateTastingService(); if (service.UpdateTasting(model)) { TempData["SaveResult"] = "Your Tasting was updated."; return(RedirectToAction("Index")); } ModelState.AddModelError("", "Your Tasting could not be updated."); return(View(model)); }