private Planejamento ObterModel(PlanejamentoView planejamentoView)
        {
            if (planejamentoView.EtiquetaId <= 0 || planejamentoView.EtiquetaId.Equals(int.MinValue))
            {
                throw new ArgumentException("O campo 'EtiquetaId' é obrigatório.");
            }

            Etiqueta etiqueta = repoEtiqueta.ObterPorId(planejamentoView.EtiquetaId);

            if (etiqueta == null)
            {
                throw new Exception($"A EtiquetaId '{planejamentoView.EtiquetaId}' não existe no banco de dados.");
            }

            return(new Planejamento
            {
                Id = planejamentoView.Id,
                Meta = planejamentoView.Meta,
                DataInicial = planejamentoView.DataInicial,
                DataFinal = planejamentoView.DataFinal,
                Tipo = planejamentoView.Tipo.StringParaTipoPlanejamento(),
                EtiquetaId = planejamentoView.EtiquetaId,
                Etiqueta = etiqueta,
                Valor = planejamentoView.Valor,
            });
        }
Beispiel #2
0
        public IActionResult PutPlanejamento([FromBody] PlanejamentoView value)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(BadRequest());
                }
                else
                {
                    var planejamento = business.ObterPorId(value.Id);
                    if (planejamento == null)
                    {
                        return(NotFound(new { Mensagem = $"A meta/planejamento id: {value.Id} informada não existe no banco de dados." }));
                    }

                    business.Alterar(value);
                    return(Ok());
                }
            }
            catch (Exception ex)
            {
                return(StatusCode(500, new { Mensagem = ex.Message.ToString() }));
            }
        }
        public PlanejamentoView Incluir(PlanejamentoView planejamentoView)
        {
            Planejamento planejamento = ObterModel(planejamentoView);

            repository.Incluir(planejamento);

            return(planejamento.ToView());
        }
        public void Excluir(PlanejamentoView planejamentoView)
        {
            Planejamento planejamento = repository.ObterPorId(planejamentoView.Id);

            if (planejamento != null)
            {
                repository.Excluir(planejamento);
            }
        }
        public void Alterar(PlanejamentoView planejamentoView)
        {
            if (planejamentoView.Id <= 0 || planejamentoView.Id.Equals(int.MinValue))
            {
                throw new ArgumentException("O código do planejamento é obrigatório.");
            }

            repository.DetachLocal(e => e.Id == planejamentoView.Id);
            repository.Alterar(ObterModel(planejamentoView));
        }
Beispiel #6
0
        public IActionResult PostPlanejamento([FromBody] PlanejamentoView value)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(BadRequest());
                }
                else
                {
                    PlanejamentoView planejamento = business.Incluir(value);

                    var uri = Url.Action("GetPlanejamentoPorId", new { id = planejamento.Id });
                    return(Created(uri, planejamento));
                }
            }
            catch (Exception ex)
            {
                return(StatusCode(500, new { Mensagem = ex.Message.ToString() }));
            }
        }