public async Task <ActionResult> Edit(PersonalEditViewModel editedDonor) { var donor = bddb.Donor.Where(d => d.Email == SessionState.Current.UserEmail).FirstOrDefault(); if (ModelState.IsValid) { using (var transaction = bddb.Database.BeginTransaction()) { donor.BirthDate = editedDonor.BirthDate; donor.DonorSexId = editedDonor.DonorSexId; donor.SocialInsuranceNumber = editedDonor.SocialInsuranceNumber; donor.ABOBloodGroupId = editedDonor.ABOBloodGroupId; donor.RhBloodGroupId = editedDonor.RhBloodGroupId; donor.LastName = editedDonor.LastName; donor.FirstName = editedDonor.FirstName; bddb.Entry(donor).State = EntityState.Modified; await bddb.SaveChangesAsync(); transaction.Commit(); UpdateUserNameInSession(); return(RedirectToAction("Index")); } } ViewBag.ABOBloodGroupId = new SelectList(bddb.ABOBloodGroup, "Id", "Name", donor.ABOBloodGroupId); ViewBag.DonorSexId = new SelectList(bddb.DonorSex, "Id", "Name", donor.DonorSexId); ViewBag.RhBloodGroupId = new SelectList(bddb.RhBloodGroup, "Id", "Name", donor.RhBloodGroupId); return(View(donor)); }
public async Task <IActionResult> PersonalEdit([Bind("Ten,NgaySinh,GioiTinh,SDT,Email,DiaChi")] PersonalEditViewModel model) { if (ModelState.IsValid) { var user = await _userManager.GetUserAsync(User); if (user == null) { return(RedirectToAction("Login")); } user.Ten = model.Ten; user.NgaySinh = model.NgaySinh; user.GioiTinh = model.GioiTinh; user.SDT = model.SDT; user.Email = model.Email; user.DiaChi = model.DiaChi; var result = await _userManager.UpdateAsync(user); if (result.Succeeded) { TempData["messageSuccess"] = "Thông tin của bạn đã cập nhật!"; return(RedirectToAction("PersonalDetails", new { taiKhoan = user.UserName })); } foreach (var error in result.Errors) { ModelState.AddModelError("", error.Description); } } return(View(model)); }
// GET: Personal/Edit/ public ActionResult Edit() { if (SessionState.Current.UserEmail == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Donor donor = bddb.Donor.Where(d => d.Email == SessionState.Current.UserEmail).FirstOrDefault(); if (donor == null) { return(HttpNotFound()); } PersonalEditViewModel model = new PersonalEditViewModel { BirthDate = donor.BirthDate, DonorSexId = donor.DonorSexId, SocialInsuranceNumber = donor.SocialInsuranceNumber, ABOBloodGroupId = donor.ABOBloodGroupId, RhBloodGroupId = donor.RhBloodGroupId, LastName = donor.LastName, FirstName = donor.FirstName }; ViewBag.ABOBloodGroupList = new SelectList(bddb.ABOBloodGroup, "Id", "Name", donor.ABOBloodGroupId); ViewBag.DonorSexList = new SelectList(bddb.DonorSex, "Id", "Name", donor.DonorSexId); ViewBag.RhBloodGroupList = new SelectList(bddb.RhBloodGroup, "Id", "Name", donor.RhBloodGroupId); return(View(model)); }
public async Task <IActionResult> PersonalEdit() { var user = await _userManager.GetUserAsync(User); if (user == null) { return(RedirectToAction("Login")); } var model = new PersonalEditViewModel { Ten = user.Ten, NgaySinh = user.NgaySinh, GioiTinh = user.GioiTinh, SDT = user.SDT, Email = user.Email, DiaChi = user.DiaChi }; return(View(model)); }