Пример #1
0
        public AddUserResponse AddUser(AddUserRequest request)
        {
            AddUserResponse response = new AddUserResponse();

            try
            {
                if (request.SecurityString == ConfigurationManager.AppSettings[Constants.APP_SETTING_SECURITY_TOKEN])
                {
                    LacesDataModel.User.User user = new LacesDataModel.User.User();

                    user.Description = request.Description;
                    user.DisplayName = request.DisplayName;
                    user.Email       = request.Email;
                    user.Password    = request.Password;
                    user.UserName    = request.UserName;

                    bool userNameValid = true;
                    bool emailValid    = true;

                    if (user.UserNameInUse())
                    {
                        userNameValid = false;
                    }

                    if (user.EmailInUse())
                    {
                        emailValid = false;
                    }

                    if (userNameValid && emailValid)
                    {
                        if (user.Add())
                        {
                            response.Success = true;
                            response.Message = "User succesfully created with Id: " + user.UserId;
                        }
                        else
                        {
                            response.Success = false;
                            response.Message = "An error occurred while processing your request.";
                        }
                    }
                    else
                    {
                        response.Success = false;
                        response.Message = "Username or email address is already in use.";

                        if (userNameValid == false)
                        {
                            response.UserNameTaken = true;
                        }

                        if (emailValid == false)
                        {
                            response.EmailTaken = true;
                        }
                    }
                }
                else
                {
                    response.Success = false;
                    response.Message = "Invalid security token.";
                }
            }
            catch
            {
                response         = new AddUserResponse();
                response.Success = false;
                response.Message = "An unexpected error has occurred; please verify the format of your request.";
            }

            return(response);
        }