public ActionResult Edit([Bind(Include = "UserID,FirstName,LastName")] UserDetail userDetail)
 {
     if (ModelState.IsValid)
     {
         db.Entry(userDetail).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(userDetail));
 }
 public ActionResult Edit([Bind(Include = "CourseID,CourseName,Description,IsActive")] Courses courses)
 {
     if (ModelState.IsValid)
     {
         db.Entry(courses).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(courses));
 }
 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);
     return(View(lessonView));
 }
Beispiel #4
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.Courses1, "CourseID", "CourseName", courseCompletion.CourseID);
     return(View(courseCompletion));
 }
Beispiel #5
0
        public ActionResult Edit([Bind(Include = "LessonID,LessonTitle,CourseID,Introduction,VideoURL,PdfFileName,IsActive")] Lesson lesson, HttpPostedFileBase fulPdf) //Step 1 adding HttpPostedFileBase fulPdf
        {
            if (ModelState.IsValid)
            {
                #region File Upload for EDIT
                if (fulPdf != null)//if it has a value, then they uploaded a file! So we process it
                {
                    //get image and assign to variable
                    string pdfName = fulPdf.FileName;

                    //declare and assign ext value
                    string ext = pdfName.Substring(pdfName.LastIndexOf('.'));//gets extension including the "." (period)
                    //declare list of valid extensions
                    string[] goodExts = { ".pdf" };
                    //check the ext variable in lowercase vs that valid list and MAX file size 4 MB in ASPNET
                    if (goodExts.Contains(ext.ToLower()) && (fulPdf.ContentLength <= 4194304))
                    {
                        //if it is in the list rename using a GUID (uniqueness is vital to avoid overwrite)
                        pdfName = Guid.NewGuid() + ext;
                        //save to the webserver (Server.MapPath figures out path)
                        fulPdf.SaveAs(Server.MapPath("~/Content/pdfs/" + pdfName));

                        //HOUSEKEEPING for the edit: Delete old file on record if not the default
                        if (lesson.PdfFileName != null && lesson.PdfFileName != "noImage.pdf")
                        {
                            //remove original file
                            System.IO.File.Delete(Server.MapPath("~/Content/pdfs/" + lesson.PdfFileName));
                        }

                        //only if file upload OK, file upload, change the new db record's file field to reflect the name
                        lesson.PdfFileName = pdfName;
                    }
                    else
                    {
                        //if you landed here, something went wrong..
                        //either file size too big, or unacceptable file type
                        //we have options - throw an error (catch or don't) Or just default to no
                        //FOR EDIT, throw error or remove the ELSE and leave image the way it was
                        throw new ApplicationException("Incorrect file type (use PDF), or file exceeds 4MB (reduce and try again)");
                    } //end if tree for good exts and file size
                }     //end if fup exists

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