Exemplo n.º 1
0
 public ActionResult Edit([Bind(Include = "LessonViewId,UserId,LessonId,DateViewed")] LessonView lessonView)
 {
     if (ModelState.IsValid)
     {
         db.Entry(lessonView).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.LessonId = new SelectList(db.Lessons, "LessonId", "LessonTitle", lessonView.LessonId);
     ViewBag.UserId   = new SelectList(db.UserDetails, "UserId", "FirstName", lessonView.UserId);
     return(View(lessonView));
 }
Exemplo n.º 2
0
 public ActionResult Edit([Bind(Include = "CourseCompletionId,UserId,CourseId,DateCompleted")] CourseCompletion courseCompletion)
 {
     if (ModelState.IsValid)
     {
         db.Entry(courseCompletion).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.CourseId = new SelectList(db.Courses, "CourseId", "CourseName", courseCompletion.CourseId);
     ViewBag.UserId   = new SelectList(db.UserDetails, "UserId", "FirstName", courseCompletion.UserId);
     return(View(courseCompletion));
 }
Exemplo n.º 3
0
        public ActionResult Edit([Bind(Include = "LessonId,LessonTitle,CourseId,Introduction,VideoURL,PdfFileName,IsActive")] Lesson lesson, HttpPostedFileBase pdfFile)
        {
            if (ModelState.IsValid)
            {
                string imgName = "Blank.pdf";
                #region File Upload
                if (pdfFile != null)
                {
                    imgName = pdfFile.FileName;

                    string ext = imgName.Substring(imgName.LastIndexOf("."));

                    string[] goodExts = { ".pdf", ".jpg", ".jpeg", ".png" };

                    if (goodExts.Contains(ext.ToLower()) && (pdfFile.ContentLength <= 4194304))
                    {
                        imgName = Guid.NewGuid() + ext;
                        pdfFile.SaveAs(Server.MapPath("~/Content/lessons/" + imgName));
                    }
                    else
                    {
                        imgName = "Blank.pdf";
                    }
                }

                lesson.PdfFileName = imgName;
                #endregion
                db.Entry(lesson).State = EntityState.Modified;
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }
            ViewBag.CourseId = new SelectList(db.Courses, "CourseId", "CourseName", lesson.CourseId);


            return(View(lesson));
        }
Exemplo n.º 4
0
        public ActionResult Edit([Bind(Include = "CourseId,CourseName,CourseDescription,IsActive")] Course course)
        {
            if (ModelState.IsValid)
            {
                db.Entry(course).State = EntityState.Modified;
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }


            #region Lesson and Course IsActive v1
            //if (course.IsActive == false && lesson.CourseId == course.CourseId && lesson.IsActive == true)
            //{
            //    lesson.IsActive = false;
            //}
            //else if (course.IsActive == true && lesson.CourseId == course.CourseId && lesson.IsActive == false)
            //{
            //    lesson.IsActive = true;
            //}
            //else
            //{
            //    return RedirectToAction("Edit/" + course.CourseId);
            //}
            #endregion
            #region Lesson and Course IsActive v2
            //if (lesson.CourseId == course.CourseId && course.IsActive == false && lesson.IsActive == true)
            //{
            //    lesson.IsActive = !lesson.IsActive;
            //}
            //else if (lesson.CourseId == course.CourseId && course.IsActive == true && lesson.IsActive == false)
            //{
            //    !lesson.IsActive = lesson.IsActive;
            //}
            #endregion
            #region Lesson and Course IsActive v3
            //Lesson lesson = new Lesson();
            //if (lesson.CourseId == course.CourseId && !course.IsActive)
            //{
            //    if (!course.IsActive)
            //    {
            //        lesson.IsActive = !lesson.IsActive;
            //    }
            //    else
            //    {
            //        lesson.IsActive = lesson.IsActive;
            //    }
            //}
            //db.SaveChanges();
            #endregion


            var lesson = (from l in db.Lessons
                          where l.CourseId == course.CourseId
                          select l).Single();

            if (course.IsActive == false)
            {
                lesson.IsActive = false;
            }
            else
            {
                lesson.IsActive = true;
            }
            db.SaveChanges();

            return(View(course));
        }