コード例 #1
0
        public IHttpActionResult PostValoresAbertosCR(ValoresAbertosCR valoresAbertosCR)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            db.ValoresAbertosCR.Add(valoresAbertosCR);

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateException)
            {
                if (ValoresAbertosCRExists(valoresAbertosCR.CodEvento, valoresAbertosCR.CodMesOrcamento, valoresAbertosCR.CodigoCR))
                {
                    return(Conflict());
                }
                else
                {
                    throw;
                }
            }

            return(CreatedAtRoute("DefaultApi", new { id = valoresAbertosCR.CodEvento }, new ValoresAbertosCRDTO(valoresAbertosCR)));
        }
コード例 #2
0
        public ValoresAbertosCRCicloDTO(CentroCusto cr, EventoFolha ev, Ciclo ciclo)
        {
            CodEvento  = ev.Codigo;
            NomeEvento = ev.NomeEvento;

            Valores = new HashSet <ValoresAbertosCRDTO>();
            Contexto db = new Contexto();

            if (cr == null || ev == null || ciclo == null)
            {
                return;
            }

            foreach (MesOrcamento m in ciclo.MesesOrcamento.OrderBy(x => x.Mes))
            {
                ValoresAbertosCR v = db.ValoresAbertosCR.Find(ev.Codigo, m.Codigo, cr.Codigo);

                if (v == null)
                {
                    ((HashSet <ValoresAbertosCRDTO>)Valores).Add(new ValoresAbertosCRDTO
                    {
                        CodEvento       = ev.Codigo,
                        CodMesOrcamento = m.Codigo,
                        CodigoCR        = cr.Codigo,
                        Valor           = 0,
                        Mes             = m.Mes
                    });
                }
                else
                {
                    ((HashSet <ValoresAbertosCRDTO>)Valores).Add(new ValoresAbertosCRDTO(v));
                }
            }
        }
コード例 #3
0
 public ValoresAbertosCRDTO(ValoresAbertosCR v)
 {
     if (v == null)
     {
         return;
     }
     CodEvento       = v.CodEvento;
     CodMesOrcamento = v.CodMesOrcamento;
     CodigoCR        = v.CodigoCR;
     Valor           = v.Valor;
 }
コード例 #4
0
        public IHttpActionResult DeleteValoresAbertosCR(string codEvento, int codMes, string cr)
        {
            ValoresAbertosCR valoresAbertosCR = db.ValoresAbertosCR.Find(codEvento, codMes, cr);

            if (valoresAbertosCR == null)
            {
                return(NotFound());
            }
            ValoresAbertosCRDTO v = new ValoresAbertosCRDTO(valoresAbertosCR);

            db.ValoresAbertosCR.Remove(valoresAbertosCR);
            db.SaveChanges();

            return(Ok(v));
        }
コード例 #5
0
        // GET: api/ValoresAbertosCRs
        public IEnumerable <ValoresAbertosCRDTO> GetValoresAbertosCR(string cr = null, string codEvento = null, int?codCiclo = null)
        {
            if (cr != null && codEvento != null && codCiclo != null)
            {
                IEnumerable <ValoresAbertosCRDTO> lista = new HashSet <ValoresAbertosCRDTO>();
                Ciclo ciclo = db.Ciclo.Find(codCiclo);
                if (ciclo == null)
                {
                    return(null);
                }

                foreach (MesOrcamento m in ciclo.MesesOrcamento)
                {
                    ValoresAbertosCR v = db.ValoresAbertosCR.Find(codEvento, m.Codigo, cr);

                    if (v == null)
                    {
                        ((HashSet <ValoresAbertosCRDTO>)lista).Add(new ValoresAbertosCRDTO
                        {
                            CodEvento       = codEvento,
                            CodMesOrcamento = m.Codigo,
                            CodigoCR        = cr,
                            Valor           = 0
                        });
                    }
                    else
                    {
                        ((HashSet <ValoresAbertosCRDTO>)lista).Add(new ValoresAbertosCRDTO(v));
                    }
                }

                return(lista);
            }
            return(db.ValoresAbertosCR.ToList()
                   .Where(x => (cr == null || x.CodigoCR == cr) && (codCiclo == null || x.MesOrcamento.CicloCod == codCiclo) && (codEvento == null || x.CodEvento == codEvento))
                   .Select(x => new ValoresAbertosCRDTO(x)));
        }
コード例 #6
0
        public IHttpActionResult PutValoresAbertosCR(string codEvento, int codMes, string cr, ValoresAbertosCR valoresAbertosCR)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (codEvento != valoresAbertosCR.CodEvento || codMes != valoresAbertosCR.CodMesOrcamento || cr != valoresAbertosCR.CodigoCR)
            {
                return(BadRequest());
            }

            db.Entry(valoresAbertosCR).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!ValoresAbertosCRExists(codEvento, codMes, cr))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }