public Medicine Get(int id) { using (MedicineDBContext context = new MedicineDBContext()) { return(context.Medicines.FirstOrDefault(e => e.Id == id)); } }
public IEnumerable <Medicine> Get() { using (MedicineDBContext context = new MedicineDBContext()) { return(context.Medicines.ToList()); } }
public IHttpActionResult Delete(int id) { using (MedicineDBContext context = new MedicineDBContext()) { Medicine m = context.Medicines.FirstOrDefault(e => e.Id == id); context.Medicines.Remove(m); context.SaveChanges(); return(Ok()); } }
public IHttpActionResult Post(Medicine m) { using (MedicineDBContext context = new MedicineDBContext()) { context.Medicines.Add(new Medicine() { MedicineName = m.MedicineName, Stock = m.Stock, Price = m.Price }); context.SaveChanges(); //var data = context.Medicines.ToList(); } return(Ok()); }
public IHttpActionResult Put(Medicine m) { using (MedicineDBContext context = new MedicineDBContext()) { Medicine data = context.Medicines.Where(e => e.Id == m.Id).FirstOrDefault <Medicine>(); if (data != null) { data.MedicineName = m.MedicineName; data.Stock = m.Stock; data.Price = m.Price; context.SaveChanges(); } else { return(NotFound()); } return(Ok()); } }