public ActionResult Edit([Bind(Include = "UserID,FirstName,LastName,AvatarImage")] UserDetail userDetail, HttpPostedFileBase avatarImage)
        {
            if (ModelState.IsValid)
            {
                #region Simple File Upload
                //set a default image name (noImage.jpg)

                //if the input has a file (is not null)
                if (avatarImage != null)
                {
                    //store the new file name
                    string image = avatarImage.FileName;

                    //extract the extension and save it in a variable
                    string ext = image.Substring(image.LastIndexOf("."));//.jpg, .gif, etc.
                    //create a whitelist of valid extensions
                    string[] goodExts = new string[] { ".jpg", ".jpeg", ".gif", ".png" };

                    //check our extension vs the whitelist
                    if (goodExts.Contains(ext.ToLower()))
                    {
                        //if we have a good ext, creat a new Unique file name and add the extension
                        //Global Unique Identifier
                        image = Guid.NewGuid() + ext;
                        //save the new file to the webserver
                        //avatarImage.SaveAs(Server.MapPath("~/Content/Images/Users/" + image));

                        #region to generate full & thumnail images //! using FamilySite.Domain.Services
                        string savePath = Server.MapPath("~/Content/Images/Users/");

                        Image convertedImage = Image.FromStream(avatarImage.InputStream);
                        ImageUtilities.ResizeImage(savePath, image, convertedImage, 500, 100);
                        userDetail.AvatarImage = image;
                        #endregion

                        if (Session["currentImage"].ToString() != "noImage.jpg")
                        {
                            System.IO.File.Delete(Server.MapPath("~/Content/Images/Users/" + Session["currentImage"].ToString()));
                            System.IO.File.Delete(Server.MapPath("~/Content/Images/Users/t_" + Session["currentImage"].ToString()));
                        }
                    }
                }

                //no matter what - add the image value back to the record.
                //save to DB //associating the uploaded file (name) to the model record being added
                #endregion

                db.Entry(userDetail).State = EntityState.Modified;
                db.SaveChanges();

                return(RedirectToAction("Index"));
            }

            //ViewBag.UserID = new SelectList(db.AspNetUsers, "Id", "Email", userDetail.UserID);
            return(View(userDetail));
        }
Exemplo n.º 2
0
        public ActionResult Edit([Bind(Include = "LessonID,LessonTitle,CourseID,Introduction,VideoURL,PdfFileName,IsActive,ReservationLimit")] Lesson lesson, HttpPostedFileBase pdfFile)
        {
            if (ModelState.IsValid)
            {
                if (pdfFile != null)
                {
                    string lessonMaterial = pdfFile.FileName;
                    string ext            = lessonMaterial.Substring(lessonMaterial.LastIndexOf("."));
                    //.pdf, .doc, .docx, .html, .xlsx, .jpg
                    string[] goodExts = new string[] { ".pdf", ".doc", ".docx", ".html", ".xlsx", ".xls", ".jpg", ".png", ".gif", ".jpeg" };
                    if (goodExts.Contains(ext.ToLower()))
                    {
                        lessonMaterial = Guid.NewGuid() + lessonMaterial;
                        pdfFile.SaveAs(Server.MapPath("~/Content/textfiles/Lessons/" + lessonMaterial));
                        lesson.PdfFileName = lessonMaterial;

                        if (Session["currentFile"].ToString() != "noFile.jpg")
                        {
                            System.IO.File.Delete(Server.MapPath("~/Content/textfiles/Lessons/" + Session["currentFile"].ToString()));
                        }
                    }
                }

                db.Entry(lesson).State = EntityState.Modified;
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }
            ViewBag.CourseID = new SelectList(db.Courses1, "CourseID", "CourseName", lesson.CourseID);
            return(View(lesson));
        }
Exemplo n.º 3
0
 public ActionResult Edit([Bind(Include = "CourseID,CourseName,Description,IsActive")] Course course)
 {
     if (ModelState.IsValid)
     {
         db.Entry(course).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(course));
 }
Exemplo n.º 4
0
 public ActionResult Edit([Bind(Include = "ReservationID,ReservationDate,UserID,LessonID")] Reservation reservation)
 {
     if (ModelState.IsValid)
     {
         db.Entry(reservation).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.UserID   = new SelectList(db.UserDetails, "UserID", "FirstName", reservation.UserID);
     ViewBag.LessonID = new SelectList(db.Lessons, "LessonID", "LessonTitle", reservation.LessonID);
     return(View(reservation));
 }
Exemplo n.º 5
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);
     ViewBag.UserID   = new SelectList(db.UserDetails, "UserID", "FirstName", courseCompletion.UserID);
     return(View(courseCompletion));
 }
Exemplo n.º 6
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));
 }