public ActionResult Edit(Student student, string ImageValue, HttpPostedFileBase doc)
 {
     if (ModelState.IsValid && doc != null)
     {
         var filename  = Path.GetFileName(doc.FileName);
         var extension = Path.GetExtension(filename).ToLower();
         if (extension == ".jpg" || extension == ".png")
         {
             var path = HostingEnvironment.MapPath(Path.Combine("~/Content/Images/", filename));
             doc.SaveAs(path);
             student.ImageUrl        = "~/Content/Images/" + filename;
             db.Entry(student).State = EntityState.Modified;
             db.SaveChanges();
             return(RedirectToAction("Index"));
         }
         else
         {
             ModelState.AddModelError("", "Document size must be less then 5MB");
             return(View(student));
         }
     }
     else if (ModelState.IsValid)
     {
         student.ImageUrl        = ImageValue;
         db.Entry(student).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ModelState.AddModelError("", "Photo is required");
     return(View(student));
 }
示例#2
0
        public IHttpActionResult PutFileUpload(int id, FileUpload fileUpload)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != fileUpload.imageid)
            {
                return(BadRequest());
            }

            db.Entry(fileUpload).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!FileUploadExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
示例#3
0
 public ActionResult Edit([Bind(Include = "FileID,FilePath")] File file)
 {
     if (ModelState.IsValid)
     {
         db.Entry(file).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(file));
 }