// GET: SupSetting public ActionResult Index() { var userId = User.Identity.Name; var userData = UserManager.Users.Where(x => x.UserName == userId).SingleOrDefault(); var supData = db.SupplierAccount.Where(x => x.SupplierAccountID == userId).SingleOrDefault(); var supInfoData = db.SupplierInfo.Where(x => x.SupplierCode == supData.SupplierCode).SingleOrDefault(); Sup_parent m = new Sup_parent(); SupInfoViewModel info = new SupInfoViewModel(); SupSettingViewModel sup = new SupSettingViewModel(); info.SupplierName = supInfoData.SupplierName; info.TaxID = supInfoData.TaxID; info.Tel = supInfoData.Tel; info.Address = supInfoData.Address; info.Email = supInfoData.Email; sup.SupplierAccountID = User.Identity.Name; sup.ContactName = userData.RealName; sup.Email = userData.Email; sup.Tel = supData.Tel; sup.Mobile = supData.Mobile; sup.EnableTwoFactorAuth = userData.TwoFactorEnabled; m.SupInfoViewModel = info; m.SupSettingViewModel = sup; return(View(m)); }
public async Task <ActionResult> Index(Sup_parent m) { try { var userId = User.Identity.Name; var userData = UserManager.Users.Where(x => x.UserName == userId).SingleOrDefault(); var supData = db.SupplierAccount.Where(x => x.SupplierAccountID == userId).SingleOrDefault(); var supInfoData = db.SupplierInfo.Where(x => x.SupplierCode == supData.SupplierCode).SingleOrDefault(); SupInfoViewModel info = new SupInfoViewModel(); SupSettingViewModel sup = new SupSettingViewModel(); //姓名 userData.RealName = m.SupSettingViewModel.ContactName; supData.ContactName = m.SupSettingViewModel.ContactName; //信箱 string holder = userData.Email; userData.Email = m.SupSettingViewModel.Email; supData.Email = m.SupSettingViewModel.Email; //如果信箱有改,驗證要重置為false if (holder != m.SupSettingViewModel.Email) { userData.EmailConfirmed = false; } //手機 userData.PhoneNumber = m.SupSettingViewModel.Mobile; supData.Mobile = m.SupSettingViewModel.Mobile; //市話 supData.Tel = m.SupSettingViewModel.Tel; //雙因素 //判斷Email是否通過驗證 userData.TwoFactorEnabled = m.SupSettingViewModel.EnableTwoFactorAuth; var r = await UserManager.UpdateAsync(userData); db.Entry(supData).State = System.Data.Entity.EntityState.Modified; var r2 = await db.SaveChangesAsync(); if (r.Succeeded && r2 > 0) { TempData["SuccessMsg"] = "修改成功!"; return(RedirectToAction("Index")); } TempData["ErrorMsg"] = "修改失敗,請檢查網路連線再試一次。"; return(RedirectToAction("Index")); } catch { TempData["ErrorMsg"] = "修改失敗,不可空值,並請檢查網路連線再試一次..."; return(RedirectToAction("Index")); } }