示例#1
0
        public IHttpActionResult UpdateUserInfo(UpdateUserInfoVM updateUserInfoVM)
        {
            var userInfo = _userInfo.GetById(updateUserInfoVM.UserInfoId);

            if (userInfo != null)
            {
                userInfo.NikeName = updateUserInfoVM.NikeName;
                //userInfo.GradeId = updateUserInfoVM.GradeId;
                userInfo.Gender = updateUserInfoVM.Gender;
                userInfo.UTime  = DateTime.Now;
                _userInfo.Update(userInfo);
                return(Json(new { Success = true, Msg = "用户信息修改成功", Data = userInfo }));
            }
            else
            {
                return(Json(new { Success = false, Msg = "用户不存在", Data = "" }));
            }
        }
示例#2
0
        public IActionResult UpdateUserInfo(UpdateUserInfoVM model)
        {
            if (ModelState.IsValid)
            {
                SystemUser.Birthdate = model.Birthdate;
                SystemUser.Email     = model.Email;
                SystemUser.FirstName = model.FirstName;
                SystemUser.LastName  = model.LastName;
                SystemUser.Phone     = model.Phone;

                var updatePassword = !string.IsNullOrWhiteSpace(model.NewPassword) &&
                                     (!string.IsNullOrWhiteSpace(model.ConfirmPassword) ||
                                      !string.IsNullOrWhiteSpace(model.CurrentPassword));

                if (updatePassword &&
                    SystemUser.Password != UnitOfWork.StoredProcedures.MD5HashPassword(model.CurrentPassword))
                {
                    return(Index("Неверно указан текущий пароль!"));
                }
                else if (updatePassword && model.NewPassword != model.ConfirmPassword)
                {
                    return(Index("Новый пароль не совпадает с повторным!"));
                }
                else if (updatePassword &&
                         SystemUser.Password == UnitOfWork.StoredProcedures.MD5HashPassword(model.CurrentPassword) &&
                         model.NewPassword == model.ConfirmPassword)
                {
                    UnitOfWork.Users.UpdateUserPassword(SystemUser.Id, model.NewPassword);
                }

                UnitOfWork.Users.Update(SystemUser);
                Login(SystemUser.Token.ToString());

                return(Index(updatedUserInfo: true));
            }
            else
            {
                var htmlError = ModelState.GetHtmlErrors();
                return(Index(htmlError));
            }
        }
        public IActionResult UpdateUserInfo(UpdateUserInfoVM model)
        {
            if (ModelState.IsValid)
            {
                SystemUser.Birthdate = model.Birthdate;
                SystemUser.Email     = model.Email;
                SystemUser.FirstName = model.FirstName;
                SystemUser.LastName  = model.LastName;
                SystemUser.Phone     = model.Phone;

                var updatePassword = !string.IsNullOrWhiteSpace(model.NewPassword) &&
                                     (!string.IsNullOrWhiteSpace(model.ConfirmPassword) ||
                                      !string.IsNullOrWhiteSpace(model.CurrentPassword));

                if (updatePassword &&
                    SystemUser.Password != UnitOfWork.StoredProcedures.MD5HashPassword(model.CurrentPassword))
                {
                    return(Index("The current password is incorrect!"));
                }
                else if (updatePassword && model.NewPassword != model.ConfirmPassword)
                {
                    return(Index("The new password does not match the new one!"));
                }
                else if (updatePassword &&
                         SystemUser.Password == UnitOfWork.StoredProcedures.MD5HashPassword(model.CurrentPassword) &&
                         model.NewPassword == model.ConfirmPassword)
                {
                    UnitOfWork.Users.UpdateUserPassword(SystemUser.Id, model.NewPassword);
                }

                UnitOfWork.Users.Update(SystemUser);
                Login(SystemUser.Token.ToString());

                return(Index(updatedUserInfo: true));
            }
            else
            {
                var htmlError = ModelState.GetHtmlErrors();
                return(Index(htmlError));
            }
        }