Example #1
0
 protected void NotifyValidationErrors(Command command)
 {
     foreach (var erro in command.ValidationResult?.Errors)
     {
         mediator.RaiseEventAsync(new DomainNotification(command.MessageType, erro.ErrorMessage));
     }
 }
Example #2
0
        public Task <bool> Handle(InsertLoginCommand command, CancellationToken cancellationToken)
        {
            if (!command.IsValid())
            {
                NotifyValidationErrors(command);
                return(Task.FromResult(false));
            }

            var appuser = new AppUser(command.UserName, command.Email, command.FullName);
            var result  = userManager.CreateAsync(appuser, command.Password).Result;

            userManager.AddToRoleAsync(appuser, "User");
            if (result.Succeeded)
            {
                mediator.RaiseEventAsync(new InsertLoginEvent(command.Email, command.FullName));
            }
            else
            {
                foreach (var item in result.Errors)
                {
                    mediator.RaiseEventAsync(new DomainNotification(command.MessageType, item.Description));
                }
                return(Task.FromResult(false));
            }

            return(Task.FromResult(true));
        }
Example #3
0
        public virtual bool Commit()
        {
            if (Notifications.HasNotifications())
            {
                return(false);
            }

            if (UoW.Commit())
            {
                return(true);
            }

            Mediator.RaiseEventAsync(new DomainNotification(nameof(DomainNotification), "Commit failed.")).GetAwaiter().GetResult();
            return(false);
        }
Example #4
0
        public Task <bool> Handle(InsertGameCommand command, CancellationToken cancellationToken)
        {
            if (!command.IsValid())
            {
                NotifyValidationErrors(command);
                return(Task.FromResult(false));
            }

            var game = new Game(command.Name, command.Description);

            gameWriteRepository.Insert(game);

            if (Commit())
            {
                command.SetId(game.Id);
                mediator.RaiseEventAsync(new InsertGameEvent(game.Name, game.Description));
            }

            return(Task.FromResult(true));
        }
Example #5
0
        public Task <bool> Handle(InsertPersonCommand command, CancellationToken cancellationToken)
        {
            if (!command.IsValid())
            {
                NotifyValidationErrors(command);
                return(Task.FromResult(false));
            }

            var person = new Person(command.Name, command.Address, command.Age);

            personWriteRepository.Insert(person);

            if (Commit())
            {
                command.SetId(person.Id);
                mediator.RaiseEventAsync(new InsertPersonEvent(person.Id, person.Name, person.Address, person.Age));
            }

            return(Task.FromResult(true));
        }