public ActionResult <Customer> PostCustomer([FromBody] sample_object.SampleCustomer cus) { try { Customer customer = new Customer(cus.Name, cus.Adress); if (CManager.ExistCustomerCheck(customer)) { return(BadRequest("Customer already exists")); } CManager.AddCustomer(customer); return(CreatedAtAction(nameof(GetCustomer), new { id = customer.ID }, customer)); } catch { throw new Exception("invalid values"); } }
public ActionResult <Customer> PutCustomer(int ID, [FromBody] sample_object.SampleCustomer cus) { try { Customer customer = CManager.GetCustomer(ID); var temp = new Customer(cus.Name, cus.Adress); if (CManager.ExistCustomerCheck(temp)) { return(BadRequest("Customer already exists")); } customer.SetAdress(cus.Adress); customer.SetName(cus.Name); CManager.UpdateCustomer(ID, customer); return(CreatedAtAction(nameof(GetCustomer), new { id = ID }, CManager.GetCustomer(ID))); } catch { return(NotFound("Customer doesn't exist")); } }