Beispiel #1
0
        public async Task <IHttpActionResult> GetCobertura(int id)
        {
            Cobertura c = await db.Coberturas.FindAsync(id);

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

            DTO_Cobertura cobertura = new DTO_Cobertura()
            {
                Id            = c.Id,
                Descripcion   = c.Descripcion,
                FechaCreacion = c.FechaCreacion
            };

            return(Ok(cobertura));
        }
Beispiel #2
0
        public async Task <IHttpActionResult> PostCobertura(DTO_Cobertura cobertura)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            Cobertura nuevaCobertura = new Cobertura()
            {
                Descripcion   = cobertura.Descripcion,
                FechaCreacion = DateTime.Now
            };

            db.Coberturas.Add(nuevaCobertura);
            await db.SaveChangesAsync();

            cobertura.Id = nuevaCobertura.Id;

            return(CreatedAtRoute("DefaultApi", new { id = cobertura.Id }, cobertura));
        }
Beispiel #3
0
        public async Task <IHttpActionResult> DeleteCobertura(int id)
        {
            Cobertura cobertura = await db.Coberturas.FindAsync(id);

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

            DTO_Cobertura eliminaCobertura = new DTO_Cobertura()
            {
                Id            = cobertura.Id,
                Descripcion   = cobertura.Descripcion,
                FechaCreacion = cobertura.FechaCreacion
            };

            db.Coberturas.Remove(cobertura);
            await db.SaveChangesAsync();

            return(Ok(eliminaCobertura));
        }
Beispiel #4
0
        public async Task <IHttpActionResult> PutCobertura(int id, DTO_Cobertura cobertura)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != cobertura.Id)
            {
                return(BadRequest());
            }

            Cobertura actualizaCobertura = await db.Coberturas.FindAsync(id);

            actualizaCobertura.Descripcion = cobertura.Descripcion;

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

            try
            {
                await db.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!CoberturaExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }