diff --git a/.idea/.idea.AaaaperoBack.dir/.idea/.gitignore b/.idea/.idea.AaaaperoBack.dir/.idea/.gitignore new file mode 100644 index 0000000..6f09796 --- /dev/null +++ b/.idea/.idea.AaaaperoBack.dir/.idea/.gitignore @@ -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/ diff --git a/.idea/.idea.AaaaperoBack.dir/.idea/encodings.xml b/.idea/.idea.AaaaperoBack.dir/.idea/encodings.xml new file mode 100644 index 0000000..df87cf9 --- /dev/null +++ b/.idea/.idea.AaaaperoBack.dir/.idea/encodings.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/.idea/.idea.AaaaperoBack.dir/.idea/indexLayout.xml b/.idea/.idea.AaaaperoBack.dir/.idea/indexLayout.xml new file mode 100644 index 0000000..27ba142 --- /dev/null +++ b/.idea/.idea.AaaaperoBack.dir/.idea/indexLayout.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/.idea.AaaaperoBack.dir/.idea/riderModule.iml b/.idea/.idea.AaaaperoBack.dir/.idea/riderModule.iml new file mode 100644 index 0000000..1a4e0d9 --- /dev/null +++ b/.idea/.idea.AaaaperoBack.dir/.idea/riderModule.iml @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/.idea/.idea.AaaaperoBack.dir/.idea/vcs.xml b/.idea/.idea.AaaaperoBack.dir/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/.idea.AaaaperoBack.dir/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/BackEndAaaapero/.dockerignore b/BackEndAaaapero/.dockerignore new file mode 100644 index 0000000..3729ff0 --- /dev/null +++ b/BackEndAaaapero/.dockerignore @@ -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 \ No newline at end of file diff --git a/BackEndAaaapero/.gitignore b/BackEndAaaapero/.gitignore new file mode 100644 index 0000000..b866a75 --- /dev/null +++ b/BackEndAaaapero/.gitignore @@ -0,0 +1,11 @@ +*.suo +*vs +*.userosscache +bin +obj +.vscode +.DS_Store +*.db +*appsettings.JSON +wwwroot +publish \ No newline at end of file diff --git a/BackEndAaaapero/Controllers/CustomerController.cs b/BackEndAaaapero/Controllers/CustomerController.cs new file mode 100644 index 0000000..8b7e869 --- /dev/null +++ b/BackEndAaaapero/Controllers/CustomerController.cs @@ -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>> GetCustomer() + { + return await _context.customers.ToListAsync(); + } + + [HttpGet("{id}")] + public ActionResult 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> PostCustomer(Customer customer) + { + _context.customers.Add(customer); + await _context.SaveChangesAsync(); + + return CreatedAtAction("GetCustomer", new { id = customer.id }, customer); + } + } +} \ No newline at end of file