Esempio n. 1
0
        public IComandResult AdicionarDepartamento([FromBody] AdicionarDepartamentoCommands command)
        {
            var result = (ComandResult)_escolaHandler.Handle(command);

            this.Commit(result.Success);
            return(result);
        }
Esempio n. 2
0
        public IComandResult Handle(AdicionarDepartamentoCommands comand)
        {
            //verificar se tem notificação no comand
            if (!comand.IsValid())
            {
                return(new ComandResult(false, "Por favor corrija os campos abaixo", comand.Notifications));
            }

            var escola = _repository.Existe(comand.EscolaId);

            if (escola != null)
            {
                foreach (var i in comand.DepartamentoId)
                {
                    var existe = _itemRepositorio.Existe(escola.Id, i.DepartamentoId);

                    if (existe == null)
                    {
                        var item = new ItemDepartamentoEscola(escola.Id, i.DepartamentoId);
                        _itemRepositorio.Salvar(item);
                    }
                }
            }
            else
            {
                return(new ComandResult(false, "Escola não encontrada,tente novamente!!", new { }));
            }

            return(new ComandResult(true, "Departamento adicionado com sucesso!!", new { }));
        }