// GET: Dashboard/EditProfile public ActionResult EditProfile() { var userId = this.User.FindFirstValue(ClaimTypes.NameIdentifier); var owner = uow.GetPortofolioByUser(new Guid(userId)); if (owner == null) { //goto create return(RedirectToAction("CreateProfile")); } var model = new OwnerBasicViewModel { OwnerID = owner.Id, FullName = owner.FullName, Job = owner.Job, Avatar = owner.Avatar, Country = owner.Address.Country, City = owner.Address.City, Street = owner.Address.Street, Number = owner.Address.Number, AddressId = owner.AddressId }; return(View(model)); }
public ActionResult EditProfile(OwnerBasicViewModel model) { try { var userId = this.User.FindFirstValue(ClaimTypes.NameIdentifier); string FileName = model.Avatar; if (model.AvatarUploader != null) { FileName = model.AvatarUploader.FileName.Split(@"\", StringSplitOptions.None).Last(); string uploadFolder = Path.Combine(hosting.WebRootPath, "img"); string FullPath = Path.Combine(uploadFolder, FileName); model.AvatarUploader.CopyTo(new FileStream(FullPath, FileMode.Create)); } else { if (model.Avatar == "") { ModelState.AddModelError("upload", "Please upload an image"); } } if (!ModelState.IsValid) { ModelState.AddModelError("", "please fix all errors"); return(View(model));//return data as it is } /// var addr = new Address { Id = model.AddressId, City = model.City, Country = model.Country, Street = model.Street, Number = model.Number }; var owner = new Owner { Id = model.OwnerID, FullName = model.FullName, Job = model.Job, Avatar = FileName, UserId = new Guid(userId), Address = addr }; uow.UpdateOwner(owner); return(Redirect("/Portofolio/Index/" + owner.Id)); } catch { return(View(model)); } }