public Tomato Get(int id) { using (TomatoDb db = new TomatoDb()) { return(db.Tomatos.First(t => t.Id == id)); } }
public IEnumerable <Tomato> Get() { using (TomatoDb db = new TomatoDb()) { return(db.Tomatos.ToList()); } }
public void Post([FromBody] JObject value) { Tomato posted = value.ToObject <Tomato>(); using (TomatoDb db = new TomatoDb()) { db.Tomatos.Add(posted); db.SaveChanges(); } }
public void Delete(int id) { using (TomatoDb db = new TomatoDb()) { if (db.Tomatos.Where(t => t.Id == id).Count() > 0) // Check if element exists { db.Tomatos.Remove(db.Tomatos.First(t => t.Id == id)); } db.SaveChanges(); } }
public void Put(int id, [FromBody] JObject value) { Tomato posted = value.ToObject <Tomato>(); posted.Id = id; // Ensure an id is attached using (TomatoDb db = new TomatoDb()) { db.Tomatos.Update(posted); db.SaveChanges(); } }