public IHttpActionResult Postrepas(repas repas) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } db.repas.Add(repas); try { db.SaveChanges(); } catch (DbUpdateException) { if (repasExists(repas.label)) { return(Conflict()); } else { throw; } } return(CreatedAtRoute("DefaultApi", new { id = repas.label }, repas)); }
public IHttpActionResult Putrepas(string id, repas repas) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != repas.label) { return(BadRequest()); } db.Entry(repas).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!repasExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public IHttpActionResult Deleterepas(string id) { repas repas = db.repas.Find(id); if (repas == null) { return(NotFound()); } db.repas.Remove(repas); db.SaveChanges(); return(Ok(repas)); }
public IHttpActionResult Getrepas(string id) { repas repas = db.repas.Find(id); RepaViewModel rep = new RepaViewModel(); if (repas == null) { return(NotFound()); } else { rep.description = repas.description; rep.label = repas.label; rep.photo = repas.photo; rep.idSpecN = repas.idSpecN; rep.label_typeRepas = repas.label_typeRepas; return(Ok(rep)); } }