コード例 #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
ファイル: FulanoAppService.cs プロジェクト: abreu-dev/haze
        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
ファイル: MainController.cs プロジェクト: abreu-dev/mist
 protected async void NotifyError(string key, string mensagem)
 {
     await _mediatorHandler.RaiseDomainNotificationAsync(new DomainNotification(key, mensagem));
 }