Esempio n. 1
0
        public User InsertOrUpdateUser(User user)
        {
            if (user == null)
            {
                throw new NullReferenceException("User is null!");
            }

            bool IsNewUser = user.UserId == 0;

            if (!IsNewUser)
            {
                if (!string.IsNullOrEmpty(user.Password))
                {
                    Users.UpdatePassword(user);
                }
            }
            else
            {
                if (string.IsNullOrEmpty(user.Password))
                {
                    throw new ArgumentException("Password is not set!");
                }
            }

            if (user.UserId == 0)
            {
                user.UserId = Users.Insert(user);
            }
            else
            {
                Users.Update(user);
            }

            if (IsNewUser)
            {
                foreach (UserRightUserMapping item in user.UserRightUserMappings)
                {
                    item.RefUserId = user.UserId;
                }
            }

            foreach (UserRightUserMapping userRightMapping in user.UserRightUserMappings)
            {
                if (userRightMapping.UserRightUserMappingId == 0)
                {
                    UserRightUserMappings.Insert(userRightMapping);
                }
                else
                {
                    UserRightUserMappings.Update(userRightMapping);
                }
            }

            RefreshUsers();

            return(user);
        }
Esempio n. 2
0
        public void RevokePermission(User user, Permission permission)
        {
            UserRight            right = Instance.UserRightList.Single(x => x.Permission == permission);
            UserRightUserMapping tempUserRightUserMapping =
                user.UserRightUserMappings.SingleOrDefault(x => x.RefUserRightId == right.UserRightId);

            if (tempUserRightUserMapping != null)
            {
                tempUserRightUserMapping.IsGranted = false;
                if (tempUserRightUserMapping.UserRightUserMappingId == 0)
                {
                    UserRightUserMappings.Insert(tempUserRightUserMapping);
                }
                else
                {
                    UserRightUserMappings.Update(tempUserRightUserMapping);
                }
            }
            else
            {
                UserRightUserMappings.Insert(
                    new UserRightUserMapping(user.UserId, right.UserRightId, false, 0));
            }
        }