Пример #1
0
        public ActionResult EditLesson(EditLesson model)
        {
            ViewBag.LinkTypes = db.RunListProcedure<LinkType>("[SelectAllLinkTypes]", new { });
            if (!ModelState.IsValid)
            {
                return View("EditLesson", model);
            }
            else
            {
                string username = User.Identity.Name;
                User user;
                try
                {
                    user = db.RunProcedure<User>("SelectUserByName", new { UserName = username });
                }
                catch (Exception ex)
                {
                    ModelState.AddModelError("", "Please Login to submit Course.");
                    if (Request.IsAjaxRequest())
                    {
                        return PartialView(model);
                    }
                    else
                    {
                        return View(model);
                    }

                }
                Lesson lesson = db.RunListProcedure<Lesson>("UpdateLesson", new
                {
                    lessonId = Convert.ToInt32(this.ControllerContext.RouteData.Values["id"]),
                    courseId = model.CourseId,
                    userId = user.UserId,
                    lessonName = model.LessonName,
                    link = model.Link,
                    lessonText = model.LessonText??"",
                    LinkTypeId = model.LinkTypeId,
                    SectionName = !string.IsNullOrEmpty(model.SectionName) ? model.SectionName : null
                }).First();

                return RedirectToAction("Lesson", "Apps", new { id = Convert.ToInt32(this.ControllerContext.RouteData.Values["id"]) });
            }
        }
Пример #2
0
        public ActionResult EditLesson()
        {
            int id = Convert.ToInt32(this.ControllerContext.RouteData.Values["id"]);
            ViewBag.courseId = id;
            Lesson lesson = db.RunListProcedure<Lesson>("SelectLessonById", new { lessonId = id }).First();
            List<LinkType> linkTypes = db.RunListProcedure<LinkType>("[SelectAllLinkTypes]", new { });
            linkTypes.Add(new LinkType(){LinkTypeId = 0, LinkTypeName = ""});
            int linktypeId = linkTypes.First(x => x.LinkTypeId == lesson.LinkTypeId).LinkTypeId;

            EditLesson model = new EditLesson()
            {
                CourseId = lesson.CourseId,
                LessonId = lesson.LessonId,
                LessonName = lesson.LessonName,
                LessonText = lesson.LessonText,
                Link = lesson.Link,
                LinkTypeId = linktypeId,
                SectionName = lesson.SectionName
            };
            ViewBag.LinkTypes = linkTypes;

            return View(model);
        }