public ActionResult EditPost(EditInterestBm bind) { if (this.ModelState.IsValid) { HttpPostedFileBase file = this.Request.Files["salePicture"]; if (file == null || !file.ContentType.Contains("image")) { this.ModelState.AddModelError("profilePicture", "Invalid image"); } else { var pathToFolder = this.Server.MapPath("~/SalePictures"); string fileName = Path.GetFileName(file.FileName); string path = this.service.GetAdequatePathToSave(pathToFolder, fileName); file.SaveAs(path); var imageUrl = this.service.GetImageUrl(path); bind.SalePicture = imageUrl; string currentUsername = this.User.Identity.Name; this.service.EditInterest(bind, currentUsername); return(this.RedirectToAction("Mine")); } } EditInterestVm vm = this.service.GetEditVm(bind.Id); return(this.View(vm)); }
public void EditInterest(EditInterestBm bind, string currentUsername) { Interest interest = this.Context.Interests.Find(bind.Id); interest.Url = bind.SalePicture; interest.Category = bind.Category; interest.PhoneNumber = bind.PhoneNumber; interest.Title = bind.Title; var user = interest.User; this.Context.SaveChanges(); }