public async Task <ActionResult> Edit([Bind(Include = "ImageLocation,id")] Photo photo) { if (ModelState.IsValid) { db.Entry(photo).State = EntityState.Modified; await db.SaveChangesAsync(); return(RedirectToAction("Index")); } return(View(photo)); }
public async Task <ActionResult> Create([Bind(Include = "RentCost,Description,PhotoID,Street,City,Country,ZipCode,State")] Appartment appartment, HttpPostedFileBase photoInput) { bool isValid = ModelState.IsValid; if (isValid && photoInput != null && photoInput.ContentLength > 0) { if (!photoInput.ContentType.StartsWith("image/")) { isValid = false; ModelState.AddModelError("PhotoID", "Photo much be an image"); } } if (isValid) { if (photoInput != null && photoInput.ContentLength > 0) { var imageFolder = Server.MapPath("/UploadedImages"); var imageFileName = DateTime.Now.ToString("yyyy-MM-dd_HHmmss_fff") + "_" + photoInput.FileName; var imagePath = Path.Combine(imageFolder, imageFileName); photoInput.SaveAs(imagePath); var photo = new Photo() { ImageLocation = imageFileName }; appartment.Photo = photo; } var userId = User.Identity.GetUserId(); var appartmentOwner = db.AppartmentOwners.Find(userId); appartmentOwner.Appartment = appartment; db.Entry(appartmentOwner).State = EntityState.Modified; await db.SaveChangesAsync(); return(RedirectToAction("Index")); } ViewBag.PhotoID = new SelectList(db.Photos, "ID", "ImageLocation", appartment.PhotoID); return(View(appartment)); }
public ActionResult Edit([Bind(Include = "Id,FirstName,LastName,PhoneNumber,EmailAddress,Description,PropertyBool,AddressID,ProfileLinkerId,PhotoID,City")] UserProfile userProfile) { if (ModelState.IsValid) { db.Entry(userProfile).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.AddressID = new SelectList(db.Addresses, "ID", "City", userProfile.AddressID); ViewBag.PhotoID = new SelectList(db.Photos, "ID", "ImageLocation", userProfile.PhotoID); return(View(userProfile)); }
public async Task <ActionResult> Edit([Bind(Include = "SenderID,RecieverID,ProfileLinkerID,MessageID")] MessageBoard messageBoard) { if (ModelState.IsValid) { db.Entry(messageBoard).State = EntityState.Modified; await db.SaveChangesAsync(); return(RedirectToAction("Index")); } ViewBag.MessageID = new SelectList(db.SingleMessages, "id", "MessageText", messageBoard.MessageID); ViewBag.ProfileLinkerID = new SelectList(db.ProfileLinkers, "ID", "UserLinkedId", messageBoard.ProfileLinkerID); ViewBag.RecieverID = new SelectList(db.UserProfiles, "Id", "FirstName", messageBoard.RecieverID); ViewBag.SenderID = new SelectList(db.UserProfiles, "Id", "FirstName", messageBoard.SenderID); return(View(messageBoard)); }