public IActionResult Delete(int id) { using (SweetDBContext db = new SweetDBContext()) { var cust = db.Customer.FirstOrDefault(r => r.CustomerId == id); if (cust != null) { db.Customer.Remove(cust); db.SaveChanges(); return(Ok(cust)); } } return(NotFound()); }
public IActionResult Post([FromBody] Models.CustomerDTO customer) { Customer newCust = new Customer(); using (SweetDBContext db = new SweetDBContext()) { newCust.Forename = customer.CustomerForename; newCust.Surname = customer.CustomerSurname; newCust.Email = customer.CustomerEmail; newCust.Created = DateTime.Now; db.Customer.Add(newCust); var ret = db.SaveChanges(); } return(Ok(new Models.CustomerDTO() { CustomerId = newCust.CustomerId, CustomerForename = newCust.Forename, CustomerSurname = newCust.Surname, CustomerEmail = newCust.Email })); }
public IActionResult Put(int id, [FromBody] Models.CustomerDTO customer) { using (SweetDBContext db = new SweetDBContext()) { var cust = db.Customer.FirstOrDefault(r => r.CustomerId == id); if (cust != null) { cust.Forename = customer.CustomerForename; cust.Surname = customer.CustomerSurname; cust.Email = customer.CustomerEmail; db.SaveChanges(); return(Ok(new Models.CustomerDTO() { CustomerId = id, CustomerForename = cust.Forename, CustomerSurname = cust.Surname, CustomerEmail = cust.Email })); } } return(NotFound()); }