public ActionResult Edit(ExampleUpdate model) { if (!ModelState.IsValid) { ModelState.AddModelError("", "Something is wrong with the Data!"); return(View(model)); } var service = GetCodeExampleService(); if (service.UpdateExample(model)) { return(RedirectToAction(nameof(Index))); } ModelState.AddModelError("", "Something went wrong internally. Please Report the problem"); return(View(model)); }
public bool UpdateExample(ExampleUpdate model) { using (var context = new ApplicationDbContext()) { var entity = context .CodeExamples .Single(j => j.CodeExampleId == model.CodeExampleId); entity.CodeExampleId = model.CodeExampleId; entity.CategoryId = model.CategoryId; entity.ProfileId = model.ProfileId; entity.Title = model.Title; entity.ExampleCode = model.ExampleCode; entity.ExampleDescription = model.ExampleDescription; entity.EditedPost = DateTimeOffset.Now; return(context.SaveChanges() == 1); } }
public ActionResult Edit(int id) { ViewBag.CategoryId = new SelectList(_db.Categories, "CategoryId", "CategoryName"); var service = GetCodeExampleService(); if (!service.GetByIdTest(id)) { return(RedirectToAction(nameof(Index))); } var detail = service.GetById(id); var model = new ExampleUpdate { CodeExampleId = detail.CodeExampleId, CategoryId = detail.CategoryId, ProfileId = detail.ProfileId, Title = detail.Title, UserName = detail.UserName, ExampleCode = detail.ExampleCode, ExampleDescription = detail.ExampleDescription, }; return(View(model)); }