// GET: Lesson Edit public async Task <IActionResult> Edit(string id) { if (id == null) { ModelState.AddModelError(string.Empty, "Id is not have a value"); } var lesson = new LessonManagerModel() { Lesson = await _schoolDataDbContext.Lessons.FirstOrDefaultAsync(s => s.Id == int.Parse(id)) }; if (lesson == default) { ModelState.AddModelError(String.Empty, "Person Update Error!!"); return(RedirectToAction("List")); } return(View(lesson)); }
// GET: Lesson Details public async Task <IActionResult> Details(string id) { if (id == null) { ModelState.AddModelError(string.Empty, "Id don't have a value"); return(RedirectToAction("List")); } var lesson = new LessonManagerModel { Lesson = await _schoolDataDbContext.Lessons.FirstOrDefaultAsync(s => s.Id == int.Parse(id)) }; if (lesson == null) { ModelState.AddModelError(string.Empty, "Role is not avaliable"); return(RedirectToAction("List")); } return(View(lesson)); }
public async Task <IActionResult> Add([Bind("Name")] LessonManagerModel lessonAddModel) { if (!ModelState.IsValid) { ModelState.AddModelError(string.Empty, "Your information is don't valid"); return(View("Add")); } try { var result = await _schoolDataDbContext.AddAsync(lessonAddModel.Lesson); await _schoolDataDbContext.SaveChangesAsync(); return(RedirectToAction("List")); } catch (DbUpdateException error) { ModelState.AddModelError(string.Empty, "Unable to save changes" + "\n Message:" + error.Message.ToString() + "Inner Exception:" + error.InnerException.ToString()); } return(View(lessonAddModel)); }
public async Task <IActionResult> Edit(string id, LessonManagerModel lessonAddModel) { if (int.Parse(id) != lessonAddModel.Lesson.Id) { ModelState.AddModelError("", "Id is Not Belongs the Role"); return(View(lessonAddModel)); } if (ModelState.IsValid) { var result = _schoolDataDbContext.Lessons.Update(lessonAddModel.Lesson); if (result == null) { ModelState.AddModelError(string.Empty, "Model is not updated"); return(View(lessonAddModel)); } await _schoolDataDbContext.SaveChangesAsync(); return(RedirectToAction("List")); } return(View(lessonAddModel)); }