Beispiel #1
0
        /// <summary>
        /// Delete User
        /// </summary>
        /// <param name="request">user request.</param>
        /// <returns>User message.</returns>
        public UserMessage DeleteUser(UserRequest request)
        {
            UserMessage message = new UserMessage();

            try
            {
                request.FindUserDto = FindUserDto.UserId;
                UserResponsePivot response = _serviceUser.FindUsers(request.ToPivot());
                if (response?.UserPivot != null)
                {
                    _serviceUser.DeleteUser(request.ToPivot());
                    message.OperationSuccess = true;
                }
                else
                {
                    message.ErrorMessage     = UserMessageResource.NotFound;
                    message.OperationSuccess = false;
                }
            }
            catch (Exception e)
            {
                message.ErrorType    = ErrorType.TechnicalError;
                message.ErrorMessage = e.Message;
            }
            return(message);
        }
Beispiel #2
0
 /// <summary>
 /// From User Response pivot to User Message.
 /// </summary>
 /// <param name="userResponsePivot">user Response pivot to assemble.</param>
 /// <returns>User Message result.</returns>
 public static UserMessage ToMessage(this UserResponsePivot userResponsePivot)
 {
     return(new UserMessage
     {
         UserDtoList = userResponsePivot?.UserPivotList.ToDtoList(),
         UserDto = userResponsePivot?.UserPivot.ToDto()
     });
 }
Beispiel #3
0
        /// <summary>
        /// Create new User
        /// </summary>
        /// <param name="request">user request.</param>
        /// <returns>User message.</returns>
        public UserMessage CreateUser(UserRequest request)
        {
            UserMessage message = new UserMessage();

            try
            {
                //search user by adress mail.
                request.FindUserDto = FindUserDto.UserMail;
                UserResponsePivot response = _serviceUser.FindUsers(request.ToPivot());

                if (response?.UserPivot == null)
                {
                    //generate and set password:
                    string password = ManagePassword.GeneratePassword(5);
                    request.UserDto.UserPassword = password;
                    message = _serviceUser.CreateUser(request.ToPivot()).ToMessage();

                    //add user rule.
                    RuleMessage ruleMessage = _serviceRule.GetAllRules().ToMessage();
                    if (ruleMessage?.RuleDtoList != null)
                    {
                        foreach (var rule in ruleMessage.RuleDtoList.ToList())
                        {
                            UserRuleRequest userRuleRequest = new UserRuleRequest
                            {
                                UserRuleDto = new UserRuleDto
                                {
                                    UserId         = message.UserDto.UserId,
                                    UserRuleStatus = false,
                                    RuleId         = rule.RuleId
                                }
                            };
                            _serviceUserRule.CreateUserRule(userRuleRequest.ToPivot()).ToMessage();
                        }
                    }
                    else
                    {
                        message.Errors = new List <string> {
                            UserRuleMessageResource.UserRuleNotAdded
                        };
                        message.ErrorMessage     = UserRuleMessageResource.UserRuleNotAdded;
                        message.ErrorType        = ErrorType.FunctionalError;
                        message.OperationSuccess = false;
                    }
                    message.OperationSuccess = true;
                }
                else
                {
                    message.Errors = new List <string> {
                        UserMessageResource.AlreadyExist
                    };
                    message.ErrorMessage     = UserMessageResource.AlreadyExist;
                    message.ErrorType        = ErrorType.FunctionalError;
                    message.OperationSuccess = false;
                }
            }
            catch (Exception e)
            {
                message.ErrorType    = ErrorType.TechnicalError;
                message.ErrorMessage = e.Message;
            }
            return(message);
        }