예제 #1
0
        public async Task RegisterAsync(RegisterUserViewModel registerUser)
        {
            var command = new RegisterUserCommand()
            {
                Entity = _mapper.Map <User>(registerUser)
            };

            if (!command.IsValid())
            {
                await RaiseValidationErrorsAsync(command);

                return;
            }

            var users = await _userRepository.GetAllAsync();

            if (users.Any(u => u.Email == command.Entity.Email))
            {
                await _mediatorHandler.RaiseDomainNotificationAsync(new DomainNotification(command.MessageType, "Email is already in use."));

                return;
            }

            await _userRepository.AddAsync(command.Entity);
        }
예제 #2
0
        public override async Task AddAsync(FulanoModel model)
        {
            var command = new AddFulanoCommand()
            {
                Entity = _mapper.Map <Fulano>(model)
            };

            if (!command.IsValid())
            {
                await RaiseValidationErrorsAsync(command);

                return;
            }

            var listaFulano = await _fulanoRepository.GetAllAsync();

            if (listaFulano.Any(c => c.Id == command.Entity.Id))
            {
                await _mediatorHandler.RaiseDomainNotificationAsync(new DomainNotification(command.MessageType,
                                                                                           CoreUserMessages.RegistroExistente.Message));

                return;
            }

            if (listaFulano.Any(c => string.Equals(c.Nome, command.Entity.Nome, StringComparison.CurrentCultureIgnoreCase)))
            {
                await _mediatorHandler.RaiseDomainNotificationAsync(new DomainNotification(command.MessageType,
                                                                                           CoreUserMessages.ValorDuplicadoO.Format("Nome").Message));

                return;
            }

            await _mediatorHandler.SendCommandAsync(command);
        }
예제 #3
0
 protected async Task RaiseValidationErrorsAsync(Command command)
 {
     foreach (var error in command.ValidationResult.Errors)
     {
         await _mediatorHandler.RaiseDomainNotificationAsync(new DomainNotification(command.MessageType,
                                                                                    error.ErrorMessage));
     }
 }
예제 #4
0
        protected async Task <bool> Commit()
        {
            if (_notifications.HasNotifications())
            {
                await _mediatorHandler.RaiseDomainNotificationAsync(new DomainNotification("Commit",
                                                                                           CoreUserMessages.ErroPersistenciaDados.Message));

                return(false);
            }

            if (await _uow.CommitAsync())
            {
                return(true);
            }

            await _mediatorHandler.RaiseDomainNotificationAsync(new DomainNotification("Commit",
                                                                                       CoreUserMessages.ErroPersistenciaDados.Message));

            return(false);
        }
예제 #5
0
        public override async Task AddAsync(UserModel model)
        {
            var command = new AddUserCommand()
            {
                Entity = _mapper.Map <User>(model)
            };

            if (!command.IsValid())
            {
                await RaiseValidationErrorsAsync(command);

                return;
            }

            var listaUser = await _userRepository.GetAllAsync();

            if (listaUser.Any(c => c.Id == command.Entity.Id))
            {
                await _mediatorHandler.RaiseDomainNotificationAsync(new DomainNotification(command.MessageType,
                                                                                           CoreUserMessages.RegistroExistente.Message));

                return;
            }

            if (listaUser.Any(c => string.Equals(c.Username, command.Entity.Username, StringComparison.CurrentCultureIgnoreCase)))
            {
                await _mediatorHandler.RaiseDomainNotificationAsync(new DomainNotification(command.MessageType,
                                                                                           CoreUserMessages.ValorDuplicadoO.Format("Username").Message));

                return;
            }

            command.Entity.Password = PasswordHashService.Hash(command.Entity.Password);

            await _mediatorHandler.SendCommandAsync(command);
        }
예제 #6
0
 protected async void NotifyError(string key, string mensagem)
 {
     await _mediatorHandler.RaiseDomainNotificationAsync(new DomainNotification(key, mensagem));
 }