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"));
            }
        }
Пример #2
0
        //4.存到資料庫
        //更新此 user table
        //await updateEmpUserTable(user, emp);
        private async Task updateEmpUserTable(ApplicationUser user, Employee emp)
        {
            //4.存到資料庫
            //更新此 user table
            var store = new UserStore <ApplicationUser>(new ApplicationDbContext());
            await UserManager.UpdateAsync(user);

            var ctx = store.Context;
            await ctx.SaveChangesAsync();

            //Emp table
            db.Entry(emp).State = EntityState.Modified;
            await db.SaveChangesAsync();
        }
Пример #3
0
        //4.存到資料庫
        //更新此 user table
        private async Task updateTable(ApplicationUser user, SupplierAccount sa)
        {
            //更新此 user table
            await UserManager.UpdateAsync(user);

            //sa table
            db.Entry(sa).State = EntityState.Modified;
            int u2 = await db.SaveChangesAsync();
        }