public ActionResult EditMember(MembersViewModel wvm) { if (ModelState.IsValid) { var member = _uow.Members.Get(wvm.Id); if (member != null) { string fileName = Path.GetFileNameWithoutExtension(wvm.MemeberImageThumbnailUrl.FileName); string extension = Path.GetExtension(wvm.MemeberImageThumbnailUrl.FileName); fileName = fileName + DateTime.Now.ToString("yymmssffff") + extension; wvm.MemberImageUrl = fileName; fileName = Path.Combine(Server.MapPath("~/Content/Images/"), fileName); member.MemberName = wvm.FirstName + "" + wvm.LastName + "" + wvm.OtherName; member.PhoneNumber = wvm.PhoneNumber; member.Address = wvm.Address; member.MemberImageUrl = wvm.MemberImageUrl; member.MemeberImageThumbnailUrl = wvm.MemberImageUrl; if (wvm.MemeberImageThumbnailUrl != null && wvm.MemeberImageThumbnailUrl.ContentLength > 0) { wvm.MemeberImageThumbnailUrl.SaveAs(fileName); } _uow.Commit(); TempData["message"] = $"{member.MemberName} was successfully edited "; } return(RedirectToAction("Index")); } else { return(View(wvm)); } }
public ActionResult EditMember(int id) { var member = _uow.Members.Get(id); var wvm = new MembersViewModel { FirstName = member.MemberName, Address = member.Address, Profession = member.Profession, PhoneNumber = member.PhoneNumber, MemberImageUrl = member.MemberImageUrl }; return(View(wvm)); }
public ActionResult Member(MembersViewModel mvm) { if (ModelState.IsValid) { var member = _uow.Members.Find(r => r.MemberName == mvm.LastName).FirstOrDefault(); string fileName = Path.GetFileNameWithoutExtension(mvm.MemeberImageThumbnailUrl.FileName); string extension = Path.GetExtension(mvm.MemeberImageThumbnailUrl.FileName); fileName = fileName + DateTime.Now.ToString("yymmssffff") + extension; mvm.MemberImageUrl = fileName; fileName = Path.Combine(Server.MapPath("~/Content/Images/"), fileName); mvm.MemeberImageThumbnailUrl.SaveAs(fileName); var _member = new Member { MemberName = mvm.FirstName + " " + mvm.OtherName + " " + mvm.LastName, Address = mvm.Address, Profession = mvm.Profession, SpouseName = mvm.SpouseName, DateOfBirth = mvm.DateOfBirth, MemberImageUrl = mvm.MemberImageUrl, MemeberImageThumbnailUrl = mvm.MemberImageUrl, WeddingAnniversary = mvm.WeddingAnniversary, PhoneNumber = mvm.PhoneNumber, Married = mvm.Married }; _uow.Members.Add(_member); _uow.Commit(); TempData["message"] = string.Format("{0} has been saved.", mvm.FirstName); return(RedirectToAction("Index")); } else { var member = _uow.Members.GetAll().Select(r => r.MemberName); return(View(mvm)); } }