public Task <bool> Handle(IncluirAlunoNoGrupoCommand message, CancellationToken cancellationToken)
        {
            if (!message.IsValid())
            {
                NotifyValidationErrors(message);
                return(Task.FromResult(false));
            }

            var alunoGrupo = new AlunoGrupo(Guid.NewGuid(), message.IdGrupo, message.IdAluno);

            if (_alunoGrupoRepository.GetByGrupo(alunoGrupo.IdAluno, alunoGrupo.IdGrupo) != null)
            {
                Bus.RaiseEvent(new DomainNotification(message.MessageType, "Já existe um aluno com esse Email neste grupo."));
                return(Task.FromResult(false));
            }

            _alunoGrupoRepository.Add(alunoGrupo);

            if (Commit())
            {
                Bus.RaiseEvent(new AlunoIncluidoNoGrupoEvent(alunoGrupo.Id, alunoGrupo.IdGrupo, alunoGrupo.IdAluno));
            }

            return(Task.FromResult(true));
        }
Example #2
0
        public bool SaveAlunoGrupo(AlunoGrupoDto dto)
        {
            var entity = new AlunoGrupo()
            {
                IdAluno    = dto.IdAluno == 0 ? null : dto.IdAluno,
                IdGrupo    = dto.IdGrupo,
                IdUsuario  = SessionUser.IdUsuario,
                Temporario = true
            };

            Contexto.AlunoGrupo.Add(entity);
            Contexto.SaveChanges();
            return(true);
        }