public async Task <ActionResult> Edit([Bind(Include = "IdLesson,Name")] LessonViewModels lessonViewModels) { if (ModelState.IsValid) { var entity = await db.Lessons.FindAsync(lessonViewModels.IdLesson); entity.LessonName = lessonViewModels.Name; db.Entry(entity).State = EntityState.Modified; await db.SaveChangesAsync(); return(RedirectToAction("Index")); } return(View(lessonViewModels)); }
public async Task <ActionResult> Create([Bind(Include = "IdLesson,Name")] LessonViewModels lessonViewModels) { if (ModelState.IsValid) { db.Lessons.Add(new Lesson { LessonName = lessonViewModels.Name, }); await db.SaveChangesAsync(); return(RedirectToAction("Index")); } return(View(lessonViewModels)); }
// GET: Lessons/Edit/5 public async Task <ActionResult> Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } var lessons = await Lesson.GetAll(db); LessonViewModels lessonViewModels = lessons.Where(x => x.IdLesson == id).Select(x => new LessonViewModels() { IdLesson = x.IdLesson, Name = x.Name }).FirstOrDefault(); if (lessonViewModels == null) { return(HttpNotFound()); } return(View(lessonViewModels)); }