Exemplo n.º 1
0
        public IHttpActionResult PostValoresAbertosBase(ValoresAbertosBase valoresAbertosBase)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            db.ValoresAbertosBase.Add(valoresAbertosBase);

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateException)
            {
                if (ValoresAbertosBaseExists(valoresAbertosBase.CodEvento, valoresAbertosBase.CodMesOrcamento, valoresAbertosBase.MatriculaFuncionario))
                {
                    return(Conflict());
                }
                else
                {
                    throw;
                }
            }

            return(CreatedAtRoute("DefaultApi", new { id = valoresAbertosBase.CodEvento }, new ValoresAbertosBaseDTO(valoresAbertosBase)));
        }
 public ValoresAbertosBaseDTO(ValoresAbertosBase v)
 {
     if (v == null)
     {
         return;
     }
     CodEvento            = v.CodEvento;
     CodMesOrcamento      = v.CodMesOrcamento;
     MatriculaFuncionario = v.MatriculaFuncionario;
     Valor = v.Valor;
 }
Exemplo n.º 3
0
        public IHttpActionResult DeleteValoresAbertosBase(string codEvento, int mes, string matricula)
        {
            ValoresAbertosBase valoresAbertosBase = db.ValoresAbertosBase.Find(codEvento, mes, matricula);

            if (valoresAbertosBase == null)
            {
                return(NotFound());
            }
            ValoresAbertosBaseDTO v = new ValoresAbertosBaseDTO(valoresAbertosBase);

            db.ValoresAbertosBase.Remove(valoresAbertosBase);
            db.SaveChanges();

            return(Ok(v));
        }
Exemplo n.º 4
0
        // GET: api/ValoresAbertosBase
        public IEnumerable <ValoresAbertosBaseDTO> GetValoresAbertosBase(string codEvento = null, string matricula = null, int?codCiclo = null)
        {
            if (matricula != null && codCiclo != null)
            {
                IEnumerable <ValoresAbertosBaseDTO> lista = new HashSet <ValoresAbertosBaseDTO>();
                Ciclo ciclo = db.Ciclo.Find(codCiclo);
                if (ciclo == null)
                {
                    return(null);
                }

                db.ValoresAbertosBase
                .Where(x => x.MatriculaFuncionario == matricula && x.MesOrcamento.CicloCod == codCiclo)
                .Select(x => x.CodEvento).Distinct().ToList().ForEach(x =>
                {
                    foreach (MesOrcamento m in ciclo.MesesOrcamento)
                    {
                        ValoresAbertosBase v = db.ValoresAbertosBase.Find(x, m.Codigo, matricula);

                        if (v == null)
                        {
                            ((HashSet <ValoresAbertosBaseDTO>)lista).Add(new ValoresAbertosBaseDTO
                            {
                                CodEvento            = x,
                                CodMesOrcamento      = m.Codigo,
                                MatriculaFuncionario = matricula,
                                Valor = 0
                            });
                        }
                        else
                        {
                            ((HashSet <ValoresAbertosBaseDTO>)lista).Add(new ValoresAbertosBaseDTO(v));
                        }
                    }
                });

                return(lista);
            }
            return(db.ValoresAbertosBase.ToList()
                   .Where(x => (codEvento == null || x.CodEvento == codEvento) && (matricula == null || x.MatriculaFuncionario == matricula) && (codCiclo == null || x.MesOrcamento.CicloCod == codCiclo))
                   .Select(x => new ValoresAbertosBaseDTO(x)));
        }
Exemplo n.º 5
0
        public IHttpActionResult PutValoresAbertosBase(string codEvento, int mes, string matricula, ValoresAbertosBase valoresAbertosBase)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (codEvento != valoresAbertosBase.CodEvento || mes != valoresAbertosBase.CodMesOrcamento || matricula != valoresAbertosBase.MatriculaFuncionario)
            {
                return(BadRequest());
            }

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

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!ValoresAbertosBaseExists(codEvento, mes, matricula))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }