CourseWork_CompShop/ComputerShopProvider/ComputerShopRestApi/Controllers/EquipmentReceivingController.cs

103 lines
2.9 KiB
C#
Raw Permalink Normal View History

2023-05-20 08:34:33 +04:00
using ComputerShopContracts.BindingModels;
using ComputerShopContracts.BusinessLogicContracts;
using ComputerShopContracts.SearchModels;
2023-12-01 19:59:06 +04:00
using ComputerShopContracts.StorageContracts;
2023-05-20 08:34:33 +04:00
using ComputerShopContracts.ViewModels;
2023-12-01 19:59:06 +04:00
using ComputerShopDatabaseImplement.Implements;
using DocumentFormat.OpenXml.Office2010.Excel;
2023-05-20 08:34:33 +04:00
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
namespace ComputerShopRestApi.Controllers
{
[Route("api/[controller]/[action]")]
[ApiController]
public class EquipmentReceivingController : Controller
{
2023-05-20 08:34:33 +04:00
private readonly ILogger _logger;
private readonly IEquipmentReceivingLogic _equipmentReceiving;
2023-12-01 19:59:06 +04:00
private readonly IEquipmentReceivingStorage _equipmentReceivingStorage;
public EquipmentReceivingController(ILogger<MainController> logger, IEquipmentReceivingLogic equipmentReceiving, IEquipmentReceivingStorage equipmentReceivingStorage)
2023-05-20 08:34:33 +04:00
{
_logger = logger;
_equipmentReceiving = equipmentReceiving;
2023-12-01 19:59:06 +04:00
_equipmentReceivingStorage = equipmentReceivingStorage;
}
2023-05-20 08:34:33 +04:00
[HttpGet]
public List<EquipmentReceivingViewModel>? GetReceivings(int clientId)
{
try
{
return _equipmentReceiving.ReadList(new EquipmentReceivingSearchModel
{
ClientId = clientId
});
}
catch (Exception ex)
{
2023-05-20 09:23:37 +04:00
_logger.LogError(ex, "Ошибка получения списка получений клиента id ={ Id}", clientId);
2023-05-20 08:34:33 +04:00
throw;
}
}
2023-12-01 19:59:06 +04:00
[HttpPost]
public void SetFinish(int id)
{
try
{
var receiving = _equipmentReceivingStorage.GetElement(new() { Id = id });
EquipmentReceivingBindingModel model = new EquipmentReceivingBindingModel()
{
Id = id,
ClientId = receiving.ClientId,
DateImplement = receiving.DateImplement,
Status = receiving.Status
};
_equipmentReceiving.Finish(model);
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка изменения закупки");
throw;
}
}
[HttpPost]
2023-05-20 08:34:33 +04:00
public void CreateReceiving(EquipmentReceivingBindingModel model)
{
try
{
_equipmentReceiving.Create(model);
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка создания получения");
throw;
}
}
2023-12-01 19:59:06 +04:00
[HttpPost]
public void DeleteReceiving(int id)
{
try
{
var receiving = _equipmentReceivingStorage.GetElement(new() { Id = id });
_equipmentReceiving.Delete(new()
{
Id = id,
ClientId = receiving.ClientId,
DateImplement = receiving.DateImplement,
Status = receiving.Status
});
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка удаления");
throw;
}
}
}
}