public ActionResult Edit(int?id, [Bind(Include = "SuppliesID,Name,Value,Number,Available,ClassRoom")] Supplies supplies, HttpPostedFileBase upload) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } // Very long function to detect if a photo exists on this supply id. Delete it then replace it will the supplied photo. var updateSupply = db.Supplies.Find(supplies.SuppliesID); if (TryUpdateModel(updateSupply, "", new string[] { "SuppliesID", "Name", "Value", "Number", "Available", "ClassRoom" })) { } if (ModelState.IsValid) { try { if (upload != null && upload.ContentLength > 0) { if (updateSupply.Files.Any(x => x.FileType == FileType.Photo)) { db.Files.Remove(updateSupply.Files.First(x => x.FileType == FileType.Photo)); } var photo = new File { FileName = System.IO.Path.GetFileName(upload.FileName), FileType = FileType.Photo, ContentType = upload.ContentType }; using (var reader = new System.IO.BinaryReader(upload.InputStream)) { photo.Content = reader.ReadBytes(upload.ContentLength); } updateSupply.Files = new List <File> { photo }; db.Entry(updateSupply).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } } catch (RetryLimitExceededException) { ModelState.AddModelError("", "Unable to add a profile image."); } } db.Entry(updateSupply).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult Edit([Bind(Include = "CheckOutBookID,StudentsID,BooksID,DepartmentID,DueDate,ReturnedBook,ReturnedDate,CheckedOutDate")] CheckOutBook checkOutBook) { if (checkOutBook.ReturnedBook) { DateTime CurrentDate = DateTime.Now; checkOutBook.ReturnedDate = CurrentDate; db.Entry(checkOutBook).State = EntityState.Modified; } if (ModelState.IsValid) { db.Entry(checkOutBook).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.BooksID = new SelectList(db.Books, "BooksID", "Title", checkOutBook.BooksID); ViewBag.DepartmentID = new SelectList(db.Departments, "DepartmentID", "DepName", checkOutBook.DepartmentID); ViewBag.StudentsID = new SelectList(db.Students, "StudentsID", "StudentName", checkOutBook.StudentsID); return(View(checkOutBook)); }
public ActionResult Edit([Bind(Include = "DepartmentID,DepName,Location,Telephone,Email,WebAddress,DepChair,DepChairEmail")] Department department) { if (ModelState.IsValid) { db.Entry(department).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(department)); }
public ActionResult Edit([Bind(Include = "UserRolesId,UserRoleName")] UserRoles userRoles) { if (ModelState.IsValid) { db.Entry(userRoles).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(userRoles)); }
public ActionResult Edit([Bind(Include = "StudentsID,UVUID,StudentName,StudentEmail,StudentPhone,HasCheckedOutBooks,HasCheckedOutSupplies")] Students students) { if (ModelState.IsValid) { db.Entry(students).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(students)); }