示例#1
0
        /// <summary>
        /// Method to create one user
        /// </summary>
        ///
        /// <param name="thisUser">
        /// User performing operation
        /// </param>
        ///
        /// <param name="operatedUser">
        /// User to create
        /// </param>
        ///
        /// <returns>
        /// True to indicate success or error if failed
        /// </returns>
        public User SingleCreateUsers(User invokingUser, User operatedUser)
        {
            // Check permissions for user performing operation
            bool permissionResult = _userManagementService.CheckPermission(invokingUser, operatedUser, "Create");

            if (permissionResult)
            {
                StringCheckerService emailChecker     = new StringCheckerService(operatedUser.Email);
                StringCheckerService firstNameChecker = new StringCheckerService(operatedUser.FirstName);
                StringCheckerService lastNameChecker  = new StringCheckerService(operatedUser.LastName);
                if (!firstNameChecker.isValidName() || !lastNameChecker.isValidName())
                {
                    operatedUser.ErrorMessage = "Invalid names";
                }
                else if (emailChecker.isValidEmail())
                {
                    if (_DataAccessService.GetUserByEmail(operatedUser.Email) != null)
                    {
                        operatedUser.ErrorMessage = "Email already registered";
                    }
                    else
                    {
                        _DataAccessService.CreateUser(operatedUser, true);
                        if ((_DataAccessService.GetUserByEmail(operatedUser.Email) == null) &&
                            (operatedUser.ErrorMessage == null))
                        {
                            operatedUser.ErrorMessage = "Email failed to register";
                        }
                    }
                }
                else
                {
                    operatedUser.ErrorMessage = "Email malformed";
                }
            }
            else
            {
                operatedUser.ErrorMessage = "Invalid permissions";
            }
            if (!operatedUser.ErrorMessage.Equals(""))
            {
                _loggingManager.Log("User Creation", operatedUser.ErrorMessage);
            }
            else
            {
                _loggingManager.Log("User Creation", "");
            }
            return(operatedUser);
        }