CustomerController

This commit is contained in:
Yanis Hermassi 2021-03-25 19:32:36 +00:00
parent 5da18a893f
commit b7f111be21
8 changed files with 145 additions and 0 deletions

View File

@ -0,0 +1,13 @@
# Default ignored files
/shelf/
/workspace.xml
# Rider ignored files
/contentModel.xml
/projectSettingsUpdater.xml
/.idea.AaaaperoBack.iml
/modules.xml
# Datasource local storage ignored files
/dataSources/
/dataSources.local.xml
# Editor-based HTTP Client requests
/httpRequests/

View File

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Encoding" addBOMForNewFiles="with BOM under Windows, with no BOM otherwise" />
</project>

View File

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ContentModelUserStore">
<attachedFolders />
<explicitIncludes />
<explicitExcludes />
</component>
</project>

View File

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="RIDER_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$/../.." />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>

View File

@ -0,0 +1,25 @@
**/.classpath
**/.dockerignore
**/.env
**/.git
**/.gitignore
**/.project
**/.settings
**/.toolstarget
**/.vs
**/.vscode
**/*.*proj.user
**/*.dbmdl
**/*.jfm
**/azds.yaml
**/bin
**/charts
**/docker-compose*
**/Dockerfile*
**/node_modules
**/npm-debug.log
**/obj
**/secrets.dev.yaml
**/values.dev.yaml
LICENSE
README.md

11
BackEndAaaapero/.gitignore vendored Normal file
View File

@ -0,0 +1,11 @@
*.suo
*vs
*.userosscache
bin
obj
.vscode
.DS_Store
*.db
*appsettings.JSON
wwwroot
publish

View File

@ -0,0 +1,71 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using Shop.Data;
using DTO;
using Models;
namespace Aaaapero.Controllers
{
[ApiController]
[Route("[controller]")]
public class CustomerController : ControllerBase
{
private readonly Context _context;
public CustomerController(Context context)
{
_context = context;
}
[HttpGet]
public async Task<ActionResult<IEnumerable<Customer>>> GetCustomer()
{
return await _context.customers.ToListAsync();
}
[HttpGet("{id}")]
public ActionResult<CustomerDTO> 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)
{
return NotFound();
}
return customer_by_id;
}
[HttpPost]
public async Task<ActionResult<Customer>> PostCustomer(Customer customer)
{
_context.customers.Add(customer);
await _context.SaveChangesAsync();
return CreatedAtAction("GetCustomer", new { id = customer.id }, customer);
}
}
}