public IHttpActionResult PutCarro(int id, Carro carro)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

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

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

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!CarroExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
Esempio n. 2
0
 public bool Post(Auto auto)
 {
     using (var context = new CarrosContext())
     {
         context.Autos.Add(auto);
         return(context.SaveChanges() > 0);
     }
 }
Esempio n. 3
0
 public bool Delete(int?id)
 {
     using (var context = new CarrosContext())
     {
         var AutoEliminar = context.Autos.FirstOrDefault(x => x.Id == id);
         context.Autos.Remove(AutoEliminar);
         return(context.SaveChanges() > 0);
     }
 }
Esempio n. 4
0
        public bool Put(Auto auto)
        {
            using (var context = new CarrosContext())
            {
                var AutoActualizar = context.Autos.FirstOrDefault(x => x.Id == auto.Id);

                AutoActualizar.Nombre = auto.Nombre;
                AutoActualizar.Modelo = auto.Modelo;
                AutoActualizar.Imagen = auto.Imagen;
                return(context.SaveChanges() > 0);
            }
        }