public ActionResult Edit([Bind(Include = "CourseID,CourseName,CourseDescription,IsActive")] Cours cours)
 {
     if (ModelState.IsValid)
     {
         db.Entry(cours).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(cours));
 }
Beispiel #2
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.UserDets, "UserID", "FirstName", lessonView.UserID);
     return(View(lessonView));
 }
 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.UserDets, "UserID", "FirstName", courseCompletion.UserID);
     return(View(courseCompletion));
 }
        public ActionResult Edit([Bind(Include = "LessonID,LessonTitle,CourseID,Introduction,VideoURL,PdfFileName,IsActive,QuizRequired,VideoRequired")] Lesson lesson, HttpPostedFileBase fupPDF)
        {
            if (ModelState.IsValid)
            {
                if (fupPDF != null)
                {
                    string pdfName = fupPDF.FileName;
                    string ext     = pdfName.Substring(pdfName.LastIndexOf("."));
                    if (ext.ToLower() == ".pdf")
                    {
                        pdfName = Guid.NewGuid() + ext;
                        fupPDF.SaveAs(Server.MapPath("~/Content/pdfs/" + pdfName));

                        if (lesson.PdfFileName != null && lesson.PdfFileName != "DefaultPDF/pdf")
                        {
                            System.IO.File.Delete(Server.MapPath("~/Content/pdfs/" + lesson.PdfFileName));
                        } //end if deleted previous pdf
                        lesson.PdfFileName = pdfName;
                    }     //end if assigned new name in here so that it only happens if the thing they uploaded was a pdf
                }         //end if

                if (lesson.VideoURL != null && lesson.VideoURL != "")
                {
                    var    v   = lesson.VideoURL.IndexOf("v=");
                    var    amp = lesson.VideoURL.IndexOf("&", v);
                    string vid;
                    // if the video id is the last value in the url
                    if (amp == -1)
                    {
                        vid = lesson.VideoURL.Substring(v + 2);
                        // if there are other parameters after the video id in the url
                    }
                    else
                    {
                        vid = lesson.VideoURL.Substring(v + 2, amp - (v + 2));
                    }
                    lesson.VideoURL = vid;
                }
                else
                {
                    lesson.VideoURL = null;
                }


                db.Entry(lesson).State = EntityState.Modified;
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }
            ViewBag.CourseID = new SelectList(db.Courses, "CourseID", "CourseName", lesson.CourseID);
            return(View(lesson));
        }