예제 #1
0
 public ActionResult SaveUser(UserInfo userInfo)
 {
     var result = ServiceProxySingleton.Instance.SaveUserInfo(userInfo);
     if (result.IsError()) return Json(result);
     if (result.CurrentUserPermissions != null)
         SessionHelper.Permissions = result.CurrentUserPermissions;
     SessionHelper.ClearUserRolesFromSession();
     return new EmptyResult();
 }
예제 #2
0
        public ChangePermissionsResult SaveUserInfo(UserInfo userInfo)
        {
            var user = Db.GetUserByLogin(userInfo.Login);
            if (user == null)
                return new ChangePermissionsResult { ErrorMessage = Messages.UserNotFoundByLogin };
            if (userInfo.UserRoles == null || !userInfo.UserRoles.Any())
                return new ChangePermissionsResult { ErrorMessage = Messages.UserRolesNotFound };

            var emailChanged = user.Email != userInfo.Email;
            var userInfoChanged = user.UserFio != userInfo.UserFio || emailChanged;
            if (emailChanged && Db.EmailIsNotUnique(userInfo.Email, user.UserId))
                return new ChangePermissionsResult { ErrorMessage = Messages.EmailAlreadyUsed };

            using (var transaction = new TransactionScope())
            {
                if (userInfoChanged)
                {
                    user.UserFio = userInfo.UserFio;
                    user.Email = userInfo.Email;
                    Db.Save(user);
                }

                bool isPermissionChanged = false;
                var userRoleIds = Db.GetUserRoleIds(user.UserId);
                foreach (var userRole in userInfo.UserRoles)
                {
                    var userRoleId = userRoleIds != null && userRoleIds.ContainsKey(userRole.RoleId) ? userRoleIds[userRole.RoleId] : 0;
                    if (userRoleId == 0 && userRole.IsUsed)
                    {
                        Db.AddUserRole(userRole.RoleId, user.UserId);
                        if (!isPermissionChanged) isPermissionChanged = true;
                    }
                    else if (userRoleId != 0 && !userRole.IsUsed)
                    {
                        Db.Delete<UserRole>(userRoleId, string.Empty);
                        if (!isPermissionChanged) isPermissionChanged = true;
                    }

                }

                transaction.Complete();
                return new ChangePermissionsResult
                {
                    IsPermissionsChanged = isPermissionChanged,
                    EntityId = user.UserId
                };

            }
        }
 public ChangePermissionsResult SaveUserInfo(UserInfo userInfo)
 {
     return SendPostRequest<ChangePermissionsResult, UserInfo>("saveUserInfo", userInfo);
 }