public ActionResult <SampleCustomer> GetCustomer(int id) { try { var temp = CManager.GetCustomer(id); return(new SampleCustomer { ID = "https://localhost:44316/api/Customers/" + temp.ID.ToString(), Name = temp.Name, Adress = temp.Adress, OrderIds = temp.orderList.Select(s => "https://localhost:44316/api/Customers/Orders/" + s.ID.ToString()).ToList() }); } catch { return(NotFound("Customer doesn't exist")); } }
public ActionResult <Order> PostCustomerOrders(int id, [FromBody] SampleOrder order) { try { var tempCustomer = CManager.GetCustomer(id); Order temp = new Order(tempCustomer, order.products, order.total); OManager.AddOrder(temp); return(CreatedAtAction(nameof(GetCustomerOrder), new { Order_id = temp.ID }, temp)); } catch { return(NotFound("Customer doesn't exist")); } }
public ActionResult <List <SampleOrder> > GetAllCustomerOrders(int id) { try { CManager.GetCustomer(id); return(OManager.GetAllOrdersByCustomerId(id).Select(s => new SampleOrder() { ID = "https://localhost:44316/api/Customers/Orders/" + s.ID.ToString(), CustomerID = ("https://localhost:44316/api/Customers/" + s.Customer.ID).ToString(), total = s.Total, products = s.products }).ToList()); } catch { return(NotFound("Customer doesn't exist")); } }
public ActionResult DeleteCustomerOrders(int id, int Order_ID) { try { var tempCustomer = CManager.GetCustomer(id); var tempOrder = tempCustomer.orderList.FirstOrDefault(s => s.ID == Order_ID); if (tempOrder == null) { return(NotFound("Order doesn't exist")); } OManager.DeleteOrderById(tempOrder.ID); return(NoContent()); } catch { return(NotFound("Customer doesn't exist")); } }
public ActionResult DeleteCustomer(int id) { try { var temp = CManager.GetCustomer(id); if (temp.orderList.Count == 0) { CManager.DeleteCustomer(id); return(NoContent()); } else { return(BadRequest("Orders still linked to customer")); } } catch { return(NotFound("Customer doesn't exist")); } }
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")); } }
public ActionResult <SampleOrder> PutCustomerOrders(int id, int Order_ID, [FromBody] SampleOrder order) { try { var tempOrder = CManager.GetCustomer(id).orderList.FirstOrDefault(s => s.ID == Order_ID); if (tempOrder == null) { return(NotFound("Order doesn't exist")); } tempOrder.SetProduct(order.products); tempOrder.SetTotal(order.total); OManager.UpdateOrder(tempOrder); var temp = OManager.GetOrder(Order_ID); return(CreatedAtAction(nameof(GetCustomerOrder), new { Order_id = temp.ID }, temp)); } catch { return(NotFound("Customer doesn't exist")); } }