get by id
This commit is contained in:
parent
36819de03d
commit
c1776c156c
|
|
@ -0,0 +1,2 @@
|
|||
|
||||
.idea/
|
||||
|
|
@ -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<CustomerDTO> GetCustomer_byId(int id)
|
||||
public async Task<ActionResult<Customers>> 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue