Comment errors + order contr + some fixes

This commit is contained in:
devil_1nc 2023-05-20 01:31:46 +04:00
parent 3ba667323d
commit e0c39713ee
7 changed files with 183 additions and 16 deletions

View File

@ -51,6 +51,12 @@ namespace ComputerShopBusinessLogic.BusinessLogics
var receivings = new List<EquipmentReceivingViewModel>();
// ОШИБКА: int не содержит определения HasValue()
/*
foreach(var supply in supplies)
{
if (supply.ReceivingId.HasValue)
@ -62,6 +68,9 @@ namespace ComputerShopBusinessLogic.BusinessLogics
}
}
}
*/
var receivingnames = new List<string>();
foreach (var receiving in receivings)
{

View File

@ -9,6 +9,7 @@ namespace ComputerShopContracts.SearchModels
public class OrderSearchModel
{
public int? Id { get; set; }
public int? ClientId { get; set; }
public DateTime? DateFrom { get; set; }
public DateTime? DateTo { get; set; }
}

View File

@ -15,7 +15,7 @@ namespace ComputerShopDatabaseImplement
{
if (optionsBuilder.IsConfigured == false)
{
optionsBuilder.UseSqlServer(@"Data Source=DESKTOP-IRUVF5S\SQLEXPRESS;Initial Catalog=ComputerShopDatabaseCW;Integrated Security=True;MultipleActiveResultSets=True;;TrustServerCertificate=True");
optionsBuilder.UseSqlServer(@"Data Source=DESKTOP-QA8P9OJ;Initial Catalog=ComputerShopDatabaseCW;Integrated Security=True;MultipleActiveResultSets=True;;TrustServerCertificate=True");
}
base.OnConfiguring(optionsBuilder);
}

View File

@ -56,7 +56,6 @@ namespace ComputerShopDatabaseImplement.Models
Status = model.Status,
DateCreate = model.DateCreate,
DateImplement = model.DateImplement,
Receiving = model.Receiving,
Orders = model.SupplyOrders.Select(x => new
SupplyOrder
{

View File

@ -0,0 +1,12 @@
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
namespace ComputerShopRestApi.Controllers
{
[Route("api/[controller]/[action]")]
[ApiController]
public class EquipmentReceivingController : Controller
{
}
}

View File

@ -7,43 +7,45 @@ using Microsoft.AspNetCore.Mvc;
namespace ComputerShopRestApi.Controllers
{
[Route("api/[controller]/[action]")]
[ApiController]
public class OrderController : Controller
{
private readonly ILogger _logger;
private readonly IOrderLogic order;
private readonly IComponentLogic component;
private readonly IOrderLogic _order;
private readonly ISupplyLogic _supply;
public OrderController(ILogger<MainController> logger, IOrderLogic order, IComponentLogic component)
public OrderController(ILogger<MainController> logger, IOrderLogic order, ISupplyLogic supply)
{
_logger = logger;
order = order;
component = component;
_order = order;
_supply = supply;
}
[HttpGet]
public List<ComponentViewModel>? GetComponentList()
public List<OrderViewModel>? GetOrderList(int clientId)
{
try
{
return component.ReadList(null);
return _order.ReadList(new OrderSearchModel { ClientId = clientId });
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка получения списка комплектующих");
_logger.LogError(ex, "Ошибка получения списка заказов");
throw;
}
}
[HttpGet]
public ComponentViewModel? GetPackage(int componentId)
public List<SupplyViewModel>? GetSuppliesList()
{
try
{
return component.ReadElement(new ComponentSearchModel { Id = componentId });
return _supply.ReadList(null);
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка получения продукта по id={Id}", componentId);
_logger.LogError(ex, "Ошибка получения списка компонентов");
throw;
}
}
@ -53,7 +55,7 @@ namespace ComputerShopRestApi.Controllers
{
try
{
return order.ReadList(new OrderSearchModel {});
return _order.ReadList(new OrderSearchModel {});
}
catch (Exception ex)
{
@ -67,7 +69,7 @@ namespace ComputerShopRestApi.Controllers
{
try
{
order.CreateOrder(model);
_order.CreateOrder(model);
}
catch (Exception ex)
{
@ -75,5 +77,18 @@ namespace ComputerShopRestApi.Controllers
throw;
}
}
[HttpDelete]
public void DeleteOrder(OrderBindingModel model)
{
try
{
_order.Delete(model);
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка при удалении заказа");
throw;
}
}
}
}

View File

@ -0,0 +1,131 @@
using ComputerShopContracts.BindingModels;
using ComputerShopContracts.BusinessLogicContracts;
using ComputerShopContracts.SearchModels;
using ComputerShopContracts.ViewModels;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
namespace ComputerShopRestApi.Controllers
{
[Route("api/[controller]/[action]")]
[ApiController]
public class SupplyController : Controller
{
private readonly ILogger _logger;
private readonly ISupplyLogic _supply;
private readonly IOrderLogic _order;
public SupplyController(ILogger<SupplyController> logger, ISupplyLogic supply, IOrderLogic order)
{
_logger = logger;
_supply = supply;
_order = order;
}
/*
[HttpGet]
public List<AssemblyViewModel>? GetAssemblyList(int clientId)
{
try
{
return _supply.ReadList(new SupplySearchModel
{
});
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка получения списка сборок");
throw;
}
}
[HttpGet]
public Tuple<AssemblyViewModel, List<Tuple<string, int>>>? GetAssembly(int assemblyId)
{
try
{
var elem = _supply.ReadElement(new SupplySearchModel { Id = assemblyId });
if (elem == null)
return null;
return Tuple.Create(elem, elem.AssemblyComponents.Select(x => Tuple.Create(x.Value.Item1.ComponentName, x.Value.Item2)).ToList());
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка получения сборки по id={Id}", assemblyId);
throw;
}
}
[HttpGet]
public List<ComponentViewModel>? GetComponentList()
{
try
{
return _component.ReadList(null);
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка получения списка компонентов");
throw;
}
}
[HttpPost]
public void CreateAssembly(AssemblyBindingModel model)
{
try
{
_assembly.Create(model);
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка создания сборки");
throw;
}
}
[HttpPost]
public void DeleteAssembly(AssemblyBindingModel model)
{
try
{
_assembly.Delete(model);
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка удаления сборки");
throw;
}
}
[HttpPost]
public void AddComponentToAssembly(Tuple<AssemblySearchModel, ComponentSearchModel, int> model)
{
try
{
_assembly.AddComponentToAssembly(model.Item1, model.Item2, model.Item3);
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка добавления компонента в сборку.");
throw;
}
}
[HttpPost]
public void EditAssembly(AssemblyBindingModel model)
{
try
{
_assembly.Update(model);
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка удаления сборки");
throw;
}
}
*/
}
}