Example #1
0
 public Tomato Get(int id)
 {
     using (TomatoDb db = new TomatoDb())
     {
         return(db.Tomatos.First(t => t.Id == id));
     }
 }
Example #2
0
 public IEnumerable <Tomato> Get()
 {
     using (TomatoDb db = new TomatoDb())
     {
         return(db.Tomatos.ToList());
     }
 }
Example #3
0
        public void Post([FromBody] JObject value)
        {
            Tomato posted = value.ToObject <Tomato>();

            using (TomatoDb db = new TomatoDb())
            {
                db.Tomatos.Add(posted);
                db.SaveChanges();
            }
        }
Example #4
0
 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();
     }
 }
Example #5
0
        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();
            }
        }