コード例 #1
0
        public IHttpActionResult GetMesOrcamento(int id)
        {
            MesOrcamento mesOrcamento = db.MesOrcamento.Find(id);

            if (mesOrcamento == null)
            {
                return(NotFound());
            }

            return(Ok(new MesOrcamentoDTO(mesOrcamento)));
        }
コード例 #2
0
        public IHttpActionResult PostMesOrcamento(MesOrcamento mesOrcamento)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            db.MesOrcamento.Add(mesOrcamento);
            db.SaveChanges();

            return(CreatedAtRoute("DefaultApi", new { id = mesOrcamento.Codigo }, new MesOrcamentoDTO(mesOrcamento)));
        }
コード例 #3
0
        public IHttpActionResult SaveAllPorCiclo(int codCiclo, IEnumerable <FeriasPorCR> ferias)
        {
            Ciclo ciclo = db.Ciclo.Find(codCiclo);

            if (ciclo == null)
            {
                return(NotFound());
            }
            float soma = 0;

            foreach (FeriasPorCR f in ferias)
            {
                MesOrcamento mes = db.MesOrcamento.Find(f.CodMesOrcamento);
                if (mes == null)
                {
                    return(NotFound());
                }
                else if (mes.CicloCod != codCiclo)
                {
                    return(BadRequest("Mês fora do ciclo informado!"));
                }

                if (f.Percentual == 0)
                {
                    if (FeriasPorCRExists(f.CodigoCR, f.CodMesOrcamento))
                    {
                        db.Entry(f).State = EntityState.Deleted;
                    }
                }
                else
                {
                    db.FeriasPorCR.AddOrUpdate(f);
                    soma += f.Percentual;
                }
            }

            if (soma != 1 && soma != 0)
            {
                return(BadRequest("A soma dos percentuais não correspondem a 100% (" + soma + ")!"));
            }

            try
            {
                db.SaveChanges();
            } catch (Exception e)
            {
                return(InternalServerError(e));
            }

            return(Ok());
        }
コード例 #4
0
        public IHttpActionResult DeleteMesOrcamento(int id)
        {
            MesOrcamento mesOrcamento = db.MesOrcamento.Find(id);

            if (mesOrcamento == null)
            {
                return(NotFound());
            }

            MesOrcamentoDTO m = new MesOrcamentoDTO(mesOrcamento);

            db.MesOrcamento.Remove(mesOrcamento);
            db.SaveChanges();

            return(Ok(m));
        }