public ActionResult LessonAction(int?id) { ViewBag.drpCourseLevel = CommonController.drpCourseLevel(); ViewBag.drpInstrument = CommonController.drpInstrument(); ViewBag.drpLessonType = CommonController.drpLessonType(); if (id != 0) { Lesson dataset = entities.Lessons.Find(id); return(PartialView(dataset)); } else { return(PartialView()); } }
public ActionResult LessonAction(Lesson lesson) { ModelState.Remove("LessonID"); if (ModelState.IsValid) { string msg = ""; if (lesson.LessonID > 0) { var dataset = entities.Lessons.Where(f => f.LessonID == lesson.LessonID).FirstOrDefault(); if (dataset != null) { dataset.Name = lesson.Name; dataset.Description = lesson.Description; dataset.CourseLevelID = lesson.CourseLevelID; dataset.LessonTypeID = lesson.LessonTypeID; dataset.InstrumentID = lesson.InstrumentID; msg = "Lesson Updated Successfully"; } } else { entities.Lessons.Add(lesson); msg = "New Lesson Added successfully"; } entities.SaveChanges(); return(new JsonResult { Data = new { success = true, action = "Lesson", message = msg }, JsonRequestBehavior = JsonRequestBehavior.AllowGet }); } ViewBag.drpCourseLevel = CommonController.drpCourseLevel(); ViewBag.drpLessonType = CommonController.drpLessonType(); ViewBag.drpInstrument = CommonController.drpInstrument(); return(PartialView(lesson)); }