public ActionResult EditAccounts(EditAccountsModel model) { if (ModelState.IsValid) { var account = _acc.GetById(model.Id); if (account == null) { return(RedirectToAction("Index", new { message = "Thông tin đăng nhập không chính xác", messageType = "error" })); } var pro = _pro.GetById(account.ProfileId); if (pro == null) { return(RedirectToAction("Index", new { message = "Không tìm thấy thông tin tài khoản", messageType = "error" })); } pro.Address = model.Address; pro.CompanyCode = model.CompanyCode; pro.CompanyName = model.CompanyName; pro.Email = model.Email; pro.Phone = model.Phone; pro.Province = model.Province; pro.TaxAgencyCode = model.TaxAgencyCode; pro.TaxAgencyName = model.TaxAgencyName; if (!_pro.Update(pro)) { return(RedirectToAction("Index", new { message = "Có lỗi khi cập nhật thông tin người dùng. Vui lòng thử lại sau", messageType = "error" })); } account.CompanyCode = model.CompanyCode; account.CompanyName = model.CompanyName; account.Address = model.Address; account.BankAccount = model.BankAccount; account.Phone = model.Phone; account.Representative = model.Representative; if (!_acc.Add(account)) { return(RedirectToAction("Index", new { message = "Có lỗi khi cập nhật thông tin tài khoản. Vui lòng thử lại sau", messageType = "error" })); } return(RedirectToAction("Index", new { message = "Cập nhật thông tin tài khoản thành công", messageType = "info" })); } else { ViewBag.Province = model.ProvinceId; ViewBag.District = model.TaxAgencyCode; model.ListProvince = ListTaxAgency(); return(View(model)); } }
public ActionResult EditAccounts(int id) { var acc = _acc.GetById(id); var pro = _pro.GetById(acc.ProfileId); var registerMode = new EditAccountsModel() { ListProvince = ListTaxAgency(), CompanyCode = acc.CompanyCode, CompanyName = acc.CompanyName, Representative = acc.Representative, Address = acc.Address, Phone = acc.Phone, BankAccount = acc.BankAccount, Province = pro.Province, TaxAgencyCode = pro.TaxAgencyCode, Email = pro.Email }; var list = ListTaxAgency(); foreach (var p in list) { if (p != null && pro.Province.Equals(p.Text)) { ViewBag.Province = p.Value; break; } } ViewBag.District = pro.TaxAgencyCode; return(View(registerMode)); }