diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..df30947 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ + +.idea/ diff --git a/BackEndAaaapero/Controllers/CustomerController.cs b/BackEndAaaapero/Controllers/CustomerController.cs index 5e34e19..044a06e 100644 --- a/BackEndAaaapero/Controllers/CustomerController.cs +++ b/BackEndAaaapero/Controllers/CustomerController.cs @@ -2,9 +2,9 @@ using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; +using BackEndAaaapero.Data; using Microsoft.AspNetCore.Mvc; using Microsoft.EntityFrameworkCore; -using Data; using DTO; using Models; @@ -28,35 +28,17 @@ namespace AaaaperoBack.Controllers } [HttpGet("{id}")] - public ActionResult GetCustomer_byId(int id) + public async Task> GetCustomer_byId(int id) { - var order = from orders in _context.orders - join product in _context.products on orders.product_id equals product.product_id - join customer in _context.customers on orders.customer_id equals customer.id - select new OrderDTO - { - customer_id = customer.id, - price = product.price, - order_id = orders.order_id, - product_id = product.product_id - }; - - var customers = from customer in _context.customers - join orders in _context.orders on customer.id equals orders.customer_id - select new CustomerDetailsDTO - { - Customer_id = customer.id, - Name = customer.name, - Orders = order.Where(x => x.customer_id == customer.id).ToList() - }; - - var customer_by_id = customers.ToList().Find(x => x.Customer_id == id); - - if (customer_by_id == null) + var customer = await _context.customers.FindAsync(id); + if(customer != null) + { + return customer; + } + else { return NotFound(); } - return customer_by_id; } [HttpPost] @@ -65,7 +47,7 @@ namespace AaaaperoBack.Controllers _context.customers.Add(customer); await _context.SaveChangesAsync(); - return CreatedAtAction("GetCustomer", new { id = customer.id }, customer); + return CreatedAtAction("GetCustomer", new { id = customer.Id }, customer); } } } \ No newline at end of file