Exemplo n.º 1
0
        /// <summary>
        /// Create new UserRule
        /// </summary>
        /// <param name="request">userRule request.</param>
        /// <returns>UserRule message.</returns>
        public UserRuleMessage CreateUserRule(UserRuleRequest request)
        {
            UserRuleMessage message = new UserRuleMessage();

            try
            {
                message = _serviceUserRule.CreateUserRule(request.ToPivot()).ToMessage();
                message.OperationSuccess = true;
            }
            catch (Exception e)
            {
                message.ErrorType    = ErrorType.TechnicalError;
                message.ErrorMessage = e.Message;
            }
            return(message);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Create new Rule.
        /// </summary>
        /// <param name="request">rule request.</param>
        /// <returns>Rule message.</returns>
        public RuleMessage CreateRule(RuleRequest request)
        {
            RuleMessage message = new RuleMessage();

            try
            {
                message = _serviceRule.CreateRule(request.ToPivot()).ToMessage();
                if (message?.RuleDto != null)
                {
                    //create user rule.
                    UserMessage userMessage = _serviceUser.GetAllUsers().ToMessage();
                    if (userMessage?.UserDtoList != null)
                    {
                        foreach (var user in userMessage.UserDtoList)
                        {
                            _serviceUserRule.CreateUserRule(new UserRuleRequestPivot()
                            {
                                UserRulePivot = new UserRulePivot()
                                {
                                    RuleId         = message.RuleDto.RuleId,
                                    UserRuleStatus = false,
                                    UserId         = user.UserId
                                }
                            });
                        }
                    }
                    message.OperationSuccess = true;
                }
                else
                {
                    if (message != null)
                    {
                        message.ErrorMessage     = RuleMessageResource.ServiceResponseNull;
                        message.ErrorType        = ErrorType.TechnicalError;
                        message.OperationSuccess = false;
                    }
                }
            }
            catch (Exception e)
            {
                message.ErrorType    = ErrorType.TechnicalError;
                message.ErrorMessage = e.Message;
            }
            return(message);
        }
Exemplo n.º 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);
        }