Ejemplo n.º 1
0
 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");
     }
 }
Ejemplo n.º 2
0
        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")); }
        }