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.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using BackEndAaaapero.Data;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
using Data;
|
|
||||||
using DTO;
|
using DTO;
|
||||||
using Models;
|
using Models;
|
||||||
|
|
||||||
|
|
@ -28,35 +28,17 @@ namespace AaaaperoBack.Controllers
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpGet("{id}")]
|
[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
|
var customer = await _context.customers.FindAsync(id);
|
||||||
join product in _context.products on orders.product_id equals product.product_id
|
if(customer != null)
|
||||||
join customer in _context.customers on orders.customer_id equals customer.id
|
{
|
||||||
select new OrderDTO
|
return customer;
|
||||||
{
|
}
|
||||||
customer_id = customer.id,
|
else
|
||||||
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)
|
|
||||||
{
|
{
|
||||||
return NotFound();
|
return NotFound();
|
||||||
}
|
}
|
||||||
return customer_by_id;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpPost]
|
[HttpPost]
|
||||||
|
|
@ -65,7 +47,7 @@ namespace AaaaperoBack.Controllers
|
||||||
_context.customers.Add(customer);
|
_context.customers.Add(customer);
|
||||||
await _context.SaveChangesAsync();
|
await _context.SaveChangesAsync();
|
||||||
|
|
||||||
return CreatedAtAction("GetCustomer", new { id = customer.id }, customer);
|
return CreatedAtAction("GetCustomer", new { id = customer.Id }, customer);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Loading…
Reference in New Issue