From 7b6f2fedf1080c0ea96f4975f82700db3e12d783 Mon Sep 17 00:00:00 2001 From: Serghei Cebotari Date: Tue, 14 Jan 2025 05:59:55 +0000 Subject: Add devcontainers --- .../Controllers/ProductsController.cs | 94 +++++++++++----------- 1 file changed, 47 insertions(+), 47 deletions(-) (limited to 'RhSolutions.SkuParser.Api/Controllers') diff --git a/RhSolutions.SkuParser.Api/Controllers/ProductsController.cs b/RhSolutions.SkuParser.Api/Controllers/ProductsController.cs index d85b01b..77b277b 100644 --- a/RhSolutions.SkuParser.Api/Controllers/ProductsController.cs +++ b/RhSolutions.SkuParser.Api/Controllers/ProductsController.cs @@ -1,48 +1,48 @@ -using Microsoft.AspNetCore.Mvc; -using RhSolutions.SkuParser.Models; -using RhSolutions.SkuParser.Services; - -namespace RhSolutions.SkuParser.Controllers; - -[ApiController] -[Route("/api/[controller]")] -public class ProductsController : ControllerBase -{ - private IServiceProvider _provider; - private Dictionary _result; - public ProductsController(IServiceProvider provider) - { - _provider = provider; - _result = new(); - } - - [HttpPost] - public IActionResult PostFiles() - { - IFormFileCollection files = Request.Form.Files; - try - { - foreach (var file in files) - { - ISkuParser parser = _provider.GetRequiredKeyedService(file.ContentType); - IEnumerable productQuantities = parser.ParseProducts(file); - foreach (ProductQuantity pq in productQuantities) - { - if (_result.ContainsKey(pq.Product)) - { - _result[pq.Product] += pq.Quantity; - } - else - { - _result.Add(pq.Product, pq.Quantity); - } - } - } - } - catch (Exception ex) - { - return BadRequest(error: $"{ex.Message}\n\n{ex.Source}\n{ex.StackTrace}"); - } - return new JsonResult(_result.Select(x => new { Sku = x.Key.ToString(), Quantity = x.Value })); - } +using Microsoft.AspNetCore.Mvc; +using RhSolutions.SkuParser.Models; +using RhSolutions.SkuParser.Services; + +namespace RhSolutions.SkuParser.Controllers; + +[ApiController] +[Route("/api/[controller]")] +public class ProductsController : ControllerBase +{ + private IServiceProvider _provider; + private Dictionary _result; + public ProductsController(IServiceProvider provider) + { + _provider = provider; + _result = new(); + } + + [HttpPost] + public IActionResult PostFiles() + { + IFormFileCollection files = Request.Form.Files; + try + { + foreach (var file in files) + { + ISkuParser parser = _provider.GetRequiredKeyedService(file.ContentType); + IEnumerable productQuantities = parser.ParseProducts(file); + foreach (ProductQuantity pq in productQuantities) + { + if (_result.ContainsKey(pq.Product)) + { + _result[pq.Product] += pq.Quantity; + } + else + { + _result.Add(pq.Product, pq.Quantity); + } + } + } + } + catch (Exception ex) + { + return BadRequest(error: $"{ex.Message}\n\n{ex.Source}\n{ex.StackTrace}"); + } + return new JsonResult(_result.Select(x => new { Sku = x.Key.ToString(), Quantity = x.Value })); + } } \ No newline at end of file -- cgit v1.2.3