Esempio n. 1
0
        public async Task <ActionResult> Edit(EmpEditModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }
            else
            {
                //var user = UserManager.FindById(User.Identity.GetUserId());
                EmpService empService = new EmpService();
                EMPLOYEE   emp        = empService.FindOne(model.empno);

                var user = await UserManager.FindByNameAsync(emp.empaccount);

                user.Email       = model.EMPEMAIL;
                user.PhoneNumber = model.emptel;
                if (!string.IsNullOrWhiteSpace(model.Newpwd))
                {
                    user.PasswordHash = UserManager.PasswordHasher.HashPassword(model.Newpwd);
                    model.emppwd      = user.PasswordHash;
                }
                using (var scope = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled))
                {
                    try
                    {
                        var result = await UserManager.UpdateAsync(user);

                        if (result.Succeeded)
                        {
                            empService.Update(model);

                            scope.Complete();
                            return(RedirectToAction("Index", "Home", new { area = "Admin" }));
                        }
                    }
                    catch (DbEntityValidationException ex)
                    {
                        logger.Error(GetEntityErrorMsg(ex));
                    }
                    catch (Exception ex)
                    {
                        logger.Error(ex.Message);
                        scope.Dispose();
                    }
                }
            }
            return(View(model));
        }
        public void TestUpdate()
        {
            Employee emp = new Employee
            {
                Emp_Id = 1001,
                Name = "Stone",
                Gender = "Male",
                Email = "*****@*****.**",
                Phone_Number = "138",
                City = "WUHAN"
            };

            var empService = new EmpService();
            int rv = empService.Update(emp);
            Assert.AreEqual(rv, 1);
        }