Compare commits
43 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| a85fa1714f | |||
| f8c72b171c | |||
| 9a5b50286b | |||
| a6264c5b1b | |||
| fd667be8b0 | |||
| c9d251a794 | |||
| 2aace65848 | |||
| 6714d4f3ef | |||
| 30ba254e86 | |||
| fab7391ca7 | |||
| 1ff73bce3a | |||
| 22b2783547 | |||
| 10a344f0b1 | |||
| 8428b895a8 | |||
| 6d525876bc | |||
| a07aff9438 | |||
| 67bffd6798 | |||
| 1d24f91773 | |||
| c1a7d73d39 | |||
| 3d750ef0b2 | |||
| fe3e9171e8 | |||
| abf3aeca23 | |||
| 81b4335193 | |||
| da4f49e290 | |||
| 1b016cc7d8 | |||
| 26eadb9fd4 | |||
| 915758fdf0 | |||
| e3721f13cb | |||
| 3a5157069b | |||
| 6700d24634 | |||
| 1e49ce1e21 | |||
| 75911262ea | |||
| b81bb26b41 | |||
| ad9847c51c | |||
| 5d703cb615 | |||
| b4c8722cd4 | |||
| 2fa2dfe6bc | |||
| 1a650d93b1 | |||
| b4d4b6d0f4 | |||
| 57d43005e6 | |||
| 4330a80dd0 | |||
| 8447239146 | |||
| 8ad6e9478e |
@@ -15,11 +15,13 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AutoWorkshopListImplement",
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AutoWorkshopFileImplement", "AutoWorkshopFileImplement\AutoWorkshopFileImplement.csproj", "{862B0F3D-1B88-45B8-9526-AD21A6D6FA81}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AutoWorkshopDatabaseImplement", "AutoWorkshopDatabaseImplement\AutoWorkshopDatabaseImplement.csproj", "{751668F7-01A3-43F0-BDD8-ABB3A8F5A955}"
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AutoWorkshopDatabaseImplement", "AutoWorkshopDatabaseImplement\AutoWorkshopDatabaseImplement.csproj", "{751668F7-01A3-43F0-BDD8-ABB3A8F5A955}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AutoWorkshopRestApi", "AutoWorkshopRestApi\AutoWorkshopRestApi.csproj", "{15C54F32-1549-4887-BE08-DC6845B0D7ED}"
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AutoWorkshopRestApi", "AutoWorkshopRestApi\AutoWorkshopRestApi.csproj", "{15C54F32-1549-4887-BE08-DC6845B0D7ED}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AutoWorkshopClientApp", "AutoWorkshopClientApp\AutoWorkshopClientApp.csproj", "{EAE83B19-8CE1-4589-907A-DB9C8313FA06}"
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AutoWorkshopClientApp", "AutoWorkshopClientApp\AutoWorkshopClientApp.csproj", "{EAE83B19-8CE1-4589-907A-DB9C8313FA06}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AutoWorkshopShopApp", "AutoWorkshopShopApp\AutoWorkshopShopApp.csproj", "{5934B924-59F1-42B6-9116-33F4947525CC}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
@@ -63,6 +65,10 @@ Global
|
||||
{EAE83B19-8CE1-4589-907A-DB9C8313FA06}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{EAE83B19-8CE1-4589-907A-DB9C8313FA06}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{EAE83B19-8CE1-4589-907A-DB9C8313FA06}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{5934B924-59F1-42B6-9116-33F4947525CC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{5934B924-59F1-42B6-9116-33F4947525CC}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{5934B924-59F1-42B6-9116-33F4947525CC}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{5934B924-59F1-42B6-9116-33F4947525CC}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
|
||||
135
AutoWorkshopBusinessLogic/BusinessLogics/ImplementerLogic.cs
Normal file
135
AutoWorkshopBusinessLogic/BusinessLogics/ImplementerLogic.cs
Normal file
@@ -0,0 +1,135 @@
|
||||
using AutoWorkshopContracts.BindingModels;
|
||||
using AutoWorkshopContracts.BusinessLogicsContracts;
|
||||
using AutoWorkshopContracts.SearchModels;
|
||||
using AutoWorkshopContracts.StoragesContracts;
|
||||
using AutoWorkshopContracts.ViewModels;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace AutoWorkshopBusinessLogic.BusinessLogics
|
||||
{
|
||||
public class ImplementerLogic : IImplementerLogic
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly IImplementerStorage _implementerStorage;
|
||||
|
||||
public ImplementerLogic(ILogger<IImplementerLogic> Logger, IImplementerStorage ImplementerStorage)
|
||||
{
|
||||
_logger = Logger;
|
||||
_implementerStorage = ImplementerStorage;
|
||||
}
|
||||
|
||||
public List<ImplementerViewModel>? ReadList(ImplementerSearchModel? Model)
|
||||
{
|
||||
_logger.LogInformation("ReadList. ImplementerFIO: {ImplementerFIO}. Password: {Password}. Id: {Id}",
|
||||
Model?.ImplementerFIO, Model?.Password?.Length, Model?.Id);
|
||||
|
||||
var List = Model == null ? _implementerStorage.GetFullList() : _implementerStorage.GetFilteredList(Model);
|
||||
|
||||
if (List == null)
|
||||
{
|
||||
_logger.LogWarning("ReadList return null list");
|
||||
return null;
|
||||
}
|
||||
|
||||
_logger.LogInformation("ReadList. Count: {Count}", List.Count);
|
||||
return List;
|
||||
}
|
||||
|
||||
public ImplementerViewModel? ReadElement(ImplementerSearchModel Model)
|
||||
{
|
||||
if (Model is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(Model));
|
||||
}
|
||||
|
||||
_logger.LogInformation("ReadElement. ImplementerFIO: {ImplementerFIO}. Password: {Password}. Id: {Id}",
|
||||
Model?.ImplementerFIO, Model?.Password?.Length, Model?.Id);
|
||||
|
||||
var Element = _implementerStorage.GetElement(Model);
|
||||
|
||||
if (Element == null)
|
||||
{
|
||||
_logger.LogWarning("ReadElement element not found");
|
||||
return null;
|
||||
}
|
||||
|
||||
_logger.LogInformation("ReadElement find. Id: {Id}", Element.Id);
|
||||
return Element;
|
||||
}
|
||||
|
||||
public bool Create(ImplementerBindingModel Model)
|
||||
{
|
||||
CheckModel(Model);
|
||||
|
||||
if (_implementerStorage.Insert(Model) == null)
|
||||
{
|
||||
_logger.LogWarning("Insert operation failed");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool Update(ImplementerBindingModel Model)
|
||||
{
|
||||
CheckModel(Model);
|
||||
|
||||
if (_implementerStorage.Update(Model) == null)
|
||||
{
|
||||
_logger.LogWarning("Update operation failed");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool Delete(ImplementerBindingModel Model)
|
||||
{
|
||||
CheckModel(Model, false);
|
||||
|
||||
_logger.LogInformation("Delete. Id:{Id}", Model.Id);
|
||||
|
||||
if (_implementerStorage.Delete(Model) == null)
|
||||
{
|
||||
_logger.LogWarning("Delete operation failed");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private void CheckModel(ImplementerBindingModel Model, bool WithParams = true)
|
||||
{
|
||||
if (Model == null)
|
||||
throw new ArgumentNullException(nameof(Model));
|
||||
|
||||
if (!WithParams)
|
||||
return;
|
||||
|
||||
if (string.IsNullOrEmpty(Model.ImplementerFIO))
|
||||
throw new ArgumentNullException("Нет ФИО исполнителя", nameof(Model.ImplementerFIO));
|
||||
|
||||
if (string.IsNullOrEmpty(Model.Password))
|
||||
throw new ArgumentNullException("Нет пароля исполнителя", nameof(Model.Password));
|
||||
|
||||
if (Model.WorkExperience < 0)
|
||||
throw new ArgumentNullException("Стаж должен быть неотрицательным целым числом", nameof(Model.WorkExperience));
|
||||
|
||||
if (Model.Qualification < 0)
|
||||
throw new ArgumentNullException("Квалификация должна быть неотрицательным целым числом", nameof(Model.Qualification));
|
||||
|
||||
_logger.LogInformation("Implementer. ImplementerFIO: {ImplementerFIO}. Password: {Password}. WorkExperience: {WorkExperience}. Qualification: {Qualification}. Id: {Id}",
|
||||
Model.ImplementerFIO, Model.Password, Model.WorkExperience, Model.Qualification, Model.Id);
|
||||
|
||||
var Implementer = _implementerStorage.GetElement(new ImplementerSearchModel
|
||||
{
|
||||
ImplementerFIO = Model.ImplementerFIO
|
||||
});
|
||||
|
||||
if (Implementer != null && Implementer.Id != Model.Id)
|
||||
{
|
||||
throw new InvalidOperationException("Исполнитель с таким ФИО уже есть");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -4,6 +4,7 @@ using AutoWorkshopContracts.SearchModels;
|
||||
using AutoWorkshopContracts.StoragesContracts;
|
||||
using AutoWorkshopContracts.ViewModels;
|
||||
using AutoWorkshopDataModels.Enums;
|
||||
using DocumentFormat.OpenXml.EMMA;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace AutoWorkshopBusinessLogic.BusinessLogics
|
||||
@@ -13,28 +14,32 @@ namespace AutoWorkshopBusinessLogic.BusinessLogics
|
||||
private readonly ILogger _logger;
|
||||
|
||||
private readonly IOrderStorage _orderStorage;
|
||||
private readonly IShopStorage _shopStorage;
|
||||
|
||||
public OrderLogic(ILogger<RepairLogic> Logger, IOrderStorage OrderStorage)
|
||||
private static readonly object _locker = new object();
|
||||
|
||||
public OrderLogic(ILogger<RepairLogic> Logger, IOrderStorage OrderStorage, IShopStorage ShopStorage)
|
||||
{
|
||||
_logger = Logger;
|
||||
|
||||
_orderStorage = OrderStorage;
|
||||
_shopStorage = ShopStorage;
|
||||
}
|
||||
|
||||
public List<OrderViewModel>? ReadList(OrderSearchModel? Model)
|
||||
{
|
||||
_logger.LogInformation("ReadList. Id:{Id}", Model?.Id);
|
||||
_logger.LogInformation("ReadList. ClientId: {ClientId}. Status: {Status}. ImplementerId: {ImplementerId}. DateFrom: {DateFrom}. DateTo: {DateTo}. OrderId: {Id}",
|
||||
Model?.ClientId, Model?.Status, Model?.ImplementerId, Model?.DateFrom, Model?.DateTo, Model?.Id);
|
||||
|
||||
var List = Model is null ? _orderStorage.GetFullList() : _orderStorage.GetFilteredList(Model);
|
||||
|
||||
if (List is null)
|
||||
{
|
||||
_logger.LogWarning("ReadList return null list");
|
||||
return null;
|
||||
}
|
||||
|
||||
_logger.LogInformation("ReadList. Count: {Count}", List.Count);
|
||||
return List;
|
||||
}
|
||||
|
||||
public bool CreateOrder(OrderBindingModel Model)
|
||||
{
|
||||
CheckModel(Model);
|
||||
@@ -58,46 +63,29 @@ namespace AutoWorkshopBusinessLogic.BusinessLogics
|
||||
|
||||
private bool ChangeOrderStatus(OrderBindingModel Model, OrderStatus NewStatus)
|
||||
{
|
||||
CheckModel(Model, false);
|
||||
|
||||
var Order = _orderStorage.GetElement(new OrderSearchModel { Id = Model.Id });
|
||||
Model = FillOrderBindingModel(Model);
|
||||
|
||||
if (Order == null)
|
||||
{
|
||||
_logger.LogWarning("Change status operation failed. Order not found");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (Order.Status + 1 != NewStatus)
|
||||
if (Model.Status + 1 != NewStatus)
|
||||
{
|
||||
_logger.LogWarning("Change status operation failed. Incorrect new status: {NewStatus}. Current status: {currStatus}",
|
||||
NewStatus, Order.Status);
|
||||
NewStatus, Model.Status);
|
||||
return false;
|
||||
}
|
||||
|
||||
Model.RepairId = Order.RepairId;
|
||||
Model.Count = Order.Count;
|
||||
Model.Sum = Order.Sum;
|
||||
Model.DateCreate = Order.DateCreate;
|
||||
|
||||
Model.Status = NewStatus;
|
||||
|
||||
if (Model.Status == OrderStatus.Ready)
|
||||
Model.DateImplement = DateTime.Now;
|
||||
else
|
||||
Model.DateImplement = Order.DateImplement;
|
||||
|
||||
if (_orderStorage.Update(Model) == null)
|
||||
{
|
||||
_logger.LogWarning("Change status operation failed");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
return UpdateOrder(Model);
|
||||
}
|
||||
|
||||
public bool TakeOrderInWork(OrderBindingModel Model)
|
||||
{
|
||||
return ChangeOrderStatus(Model, OrderStatus.BeingProcessed);
|
||||
lock (_locker)
|
||||
{
|
||||
return ChangeOrderStatus(Model, OrderStatus.BeingProcessed);
|
||||
}
|
||||
}
|
||||
|
||||
public bool FinishOrder(OrderBindingModel Model)
|
||||
@@ -107,7 +95,29 @@ namespace AutoWorkshopBusinessLogic.BusinessLogics
|
||||
|
||||
public bool DeliveryOrder(OrderBindingModel Model)
|
||||
{
|
||||
return ChangeOrderStatus(Model, OrderStatus.Delivered);
|
||||
lock ( _locker)
|
||||
{
|
||||
Model = FillOrderBindingModel(Model);
|
||||
|
||||
if (Model.Status != OrderStatus.Ready && Model.Status != OrderStatus.Waiting)
|
||||
{
|
||||
_logger.LogWarning("Changing status operation failed");
|
||||
throw new InvalidOperationException($"Невозможно присвоить статус Delivered заказу с текущим статусом {Model.Status}");
|
||||
}
|
||||
|
||||
if (!_shopStorage.RestockingShops(new SupplyBindingModel
|
||||
{
|
||||
RepairId = Model.RepairId,
|
||||
Count = Model.Count
|
||||
}))
|
||||
{
|
||||
Model.Status = OrderStatus.Waiting;
|
||||
return UpdateOrder(Model);
|
||||
}
|
||||
|
||||
Model.Status = OrderStatus.Delivered;
|
||||
return UpdateOrder(Model);
|
||||
}
|
||||
}
|
||||
|
||||
private void CheckModel(OrderBindingModel Model, bool WithParams = true)
|
||||
@@ -129,5 +139,64 @@ namespace AutoWorkshopBusinessLogic.BusinessLogics
|
||||
Model.RepairId, Model.Count, Model.Sum, Model.Status, Model.DateCreate,
|
||||
Model.DateImplement, Model.Id);
|
||||
}
|
||||
}
|
||||
|
||||
public OrderViewModel? ReadElement(OrderSearchModel Model)
|
||||
{
|
||||
if (Model == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(Model));
|
||||
}
|
||||
|
||||
_logger.LogInformation("ReadElement. ClientId: {ClientId}. Status: {Status}. ImplementerId: {ImplementerId}. DateFrom: {DateFrom}. DateTo: {DateTo}. OrderId: {Id}",
|
||||
Model.ClientId, Model.Status, Model.ImplementerId, Model.DateFrom, Model.DateTo, Model.Id);
|
||||
|
||||
var Order = _orderStorage.GetElement(Model);
|
||||
|
||||
if (Order == null)
|
||||
{
|
||||
_logger.LogWarning("ReadElement element not found");
|
||||
return null;
|
||||
}
|
||||
|
||||
_logger.LogInformation("ReadElement find. Id: {Id}", Order.Id);
|
||||
return Order;
|
||||
}
|
||||
|
||||
private OrderBindingModel FillOrderBindingModel(OrderBindingModel Model)
|
||||
{
|
||||
CheckModel(Model, false);
|
||||
var OrderViewModel = _orderStorage.GetElement(new OrderSearchModel()
|
||||
{
|
||||
Id = Model.Id
|
||||
});
|
||||
if (OrderViewModel == null)
|
||||
{
|
||||
throw new InvalidOperationException(nameof(OrderViewModel));
|
||||
}
|
||||
Model.Id = OrderViewModel.Id;
|
||||
Model.DateCreate = OrderViewModel.DateCreate;
|
||||
Model.RepairId = OrderViewModel.RepairId;
|
||||
Model.DateImplement = OrderViewModel.DateImplement;
|
||||
Model.ClientId = OrderViewModel.ClientId;
|
||||
Model.Status = OrderViewModel.Status;
|
||||
Model.Count = OrderViewModel.Count;
|
||||
Model.Sum = OrderViewModel.Sum;
|
||||
if (!Model.ImplementerId.HasValue)
|
||||
{
|
||||
Model.ImplementerId = OrderViewModel.ImplementerId;
|
||||
}
|
||||
return Model;
|
||||
}
|
||||
|
||||
private bool UpdateOrder(OrderBindingModel Model)
|
||||
{
|
||||
if (_orderStorage.Update(Model) == null)
|
||||
{
|
||||
_logger.LogWarning("Update operation failed");
|
||||
return false;
|
||||
}
|
||||
_logger.LogWarning("Update operation sucsess");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,16 +13,18 @@ namespace AutoWorkshopBusinessLogic.BusinessLogics
|
||||
private readonly IComponentStorage _componentStorage;
|
||||
private readonly IRepairStorage _RepairStorage;
|
||||
private readonly IOrderStorage _orderStorage;
|
||||
private readonly IShopStorage _shopStorage;
|
||||
private readonly AbstractSaveToExcel _saveToExcel;
|
||||
private readonly AbstractSaveToWord _saveToWord;
|
||||
private readonly AbstractSaveToPdf _saveToPdf;
|
||||
|
||||
public ReportLogic(IRepairStorage RepairStorage, IComponentStorage ComponentStorage, IOrderStorage OrderStorage,
|
||||
public ReportLogic(IRepairStorage RepairStorage, IComponentStorage ComponentStorage, IOrderStorage OrderStorage, IShopStorage ShopStorage,
|
||||
AbstractSaveToExcel SaveToExcel, AbstractSaveToWord SaveToWord, AbstractSaveToPdf SaveToPdf)
|
||||
{
|
||||
_RepairStorage = RepairStorage;
|
||||
_componentStorage = ComponentStorage;
|
||||
_orderStorage = OrderStorage;
|
||||
_shopStorage = ShopStorage;
|
||||
|
||||
_saveToExcel = SaveToExcel;
|
||||
_saveToWord = SaveToWord;
|
||||
@@ -41,6 +43,26 @@ namespace AutoWorkshopBusinessLogic.BusinessLogics
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public List<ReportShopsViewModel> GetShops()
|
||||
{
|
||||
return _shopStorage.GetFullList().Select(x => new ReportShopsViewModel
|
||||
{
|
||||
ShopName = x.ShopName,
|
||||
Repairs = x.ShopRepairs.Select(x => (x.Value.Item1.RepairName, x.Value.Item2)).ToList(),
|
||||
TotalCount = x.ShopRepairs.Select(x => x.Value.Item2).Sum()
|
||||
}).ToList();
|
||||
}
|
||||
|
||||
public List<ReportGroupedOrdersViewModel> GetGroupedOrders()
|
||||
{
|
||||
return _orderStorage.GetFullList().GroupBy(x => x.DateCreate.Date).Select(x => new ReportGroupedOrdersViewModel
|
||||
{
|
||||
Date = x.Key,
|
||||
OrdersCount = x.Count(),
|
||||
OrdersSum = x.Select(y => y.Sum).Sum()
|
||||
}).ToList();
|
||||
}
|
||||
|
||||
public List<ReportOrdersViewModel> GetOrders(ReportBindingModel Model)
|
||||
{
|
||||
return _orderStorage.GetFilteredList(new OrderSearchModel { DateFrom = Model.DateFrom, DateTo = Model.DateTo })
|
||||
@@ -57,7 +79,7 @@ namespace AutoWorkshopBusinessLogic.BusinessLogics
|
||||
|
||||
public void SaveRepairsToWordFile(ReportBindingModel Model)
|
||||
{
|
||||
_saveToWord.CreateDoc(new WordInfo
|
||||
_saveToWord.CreateRepairsDoc(new WordRepairsInfo
|
||||
{
|
||||
FileName = Model.FileName,
|
||||
Title = "Список ремонтов",
|
||||
@@ -67,7 +89,7 @@ namespace AutoWorkshopBusinessLogic.BusinessLogics
|
||||
|
||||
public void SaveRepairComponentToExcelFile(ReportBindingModel Model)
|
||||
{
|
||||
_saveToExcel.CreateReport(new ExcelInfo
|
||||
_saveToExcel.CreateReport(new ExcelRepairsInfo
|
||||
{
|
||||
FileName = Model.FileName,
|
||||
Title = "Список ремонтов",
|
||||
@@ -77,7 +99,7 @@ namespace AutoWorkshopBusinessLogic.BusinessLogics
|
||||
|
||||
public void SaveOrdersToPdfFile(ReportBindingModel Model)
|
||||
{
|
||||
_saveToPdf.CreateDoc(new PdfInfo
|
||||
_saveToPdf.CreateDoc(new PdfOrdersInfo
|
||||
{
|
||||
FileName = Model.FileName,
|
||||
Title = "Список заказов",
|
||||
@@ -86,5 +108,35 @@ namespace AutoWorkshopBusinessLogic.BusinessLogics
|
||||
Orders = GetOrders(Model)
|
||||
});
|
||||
}
|
||||
|
||||
public void SaveShopsToWordFile(ReportBindingModel model)
|
||||
{
|
||||
_saveToWord.CreateShopsDoc(new WordShopsInfo
|
||||
{
|
||||
FileName = model.FileName,
|
||||
Title = "Список магазинов",
|
||||
Shops = _shopStorage.GetFullList()
|
||||
});
|
||||
}
|
||||
|
||||
public void SaveShopsToExcelFile(ReportBindingModel model)
|
||||
{
|
||||
_saveToExcel.CreateShopRepairsReport(new ExcelShopsInfo
|
||||
{
|
||||
FileName = model.FileName,
|
||||
Title = "Загруженность магазинов",
|
||||
ShopRepairs = GetShops()
|
||||
});
|
||||
}
|
||||
|
||||
public void SaveGroupedOrdersToPdfFile(ReportBindingModel model)
|
||||
{
|
||||
_saveToPdf.CreateGroupedOrdersDoc(new PdfGroupedOrdersInfo
|
||||
{
|
||||
FileName = model.FileName,
|
||||
Title = "Список заказов, объединенных по датам",
|
||||
GroupedOrders = GetGroupedOrders()
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
194
AutoWorkshopBusinessLogic/BusinessLogics/ShopLogic.cs
Normal file
194
AutoWorkshopBusinessLogic/BusinessLogics/ShopLogic.cs
Normal file
@@ -0,0 +1,194 @@
|
||||
using AutoWorkshopContracts.BindingModels;
|
||||
using AutoWorkshopContracts.BusinessLogicsContracts;
|
||||
using AutoWorkshopContracts.SearchModels;
|
||||
using AutoWorkshopContracts.StoragesContracts;
|
||||
using AutoWorkshopContracts.ViewModels;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace AutoWorkshopBusinessLogic.BusinessLogics
|
||||
{
|
||||
public class ShopLogic : IShopLogic
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly IShopStorage _shopStorage;
|
||||
private readonly IRepairStorage _repairStorage;
|
||||
|
||||
public ShopLogic(ILogger<ShopLogic> Logger, IShopStorage ShopStorage, IRepairStorage RepairStorage)
|
||||
{
|
||||
_logger = Logger;
|
||||
_shopStorage = ShopStorage;
|
||||
_repairStorage = RepairStorage;
|
||||
}
|
||||
|
||||
public List<ShopViewModel>? ReadList(ShopSearchModel? Model)
|
||||
{
|
||||
_logger.LogInformation("ReadList. ShopName:{ShopName}.Id:{ Id}", Model?.ShopName, Model?.Id);
|
||||
|
||||
var List = Model == null ? _shopStorage.GetFullList() : _shopStorage.GetFilteredList(Model);
|
||||
|
||||
if (List == null)
|
||||
{
|
||||
_logger.LogWarning("ReadList return null list");
|
||||
return null;
|
||||
}
|
||||
|
||||
_logger.LogInformation("ReadList. Count:{Count}", List.Count);
|
||||
return List;
|
||||
}
|
||||
|
||||
public ShopViewModel? ReadElement(ShopSearchModel Model)
|
||||
{
|
||||
if (Model == null)
|
||||
throw new ArgumentNullException(nameof(Model));
|
||||
|
||||
_logger.LogInformation("ReadElement. ShopName:{ShopName}.Id:{ Id}", Model.ShopName, Model.Id);
|
||||
|
||||
var Element = _shopStorage.GetElement(Model);
|
||||
if (Element == null)
|
||||
{
|
||||
_logger.LogWarning("ReadElement element not found");
|
||||
return null;
|
||||
}
|
||||
|
||||
_logger.LogInformation("ReadElement find. Id:{Id}", Element.Id);
|
||||
return Element;
|
||||
}
|
||||
|
||||
public bool Create(ShopBindingModel Model)
|
||||
{
|
||||
CheckModel(Model);
|
||||
|
||||
if (_shopStorage.Insert(Model) == null)
|
||||
{
|
||||
_logger.LogWarning("Insert operation failed");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool Update(ShopBindingModel Model)
|
||||
{
|
||||
CheckModel(Model);
|
||||
|
||||
if (_shopStorage.Update(Model) == null)
|
||||
{
|
||||
_logger.LogWarning("Update operation failed");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool Delete(ShopBindingModel Model)
|
||||
{
|
||||
CheckModel(Model, false);
|
||||
_logger.LogInformation("Delete. Id:{Id}", Model.Id);
|
||||
|
||||
if (_shopStorage.Delete(Model) == null)
|
||||
{
|
||||
_logger.LogWarning("Delete operation failed");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool MakeSupply(SupplyBindingModel Model)
|
||||
{
|
||||
if (Model == null)
|
||||
throw new ArgumentNullException(nameof(Model));
|
||||
|
||||
if (Model.Count <= 0)
|
||||
throw new ArgumentException("Количество ремонтов должно быть больше 0");
|
||||
|
||||
ShopViewModel? Shop = _shopStorage.GetElement(new ShopSearchModel
|
||||
{
|
||||
Id = Model.ShopId
|
||||
});
|
||||
|
||||
if (Shop == null)
|
||||
throw new ArgumentException("Магазина не существует");
|
||||
|
||||
int CurrentRepairsNum = Shop.ShopRepairs.Select(x => x.Value.Item2).Sum();
|
||||
if (Model.Count > Shop.RepairsMaxCount - CurrentRepairsNum)
|
||||
{
|
||||
_logger.LogWarning("Попытка добавить в магазин число элементов, большее RepairsMaxCount");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (Shop.ShopRepairs.ContainsKey(Model.RepairId))
|
||||
{
|
||||
var RepairsNum = Shop.ShopRepairs[Model.RepairId];
|
||||
RepairsNum.Item2 += Model.Count;
|
||||
Shop.ShopRepairs[Model.RepairId] = RepairsNum;
|
||||
}
|
||||
else
|
||||
{
|
||||
var Repair = _repairStorage.GetElement(new RepairSearchModel
|
||||
{
|
||||
Id = Model.RepairId
|
||||
});
|
||||
|
||||
if (Repair == null)
|
||||
throw new ArgumentException($"Поставка: Товар с id {Model.RepairId} не найден");
|
||||
|
||||
Shop.ShopRepairs.Add(Model.RepairId, (Repair, Model.Count));
|
||||
}
|
||||
|
||||
_shopStorage.Update(new ShopBindingModel()
|
||||
{
|
||||
Id = Shop.Id,
|
||||
ShopName = Shop.ShopName,
|
||||
Address = Shop.Address,
|
||||
OpeningDate = Shop.OpeningDate,
|
||||
ShopRepairs = Shop.ShopRepairs,
|
||||
RepairsMaxCount = Shop.RepairsMaxCount,
|
||||
});
|
||||
return true;
|
||||
}
|
||||
|
||||
private void CheckModel(ShopBindingModel Model, bool WithParams=true)
|
||||
{
|
||||
if (Model == null)
|
||||
throw new ArgumentNullException(nameof(Model));
|
||||
|
||||
if (!WithParams)
|
||||
return;
|
||||
|
||||
if (string.IsNullOrEmpty(Model.Address))
|
||||
throw new ArgumentException("Адрес магазина длжен быть заполнен", nameof(Model.Address));
|
||||
|
||||
if (string.IsNullOrEmpty(Model.ShopName))
|
||||
throw new ArgumentException("Название магазина должно быть заполнено", nameof(Model.ShopName));
|
||||
|
||||
_logger.LogInformation("Shop. ShopName: {ShopName}. Address: {Address}. OpeningDate: {OpeningDate}. Id:{Id}",
|
||||
Model.ShopName, Model.Address, Model.OpeningDate, Model.Id);
|
||||
|
||||
var Element = _shopStorage.GetElement(new ShopSearchModel
|
||||
{
|
||||
ShopName = Model.ShopName
|
||||
});
|
||||
if (Element != null && Element.Id != Model.Id)
|
||||
{
|
||||
throw new InvalidOperationException("Магазин с таким названием уже есть");
|
||||
}
|
||||
}
|
||||
|
||||
public bool MakeSell(SupplySearchModel Model)
|
||||
{
|
||||
if (!Model.RepairId.HasValue || !Model.Count.HasValue)
|
||||
return false;
|
||||
|
||||
_logger.LogInformation("Поиск ремонтов во всех магазинах");
|
||||
if (_shopStorage.Sell(Model))
|
||||
{
|
||||
_logger.LogInformation("Продажа выполнена успешно");
|
||||
return true;
|
||||
}
|
||||
|
||||
_logger.LogInformation("Продажа не выполнена");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
193
AutoWorkshopBusinessLogic/BusinessLogics/WorkModeling.cs
Normal file
193
AutoWorkshopBusinessLogic/BusinessLogics/WorkModeling.cs
Normal file
@@ -0,0 +1,193 @@
|
||||
using AutoWorkshopContracts.BindingModels;
|
||||
using AutoWorkshopContracts.BusinessLogicContracts;
|
||||
using AutoWorkshopContracts.BusinessLogicsContracts;
|
||||
using AutoWorkshopContracts.SearchModels;
|
||||
using AutoWorkshopContracts.ViewModels;
|
||||
using AutoWorkshopDataModels.Enums;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace AutoWorkshopBusinessLogic.BusinessLogics
|
||||
{
|
||||
public class WorkModeling : IWorkProcess
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
|
||||
private readonly Random _rnd;
|
||||
|
||||
private IOrderLogic? _orderLogic;
|
||||
|
||||
public WorkModeling(ILogger<WorkModeling> Logger)
|
||||
{
|
||||
_logger = Logger;
|
||||
_rnd = new Random(1000);
|
||||
}
|
||||
|
||||
public void DoWork(IImplementerLogic ImplementerLogic, IOrderLogic OrderLogic)
|
||||
{
|
||||
_orderLogic = OrderLogic;
|
||||
|
||||
var Implementers = ImplementerLogic.ReadList(null);
|
||||
|
||||
if (Implementers == null)
|
||||
{
|
||||
_logger.LogWarning("DoWork. Implementers is null");
|
||||
return;
|
||||
}
|
||||
|
||||
var Orders = _orderLogic.ReadList(new OrderSearchModel { Status = OrderStatus.Accepted });
|
||||
var BeingProcessedOrders = _orderLogic.ReadList(new OrderSearchModel { Status = OrderStatus.BeingProcessed });
|
||||
var WaitingOrders = _orderLogic.ReadList(new OrderSearchModel { Status = OrderStatus.Waiting });
|
||||
|
||||
if (Orders == null || BeingProcessedOrders == null || WaitingOrders == null)
|
||||
{
|
||||
_logger.LogWarning("DoWork. Orders are null");
|
||||
return;
|
||||
}
|
||||
if (Orders.Count == 0 && BeingProcessedOrders.Count == 0 && WaitingOrders.Count == 0)
|
||||
{
|
||||
_logger.LogWarning("DoWork. No orders to process");
|
||||
return;
|
||||
}
|
||||
|
||||
_logger.LogDebug("DoWork for {Count} orders", Orders.Count);
|
||||
|
||||
foreach (var Implementer in Implementers)
|
||||
{
|
||||
Task.Run(() => WorkerWorkAsync(Implementer, Orders));
|
||||
}
|
||||
}
|
||||
|
||||
private async Task WorkerWorkAsync(ImplementerViewModel Implementer, List<OrderViewModel> Orders)
|
||||
{
|
||||
if (_orderLogic == null || Implementer == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
await RunWaitingOrders(Implementer);
|
||||
await RunOrderInWork(Implementer);
|
||||
|
||||
await Task.Run(() =>
|
||||
{
|
||||
foreach (var Order in Orders)
|
||||
{
|
||||
try
|
||||
{
|
||||
_logger.LogDebug("WorkerWorkAsync. Worker {Id} try get order {Order}", Implementer.Id, Order.Id);
|
||||
|
||||
// TakeOrderInWork will fail when the worker tries to change status to BeingProcessed when the order is already BeingProcessed
|
||||
// which would happen when other worker already acquired that order
|
||||
bool AcquireResult = _orderLogic.TakeOrderInWork(new OrderBindingModel
|
||||
{
|
||||
Id = Order.Id,
|
||||
ImplementerId = Implementer.Id
|
||||
});
|
||||
|
||||
if (!AcquireResult)
|
||||
{
|
||||
_logger.LogDebug("WorkerWorkAsync. Worker {Id} tried to get order {Order} but it's already acquired by other worker", Implementer.Id, Order.Id);
|
||||
continue;
|
||||
}
|
||||
|
||||
Thread.Sleep(Implementer.WorkExperience * _rnd.Next(100, 1000) * Order.Count);
|
||||
|
||||
_logger.LogDebug("WorkerWorkAsync. Worker {Id} finish order {Order}", Implementer.Id, Order.Id);
|
||||
_orderLogic.FinishOrder(new OrderBindingModel { Id = Order.Id });
|
||||
_orderLogic.DeliveryOrder(new OrderBindingModel { Id = Order.Id });
|
||||
}
|
||||
|
||||
catch (InvalidOperationException ex)
|
||||
{
|
||||
_logger.LogWarning(ex, "Error try get work");
|
||||
}
|
||||
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Error while do work");
|
||||
throw;
|
||||
}
|
||||
|
||||
Thread.Sleep(Implementer.Qualification * _rnd.Next(10, 100));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private async Task RunOrderInWork(ImplementerViewModel Implementer)
|
||||
{
|
||||
if (_orderLogic == null || Implementer == null)
|
||||
return;
|
||||
|
||||
try
|
||||
{
|
||||
var RunOrder = await Task.Run(() => _orderLogic.ReadElement(new OrderSearchModel
|
||||
{
|
||||
ImplementerId = Implementer.Id,
|
||||
Status = OrderStatus.BeingProcessed
|
||||
}));
|
||||
|
||||
if (RunOrder == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_logger.LogDebug("RunOrderInWork. Worker {Id} back to order {Order}", Implementer.Id, RunOrder.Id);
|
||||
Thread.Sleep(Implementer.WorkExperience * _rnd.Next(100, 300) * RunOrder.Count);
|
||||
|
||||
_logger.LogDebug("RunOrderInWork. Worker {Id} finish order {Order}", Implementer.Id, RunOrder.Id);
|
||||
_orderLogic.FinishOrder(new OrderBindingModel { Id = RunOrder.Id });
|
||||
_orderLogic.DeliveryOrder(new OrderBindingModel { Id = RunOrder.Id });
|
||||
|
||||
Thread.Sleep(Implementer.Qualification * _rnd.Next(10, 100));
|
||||
}
|
||||
|
||||
catch (InvalidOperationException ex)
|
||||
{
|
||||
_logger.LogWarning(ex, "Error try get work");
|
||||
}
|
||||
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Error while do work");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
private async Task RunWaitingOrders(ImplementerViewModel Implementer)
|
||||
{
|
||||
if (_orderLogic == null || Implementer == null)
|
||||
return;
|
||||
|
||||
var WaitingOrders = await Task.Run(() => _orderLogic.ReadList(new OrderSearchModel
|
||||
{
|
||||
ImplementerId = Implementer.Id,
|
||||
Status = OrderStatus.Waiting
|
||||
}));
|
||||
if (WaitingOrders == null || WaitingOrders.Count == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_logger.LogDebug("RunWaitingOrders for {Count} orders. Implementer: {id}.", WaitingOrders.Count, Implementer.Id);
|
||||
foreach (var WaitingOrder in WaitingOrders)
|
||||
{
|
||||
try
|
||||
{
|
||||
_logger.LogInformation("RunWaitingOrders. Order {Order} delivery", WaitingOrder.Id);
|
||||
_orderLogic.DeliveryOrder(new OrderBindingModel
|
||||
{
|
||||
Id = WaitingOrder.Id
|
||||
});
|
||||
}
|
||||
catch (InvalidOperationException ex)
|
||||
{
|
||||
_logger.LogWarning(ex, $"Error try deliver waiting order {WaitingOrder.Id}");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, $"Error while delivering waiting order {WaitingOrder.Id}");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -5,7 +5,7 @@ namespace AutoWorkshopBusinessLogic.OfficePackage
|
||||
{
|
||||
public abstract class AbstractSaveToExcel
|
||||
{
|
||||
public void CreateReport(ExcelInfo Info)
|
||||
public void CreateReport(ExcelRepairsInfo Info)
|
||||
{
|
||||
CreateExcel(Info);
|
||||
|
||||
@@ -78,13 +78,88 @@ namespace AutoWorkshopBusinessLogic.OfficePackage
|
||||
|
||||
SaveExcel(Info);
|
||||
}
|
||||
|
||||
protected abstract void CreateExcel(ExcelInfo Info);
|
||||
|
||||
public void CreateShopRepairsReport(ExcelShopsInfo Info)
|
||||
{
|
||||
CreateExcel(Info);
|
||||
|
||||
InsertCellInWorksheet(new ExcelCellParameters
|
||||
{
|
||||
ColumnName = "A",
|
||||
RowIndex = 1,
|
||||
Text = Info.Title,
|
||||
StyleInfo = ExcelStyleInfoType.Title
|
||||
});
|
||||
|
||||
MergeCells(new ExcelMergeParameters
|
||||
{
|
||||
CellFromName = "A1",
|
||||
CellToName = "C1"
|
||||
});
|
||||
|
||||
uint RowIndex = 2;
|
||||
|
||||
foreach (var ShopRep in Info.ShopRepairs)
|
||||
{
|
||||
InsertCellInWorksheet(new ExcelCellParameters
|
||||
{
|
||||
ColumnName = "A",
|
||||
RowIndex = RowIndex,
|
||||
Text = ShopRep.ShopName,
|
||||
StyleInfo = ExcelStyleInfoType.Text
|
||||
});
|
||||
|
||||
RowIndex++;
|
||||
|
||||
foreach (var (Repair, Count) in ShopRep.Repairs)
|
||||
{
|
||||
InsertCellInWorksheet(new ExcelCellParameters
|
||||
{
|
||||
ColumnName = "B",
|
||||
RowIndex = RowIndex,
|
||||
Text = Repair,
|
||||
StyleInfo = ExcelStyleInfoType.TextWithBroder
|
||||
});
|
||||
|
||||
InsertCellInWorksheet(new ExcelCellParameters
|
||||
{
|
||||
ColumnName = "C",
|
||||
RowIndex = RowIndex,
|
||||
Text = Count.ToString(),
|
||||
StyleInfo = ExcelStyleInfoType.TextWithBroder
|
||||
});
|
||||
|
||||
RowIndex++;
|
||||
}
|
||||
|
||||
InsertCellInWorksheet(new ExcelCellParameters
|
||||
{
|
||||
ColumnName = "A",
|
||||
RowIndex = RowIndex,
|
||||
Text = "Итого",
|
||||
StyleInfo = ExcelStyleInfoType.Text
|
||||
});
|
||||
|
||||
InsertCellInWorksheet(new ExcelCellParameters
|
||||
{
|
||||
ColumnName = "C",
|
||||
RowIndex = RowIndex,
|
||||
Text = ShopRep.TotalCount.ToString(),
|
||||
StyleInfo = ExcelStyleInfoType.Text
|
||||
});
|
||||
|
||||
RowIndex++;
|
||||
}
|
||||
|
||||
SaveExcel(Info);
|
||||
}
|
||||
|
||||
protected abstract void CreateExcel(IDocumentInfo Info);
|
||||
|
||||
protected abstract void InsertCellInWorksheet(ExcelCellParameters ExcelParams);
|
||||
|
||||
protected abstract void MergeCells(ExcelMergeParameters ExcelParams);
|
||||
|
||||
protected abstract void SaveExcel(ExcelInfo Info);
|
||||
protected abstract void SaveExcel(IDocumentInfo Info);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ namespace AutoWorkshopBusinessLogic.OfficePackage
|
||||
{
|
||||
public abstract class AbstractSaveToPdf
|
||||
{
|
||||
public void CreateDoc(PdfInfo Info)
|
||||
public void CreateDoc(PdfOrdersInfo Info)
|
||||
{
|
||||
CreatePdf(Info);
|
||||
CreateParagraph(new PdfParagraph { Text = Info.Title, Style = "NormalTitle", ParagraphAlignment = PdfParagraphAlignmentType.Center });
|
||||
@@ -33,8 +33,35 @@ namespace AutoWorkshopBusinessLogic.OfficePackage
|
||||
|
||||
SavePdf(Info);
|
||||
}
|
||||
|
||||
protected abstract void CreatePdf(PdfInfo Info);
|
||||
|
||||
public void CreateGroupedOrdersDoc(PdfGroupedOrdersInfo Info)
|
||||
{
|
||||
CreatePdf(Info);
|
||||
CreateParagraph(new PdfParagraph { Text = Info.Title, Style = "NormalTitle", ParagraphAlignment = PdfParagraphAlignmentType.Center });
|
||||
|
||||
CreateTable(new List<string> { "4cm", "3cm", "2cm" });
|
||||
CreateRow(new PdfRowParameters
|
||||
{
|
||||
Texts = new List<string> { "Дата заказа", "Кол-во", "Сумма" },
|
||||
Style = "NormalTitle",
|
||||
ParagraphAlignment = PdfParagraphAlignmentType.Center
|
||||
});
|
||||
|
||||
foreach (var groupedOrder in Info.GroupedOrders)
|
||||
{
|
||||
CreateRow(new PdfRowParameters
|
||||
{
|
||||
Texts = new List<string> { groupedOrder.Date.ToShortDateString(), groupedOrder.OrdersCount.ToString(), groupedOrder.OrdersSum.ToString() },
|
||||
Style = "Normal",
|
||||
ParagraphAlignment = PdfParagraphAlignmentType.Left
|
||||
});
|
||||
}
|
||||
|
||||
CreateParagraph(new PdfParagraph { Text = $"Итого: {Info.GroupedOrders.Sum(x => x.OrdersSum)}\t", Style = "Normal", ParagraphAlignment = PdfParagraphAlignmentType.Center });
|
||||
SavePdf(Info);
|
||||
}
|
||||
|
||||
protected abstract void CreatePdf(IDocumentInfo Info);
|
||||
|
||||
protected abstract void CreateParagraph(PdfParagraph Paragraph);
|
||||
|
||||
@@ -42,6 +69,6 @@ namespace AutoWorkshopBusinessLogic.OfficePackage
|
||||
|
||||
protected abstract void CreateRow(PdfRowParameters RowParameters);
|
||||
|
||||
protected abstract void SavePdf(PdfInfo Info);
|
||||
protected abstract void SavePdf(IDocumentInfo Info);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ namespace AutoWorkshopBusinessLogic.OfficePackage
|
||||
{
|
||||
public abstract class AbstractSaveToWord
|
||||
{
|
||||
public void CreateDoc(WordInfo Info)
|
||||
public void CreateRepairsDoc(WordRepairsInfo Info)
|
||||
{
|
||||
CreateWord(Info);
|
||||
|
||||
@@ -37,11 +37,57 @@ namespace AutoWorkshopBusinessLogic.OfficePackage
|
||||
|
||||
SaveWord(Info);
|
||||
}
|
||||
|
||||
protected abstract void CreateWord(WordInfo Info);
|
||||
|
||||
public void CreateShopsDoc(WordShopsInfo Info)
|
||||
{
|
||||
CreateWord(Info);
|
||||
|
||||
CreateParagraph(new WordParagraph
|
||||
{
|
||||
Texts = new List<(string, WordTextProperties)> { (Info.Title, new WordTextProperties { Bold = true, Size = "24", }) },
|
||||
TextProperties = new WordTextProperties
|
||||
{
|
||||
Size = "24",
|
||||
JustificationType = WordJustificationType.Center
|
||||
}
|
||||
});
|
||||
|
||||
CreateTable(new List<string> { "3000", "3000", "3000" });
|
||||
CreateRow(new WordRowParameters
|
||||
{
|
||||
Texts = new List<string> { "Название", "Адрес", "Дата открытия" },
|
||||
TextProperties = new WordTextProperties
|
||||
{
|
||||
Size = "24",
|
||||
Bold = true,
|
||||
JustificationType = WordJustificationType.Center
|
||||
}
|
||||
});
|
||||
|
||||
foreach (var Shop in Info.Shops)
|
||||
{
|
||||
CreateRow(new WordRowParameters
|
||||
{
|
||||
Texts = new List<string> { Shop.ShopName, Shop.Address, Shop.OpeningDate.ToString() },
|
||||
TextProperties = new WordTextProperties
|
||||
{
|
||||
Size = "22",
|
||||
JustificationType = WordJustificationType.Both
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
SaveWord(Info);
|
||||
}
|
||||
|
||||
protected abstract void CreateWord(IDocumentInfo Info);
|
||||
|
||||
protected abstract void CreateParagraph(WordParagraph Paragraph);
|
||||
|
||||
protected abstract void SaveWord(WordInfo Info);
|
||||
protected abstract void SaveWord(IDocumentInfo Info);
|
||||
|
||||
protected abstract void CreateTable(List<string> Colums);
|
||||
|
||||
protected abstract void CreateRow(WordRowParameters RowParameters);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
namespace AutoWorkshopBusinessLogic.OfficePackage.HelperModels
|
||||
{
|
||||
public class ExcelInfo
|
||||
public class ExcelRepairsInfo : IDocumentInfo
|
||||
{
|
||||
public string FileName { get; set; } = string.Empty;
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
using AutoWorkshopContracts.ViewModels;
|
||||
|
||||
namespace AutoWorkshopBusinessLogic.OfficePackage.HelperModels
|
||||
{
|
||||
public class ExcelShopsInfo : IDocumentInfo
|
||||
{
|
||||
public string FileName { get; set; } = string.Empty;
|
||||
|
||||
public string Title { get; set; } = string.Empty;
|
||||
|
||||
public List<ReportShopsViewModel> ShopRepairs { get; set; } = new();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
namespace AutoWorkshopBusinessLogic.OfficePackage.HelperModels
|
||||
{
|
||||
public interface IDocumentInfo
|
||||
{
|
||||
public string FileName { get; set; }
|
||||
|
||||
public string Title { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
using AutoWorkshopContracts.ViewModels;
|
||||
|
||||
namespace AutoWorkshopBusinessLogic.OfficePackage.HelperModels
|
||||
{
|
||||
public class PdfGroupedOrdersInfo : IDocumentInfo
|
||||
{
|
||||
public string FileName { get; set; } = string.Empty;
|
||||
|
||||
public string Title { get; set; } = string.Empty;
|
||||
|
||||
public DateTime DateFrom { get; set; }
|
||||
|
||||
public DateTime DateTo { get; set; }
|
||||
|
||||
public List<ReportGroupedOrdersViewModel> GroupedOrders { get; set; } = new();
|
||||
}
|
||||
}
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
namespace AutoWorkshopBusinessLogic.OfficePackage.HelperModels
|
||||
{
|
||||
public class PdfInfo
|
||||
public class PdfOrdersInfo : IDocumentInfo
|
||||
{
|
||||
public string FileName { get; set; } = string.Empty;
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
namespace AutoWorkshopBusinessLogic.OfficePackage.HelperModels
|
||||
{
|
||||
public class WordInfo
|
||||
public class WordRepairsInfo : IDocumentInfo
|
||||
{
|
||||
public string FileName { get; set; } = string.Empty;
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
namespace AutoWorkshopBusinessLogic.OfficePackage.HelperModels
|
||||
{
|
||||
public class WordRowParameters
|
||||
{
|
||||
public List<string> Texts { get; set; } = new();
|
||||
|
||||
public WordTextProperties TextProperties { get; set; } = new();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
using AutoWorkshopContracts.ViewModels;
|
||||
|
||||
namespace AutoWorkshopBusinessLogic.OfficePackage.HelperModels
|
||||
{
|
||||
public class WordShopsInfo : IDocumentInfo
|
||||
{
|
||||
public string FileName { get; set; } = string.Empty;
|
||||
|
||||
public string Title { get; set; } = string.Empty;
|
||||
|
||||
public List<ShopViewModel> Shops { get; set; } = new();
|
||||
}
|
||||
}
|
||||
@@ -139,7 +139,7 @@ namespace AutoWorkshopBusinessLogic.OfficePackage.Implements
|
||||
};
|
||||
}
|
||||
|
||||
protected override void CreateExcel(ExcelInfo Info)
|
||||
protected override void CreateExcel(IDocumentInfo Info)
|
||||
{
|
||||
_spreadsheetDocument = SpreadsheetDocument.Create(Info.FileName, SpreadsheetDocumentType.Workbook);
|
||||
|
||||
@@ -269,7 +269,7 @@ namespace AutoWorkshopBusinessLogic.OfficePackage.Implements
|
||||
MergeCells.Append(MergeCell);
|
||||
}
|
||||
|
||||
protected override void SaveExcel(ExcelInfo Info)
|
||||
protected override void SaveExcel(IDocumentInfo Info)
|
||||
{
|
||||
if (_spreadsheetDocument == null)
|
||||
return;
|
||||
|
||||
@@ -33,7 +33,7 @@ namespace AutoWorkshopBusinessLogic.OfficePackage.Implements
|
||||
Style.Font.Bold = true;
|
||||
}
|
||||
|
||||
protected override void CreatePdf(PdfInfo Info)
|
||||
protected override void CreatePdf(IDocumentInfo Info)
|
||||
{
|
||||
_document = new Document();
|
||||
DefineStyles(_document);
|
||||
@@ -94,7 +94,7 @@ namespace AutoWorkshopBusinessLogic.OfficePackage.Implements
|
||||
}
|
||||
}
|
||||
|
||||
protected override void SavePdf(PdfInfo Info)
|
||||
protected override void SavePdf(IDocumentInfo Info)
|
||||
{
|
||||
var Renderer = new PdfDocumentRenderer(true)
|
||||
{
|
||||
|
||||
@@ -64,7 +64,7 @@ namespace AutoWorkshopBusinessLogic.OfficePackage.Implements
|
||||
return Properties;
|
||||
}
|
||||
|
||||
protected override void CreateWord(WordInfo Info)
|
||||
protected override void CreateWord(IDocumentInfo Info)
|
||||
{
|
||||
_wordDocument = WordprocessingDocument.Create(Info.FileName, WordprocessingDocumentType.Document);
|
||||
MainDocumentPart mainPart = _wordDocument.AddMainDocumentPart();
|
||||
@@ -103,7 +103,7 @@ namespace AutoWorkshopBusinessLogic.OfficePackage.Implements
|
||||
_docBody.AppendChild(DocParagraph);
|
||||
}
|
||||
|
||||
protected override void SaveWord(WordInfo Info)
|
||||
protected override void SaveWord(IDocumentInfo Info)
|
||||
{
|
||||
if (_docBody == null || _wordDocument == null)
|
||||
{
|
||||
@@ -114,5 +114,79 @@ namespace AutoWorkshopBusinessLogic.OfficePackage.Implements
|
||||
_wordDocument.MainDocumentPart!.Document.Save();
|
||||
_wordDocument.Close();
|
||||
}
|
||||
|
||||
private Table? _lastTable;
|
||||
|
||||
protected override void CreateTable(List<string> Columns)
|
||||
{
|
||||
if (_docBody == null)
|
||||
return;
|
||||
|
||||
_lastTable = new Table();
|
||||
|
||||
var TableProp = new TableProperties();
|
||||
TableProp.AppendChild(new TableLayout { Type = TableLayoutValues.Fixed });
|
||||
TableProp.AppendChild(new TableBorders(
|
||||
new TopBorder() { Val = new EnumValue<BorderValues>(BorderValues.Single), Size = 4 },
|
||||
new LeftBorder() { Val = new EnumValue<BorderValues>(BorderValues.Single), Size = 4 },
|
||||
new RightBorder() { Val = new EnumValue<BorderValues>(BorderValues.Single), Size = 4 },
|
||||
new BottomBorder() { Val = new EnumValue<BorderValues>(BorderValues.Single), Size = 4 },
|
||||
new InsideHorizontalBorder() { Val = new EnumValue<BorderValues>(BorderValues.Single), Size = 4 },
|
||||
new InsideVerticalBorder() { Val = new EnumValue<BorderValues>(BorderValues.Single), Size = 4 }
|
||||
));
|
||||
TableProp.AppendChild(new TableWidth { Type = TableWidthUnitValues.Auto });
|
||||
_lastTable.AppendChild(TableProp);
|
||||
|
||||
TableGrid TableGrid = new TableGrid();
|
||||
|
||||
foreach (var Column in Columns)
|
||||
{
|
||||
TableGrid.AppendChild(new GridColumn() { Width = Column });
|
||||
}
|
||||
|
||||
_lastTable.AppendChild(TableGrid);
|
||||
_docBody.AppendChild(_lastTable);
|
||||
}
|
||||
|
||||
protected override void CreateRow(WordRowParameters RowParameters)
|
||||
{
|
||||
if (_docBody == null || _lastTable == null)
|
||||
return;
|
||||
|
||||
TableRow DocRow = new TableRow();
|
||||
foreach (var Column in RowParameters.Texts)
|
||||
{
|
||||
var DocParagraph = new Paragraph();
|
||||
WordParagraph Paragraph = new WordParagraph
|
||||
{
|
||||
Texts = new List<(string, WordTextProperties)> { (Column, RowParameters.TextProperties) },
|
||||
TextProperties = RowParameters.TextProperties
|
||||
};
|
||||
|
||||
DocParagraph.AppendChild(CreateParagraphProperties(Paragraph.TextProperties));
|
||||
|
||||
foreach (var Run in Paragraph.Texts)
|
||||
{
|
||||
var DocRun = new Run();
|
||||
var Properties = new RunProperties();
|
||||
|
||||
Properties.AppendChild(new FontSize { Val = Run.Item2.Size });
|
||||
if (Run.Item2.Bold)
|
||||
{
|
||||
Properties.AppendChild(new Bold());
|
||||
}
|
||||
DocRun.AppendChild(Properties);
|
||||
DocRun.AppendChild(new Text { Text = Run.Item1, Space = SpaceProcessingModeValues.Preserve });
|
||||
DocParagraph.AppendChild(DocRun);
|
||||
}
|
||||
|
||||
TableCell docCell = new TableCell();
|
||||
|
||||
docCell.AppendChild(DocParagraph);
|
||||
DocRow.AppendChild(docCell);
|
||||
}
|
||||
|
||||
_lastTable.AppendChild(DocRow);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
using AutoWorkshopDataModels.Models;
|
||||
|
||||
namespace AutoWorkshopContracts.BindingModels
|
||||
{
|
||||
public class ImplementerBindingModel : IImplementerModel
|
||||
{
|
||||
public int Id { get; set; }
|
||||
|
||||
public string ImplementerFIO { get; set; } = string.Empty;
|
||||
|
||||
public string Password { get; set; } = string.Empty;
|
||||
|
||||
public int WorkExperience { get; set; }
|
||||
|
||||
public int Qualification { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -8,6 +8,7 @@ namespace AutoWorkshopContracts.BindingModels
|
||||
public int Id { get; set; }
|
||||
public int RepairId { get; set; }
|
||||
public int ClientId { get; set; }
|
||||
public int? ImplementerId { get; set; }
|
||||
public int Count { get; set; }
|
||||
public double Sum { get; set; }
|
||||
public OrderStatus Status { get; set; } = OrderStatus.Undefined;
|
||||
|
||||
19
AutoWorkshopContracts/BindingModels/ShopBindingModel.cs
Normal file
19
AutoWorkshopContracts/BindingModels/ShopBindingModel.cs
Normal file
@@ -0,0 +1,19 @@
|
||||
using AutoWorkshopDataModels.Models;
|
||||
|
||||
namespace AutoWorkshopContracts.BindingModels
|
||||
{
|
||||
public class ShopBindingModel : IShopModel
|
||||
{
|
||||
public int Id { get; set; }
|
||||
|
||||
public string ShopName { get; set; } = string.Empty;
|
||||
|
||||
public string Address { get; set; } = string.Empty;
|
||||
|
||||
public DateTime OpeningDate { get; set; } = DateTime.Now;
|
||||
|
||||
public Dictionary<int, (IRepairModel, int)> ShopRepairs { get; set; } = new();
|
||||
|
||||
public int RepairsMaxCount { get; set; }
|
||||
}
|
||||
}
|
||||
13
AutoWorkshopContracts/BindingModels/SupplyBindingModel.cs
Normal file
13
AutoWorkshopContracts/BindingModels/SupplyBindingModel.cs
Normal file
@@ -0,0 +1,13 @@
|
||||
using AutoWorkshopDataModels.Models;
|
||||
|
||||
namespace AutoWorkshopContracts.BindingModels
|
||||
{
|
||||
public class SupplyBindingModel : ISupplyModel
|
||||
{
|
||||
public int ShopId { get; set; }
|
||||
|
||||
public int RepairId { get; set; }
|
||||
|
||||
public int Count { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
using AutoWorkshopContracts.BindingModels;
|
||||
using AutoWorkshopContracts.SearchModels;
|
||||
using AutoWorkshopContracts.ViewModels;
|
||||
|
||||
namespace AutoWorkshopContracts.BusinessLogicsContracts
|
||||
{
|
||||
public interface IImplementerLogic
|
||||
{
|
||||
List<ImplementerViewModel>? ReadList(ImplementerSearchModel? Model);
|
||||
|
||||
ImplementerViewModel? ReadElement(ImplementerSearchModel Model);
|
||||
|
||||
bool Create(ImplementerBindingModel Model);
|
||||
|
||||
bool Update(ImplementerBindingModel Model);
|
||||
|
||||
bool Delete(ImplementerBindingModel Model);
|
||||
}
|
||||
}
|
||||
@@ -11,5 +11,6 @@ namespace AutoWorkshopContracts.BusinessLogicContracts
|
||||
bool TakeOrderInWork(OrderBindingModel Model);
|
||||
bool FinishOrder(OrderBindingModel Model);
|
||||
bool DeliveryOrder(OrderBindingModel Model);
|
||||
OrderViewModel? ReadElement(OrderSearchModel Model);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,11 +8,21 @@ namespace AutoWorkshopContracts.BusinessLogicContracts
|
||||
List<ReportRepairComponentViewModel> GetRepairComponents();
|
||||
|
||||
List<ReportOrdersViewModel> GetOrders(ReportBindingModel Model);
|
||||
|
||||
|
||||
List<ReportShopsViewModel> GetShops();
|
||||
|
||||
List<ReportGroupedOrdersViewModel> GetGroupedOrders();
|
||||
|
||||
void SaveRepairsToWordFile(ReportBindingModel Model);
|
||||
|
||||
void SaveRepairComponentToExcelFile(ReportBindingModel Model);
|
||||
|
||||
void SaveOrdersToPdfFile(ReportBindingModel Model);
|
||||
|
||||
void SaveShopsToWordFile(ReportBindingModel Model);
|
||||
|
||||
void SaveShopsToExcelFile(ReportBindingModel Model);
|
||||
|
||||
void SaveGroupedOrdersToPdfFile(ReportBindingModel Model);
|
||||
}
|
||||
}
|
||||
|
||||
23
AutoWorkshopContracts/BusinessLogicContracts/IShopLogic.cs
Normal file
23
AutoWorkshopContracts/BusinessLogicContracts/IShopLogic.cs
Normal file
@@ -0,0 +1,23 @@
|
||||
using AutoWorkshopContracts.BindingModels;
|
||||
using AutoWorkshopContracts.SearchModels;
|
||||
using AutoWorkshopContracts.ViewModels;
|
||||
|
||||
namespace AutoWorkshopContracts.BusinessLogicsContracts
|
||||
{
|
||||
public interface IShopLogic
|
||||
{
|
||||
List<ShopViewModel>? ReadList(ShopSearchModel? Model);
|
||||
|
||||
ShopViewModel? ReadElement(ShopSearchModel Model);
|
||||
|
||||
bool Create(ShopBindingModel Model);
|
||||
|
||||
bool Update(ShopBindingModel Model);
|
||||
|
||||
bool Delete(ShopBindingModel Model);
|
||||
|
||||
bool MakeSupply(SupplyBindingModel Model);
|
||||
|
||||
bool MakeSell(SupplySearchModel Model);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
using AutoWorkshopContracts.BusinessLogicsContracts;
|
||||
|
||||
namespace AutoWorkshopContracts.BusinessLogicContracts
|
||||
{
|
||||
public interface IWorkProcess
|
||||
{
|
||||
void DoWork(IImplementerLogic ImplementerLogic, IOrderLogic OrderLogic);
|
||||
}
|
||||
}
|
||||
11
AutoWorkshopContracts/SearchModels/ImplementerSearchModel.cs
Normal file
11
AutoWorkshopContracts/SearchModels/ImplementerSearchModel.cs
Normal file
@@ -0,0 +1,11 @@
|
||||
namespace AutoWorkshopContracts.SearchModels
|
||||
{
|
||||
public class ImplementerSearchModel
|
||||
{
|
||||
public int? Id { get; set; }
|
||||
|
||||
public string? ImplementerFIO { get; set; }
|
||||
|
||||
public string? Password { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,6 @@
|
||||
namespace AutoWorkshopContracts.SearchModels
|
||||
using AutoWorkshopDataModels.Enums;
|
||||
|
||||
namespace AutoWorkshopContracts.SearchModels
|
||||
{
|
||||
public class OrderSearchModel
|
||||
{
|
||||
@@ -6,6 +8,10 @@
|
||||
|
||||
public int? ClientId { get; set; }
|
||||
|
||||
public OrderStatus? Status { get; set; }
|
||||
|
||||
public int? ImplementerId { get; set; }
|
||||
|
||||
public DateTime? DateFrom { get; set; }
|
||||
|
||||
public DateTime? DateTo { get; set; }
|
||||
|
||||
9
AutoWorkshopContracts/SearchModels/ShopSearchModel.cs
Normal file
9
AutoWorkshopContracts/SearchModels/ShopSearchModel.cs
Normal file
@@ -0,0 +1,9 @@
|
||||
namespace AutoWorkshopContracts.SearchModels
|
||||
{
|
||||
public class ShopSearchModel
|
||||
{
|
||||
public int? Id { get; set; }
|
||||
|
||||
public string? ShopName { get; set; }
|
||||
}
|
||||
}
|
||||
9
AutoWorkshopContracts/SearchModels/SupplySearchModel.cs
Normal file
9
AutoWorkshopContracts/SearchModels/SupplySearchModel.cs
Normal file
@@ -0,0 +1,9 @@
|
||||
namespace AutoWorkshopContracts.SearchModels
|
||||
{
|
||||
public class SupplySearchModel
|
||||
{
|
||||
public int? RepairId { get; set; }
|
||||
|
||||
public int? Count { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
using AutoWorkshopContracts.BindingModels;
|
||||
using AutoWorkshopContracts.SearchModels;
|
||||
using AutoWorkshopContracts.ViewModels;
|
||||
|
||||
namespace AutoWorkshopContracts.StoragesContracts
|
||||
{
|
||||
public interface IImplementerStorage
|
||||
{
|
||||
List<ImplementerViewModel> GetFullList();
|
||||
|
||||
List<ImplementerViewModel> GetFilteredList(ImplementerSearchModel Model);
|
||||
|
||||
ImplementerViewModel? GetElement(ImplementerSearchModel Model);
|
||||
|
||||
ImplementerViewModel? Insert(ImplementerBindingModel Model);
|
||||
|
||||
ImplementerViewModel? Update(ImplementerBindingModel Model);
|
||||
|
||||
ImplementerViewModel? Delete(ImplementerBindingModel Model);
|
||||
}
|
||||
}
|
||||
25
AutoWorkshopContracts/StoragesContracts/IShopStorage.cs
Normal file
25
AutoWorkshopContracts/StoragesContracts/IShopStorage.cs
Normal file
@@ -0,0 +1,25 @@
|
||||
using AutoWorkshopContracts.BindingModels;
|
||||
using AutoWorkshopContracts.SearchModels;
|
||||
using AutoWorkshopContracts.ViewModels;
|
||||
|
||||
namespace AutoWorkshopContracts.StoragesContracts
|
||||
{
|
||||
public interface IShopStorage
|
||||
{
|
||||
List<ShopViewModel> GetFullList();
|
||||
|
||||
List<ShopViewModel> GetFilteredList(ShopSearchModel Model);
|
||||
|
||||
ShopViewModel? GetElement(ShopSearchModel Model);
|
||||
|
||||
ShopViewModel? Insert(ShopBindingModel Model);
|
||||
|
||||
ShopViewModel? Update(ShopBindingModel Model);
|
||||
|
||||
ShopViewModel? Delete(ShopBindingModel Model);
|
||||
|
||||
bool Sell(SupplySearchModel Model);
|
||||
|
||||
bool RestockingShops(SupplyBindingModel Model);
|
||||
}
|
||||
}
|
||||
22
AutoWorkshopContracts/ViewModels/ImplementerViewModel.cs
Normal file
22
AutoWorkshopContracts/ViewModels/ImplementerViewModel.cs
Normal file
@@ -0,0 +1,22 @@
|
||||
using AutoWorkshopDataModels.Models;
|
||||
using System.ComponentModel;
|
||||
|
||||
namespace AutoWorkshopContracts.ViewModels
|
||||
{
|
||||
public class ImplementerViewModel : IImplementerModel
|
||||
{
|
||||
public int Id { get; set; }
|
||||
|
||||
[DisplayName("ФИО исполнителя")]
|
||||
public string ImplementerFIO { get; set; } = string.Empty;
|
||||
|
||||
[DisplayName("Пароль")]
|
||||
public string Password { get; set; } = string.Empty;
|
||||
|
||||
[DisplayName("Стаж работы")]
|
||||
public int WorkExperience { get; set; }
|
||||
|
||||
[DisplayName("Квалификация")]
|
||||
public int Qualification { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -19,6 +19,11 @@ namespace AutoWorkshopContracts.ViewModels
|
||||
[DisplayName("Клиент")]
|
||||
public string ClientFIO { get; set; } = string.Empty;
|
||||
|
||||
public int? ImplementerId { get; set; }
|
||||
|
||||
[DisplayName("Исполнитель")]
|
||||
public string? ImplementerFIO { get; set; }
|
||||
|
||||
[DisplayName("Количество")]
|
||||
public int Count { get; set; }
|
||||
|
||||
|
||||
9
AutoWorkshopContracts/ViewModels/RepairCount.cs
Normal file
9
AutoWorkshopContracts/ViewModels/RepairCount.cs
Normal file
@@ -0,0 +1,9 @@
|
||||
namespace AutoWorkshopContracts.ViewModels
|
||||
{
|
||||
public class RepairCount
|
||||
{
|
||||
public RepairViewModel Repair { get; set; } = new();
|
||||
|
||||
public int Count { get; set; } = new();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
namespace AutoWorkshopContracts.ViewModels
|
||||
{
|
||||
public class ReportGroupedOrdersViewModel
|
||||
{
|
||||
public DateTime Date { get; set; } = DateTime.Now;
|
||||
|
||||
public int OrdersCount { get; set; }
|
||||
|
||||
public double OrdersSum { get; set; }
|
||||
}
|
||||
}
|
||||
11
AutoWorkshopContracts/ViewModels/ReportShopsViewModel.cs
Normal file
11
AutoWorkshopContracts/ViewModels/ReportShopsViewModel.cs
Normal file
@@ -0,0 +1,11 @@
|
||||
namespace AutoWorkshopContracts.ViewModels
|
||||
{
|
||||
public class ReportShopsViewModel
|
||||
{
|
||||
public string ShopName { get; set; } = string.Empty;
|
||||
|
||||
public int TotalCount { get; set; }
|
||||
|
||||
public List<(string Repair, int Count)> Repairs { get; set; } = new();
|
||||
}
|
||||
}
|
||||
9
AutoWorkshopContracts/ViewModels/ShopRepairsViewModel.cs
Normal file
9
AutoWorkshopContracts/ViewModels/ShopRepairsViewModel.cs
Normal file
@@ -0,0 +1,9 @@
|
||||
namespace AutoWorkshopContracts.ViewModels
|
||||
{
|
||||
public class ShopRepairsViewModel
|
||||
{
|
||||
public ShopViewModel Shop { get; set; } = new();
|
||||
|
||||
public Dictionary<int, RepairCount> ShopRepairs { get; set; } = new();
|
||||
}
|
||||
}
|
||||
24
AutoWorkshopContracts/ViewModels/ShopViewModel.cs
Normal file
24
AutoWorkshopContracts/ViewModels/ShopViewModel.cs
Normal file
@@ -0,0 +1,24 @@
|
||||
using AutoWorkshopDataModels.Models;
|
||||
using System.ComponentModel;
|
||||
|
||||
namespace AutoWorkshopContracts.ViewModels
|
||||
{
|
||||
public class ShopViewModel : IShopModel
|
||||
{
|
||||
public int Id { get; set; }
|
||||
|
||||
[DisplayName("Название")]
|
||||
public string ShopName { get; set; } = string.Empty;
|
||||
|
||||
[DisplayName("Адрес")]
|
||||
public string Address { get; set; } = string.Empty;
|
||||
|
||||
[DisplayName("Дата открытия")]
|
||||
public DateTime OpeningDate { get; set; }
|
||||
|
||||
public Dictionary<int, (IRepairModel, int)> ShopRepairs { get; set; } = new();
|
||||
|
||||
[DisplayName("Вместимость")]
|
||||
public int RepairsMaxCount { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -7,5 +7,6 @@
|
||||
BeingProcessed,
|
||||
Ready,
|
||||
Delivered,
|
||||
Waiting,
|
||||
}
|
||||
}
|
||||
|
||||
13
AutoWorkshopDataModels/Models/IImplementerModel.cs
Normal file
13
AutoWorkshopDataModels/Models/IImplementerModel.cs
Normal file
@@ -0,0 +1,13 @@
|
||||
namespace AutoWorkshopDataModels.Models
|
||||
{
|
||||
public interface IImplementerModel : IId
|
||||
{
|
||||
string ImplementerFIO { get; }
|
||||
|
||||
string Password { get; }
|
||||
|
||||
int WorkExperience { get; }
|
||||
|
||||
int Qualification { get; }
|
||||
}
|
||||
}
|
||||
@@ -6,6 +6,7 @@ namespace AutoWorkshopDataModels.Models
|
||||
{
|
||||
int RepairId { get; }
|
||||
int ClientId { get; }
|
||||
int? ImplementerId { get; }
|
||||
int Count { get; }
|
||||
double Sum { get; }
|
||||
OrderStatus Status { get; }
|
||||
|
||||
15
AutoWorkshopDataModels/Models/IShopModel.cs
Normal file
15
AutoWorkshopDataModels/Models/IShopModel.cs
Normal file
@@ -0,0 +1,15 @@
|
||||
namespace AutoWorkshopDataModels.Models
|
||||
{
|
||||
public interface IShopModel : IId
|
||||
{
|
||||
string ShopName { get; }
|
||||
|
||||
string Address { get; }
|
||||
|
||||
DateTime OpeningDate { get; }
|
||||
|
||||
Dictionary<int, (IRepairModel, int)> ShopRepairs { get; }
|
||||
|
||||
int RepairsMaxCount { get; }
|
||||
}
|
||||
}
|
||||
11
AutoWorkshopDataModels/Models/ISupplyModel.cs
Normal file
11
AutoWorkshopDataModels/Models/ISupplyModel.cs
Normal file
@@ -0,0 +1,11 @@
|
||||
namespace AutoWorkshopDataModels.Models
|
||||
{
|
||||
public interface ISupplyModel
|
||||
{
|
||||
int ShopId { get; }
|
||||
|
||||
int RepairId { get; }
|
||||
|
||||
int Count { get; }
|
||||
}
|
||||
}
|
||||
@@ -9,7 +9,7 @@ namespace AutoWorkshopDatabaseImplement
|
||||
{
|
||||
if (OptionsBuilder.IsConfigured == false)
|
||||
{
|
||||
OptionsBuilder.UseNpgsql(@"Host=localhost;Database=AutoWorkshop;Username=postgres;Password=admin");
|
||||
OptionsBuilder.UseNpgsql(@"Host=localhost;Port=5000;Database=AutoWorkshop_Hard;Username=postgres;Password=admin");
|
||||
}
|
||||
|
||||
base.OnConfiguring(OptionsBuilder);
|
||||
@@ -26,6 +26,12 @@ namespace AutoWorkshopDatabaseImplement
|
||||
|
||||
public virtual DbSet<Order> Orders { set; get; }
|
||||
|
||||
public virtual DbSet<Shop> Shops { get; set; }
|
||||
|
||||
public virtual DbSet<ShopRepair> ShopRepairs { get; set; }
|
||||
|
||||
public virtual DbSet<Client> Clients { set; get; }
|
||||
|
||||
public virtual DbSet<Implementer> Implementers { set; get; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,90 @@
|
||||
using AutoWorkshopContracts.BindingModels;
|
||||
using AutoWorkshopContracts.SearchModels;
|
||||
using AutoWorkshopContracts.StoragesContracts;
|
||||
using AutoWorkshopContracts.ViewModels;
|
||||
using AutoWorkshopDatabaseImplement.Models;
|
||||
|
||||
namespace AutoWorkshopDatabaseImplement.Implements
|
||||
{
|
||||
public class ImplementerStorage : IImplementerStorage
|
||||
{
|
||||
public List<ImplementerViewModel> GetFullList()
|
||||
{
|
||||
using var Context = new AutoWorkshopDatabase();
|
||||
|
||||
return Context.Implementers.Select(x => x.GetViewModel).ToList();
|
||||
}
|
||||
|
||||
public List<ImplementerViewModel> GetFilteredList(ImplementerSearchModel Model)
|
||||
{
|
||||
if (string.IsNullOrEmpty(Model.ImplementerFIO))
|
||||
{
|
||||
return new();
|
||||
}
|
||||
using var Context = new AutoWorkshopDatabase();
|
||||
return Context.Implementers.Where(x => x.ImplementerFIO.Contains(Model.ImplementerFIO)).Select(x => x.GetViewModel).ToList();
|
||||
}
|
||||
|
||||
public ImplementerViewModel? GetElement(ImplementerSearchModel Model)
|
||||
{
|
||||
if (string.IsNullOrEmpty(Model.ImplementerFIO) && !Model.Id.HasValue)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
using var Context = new AutoWorkshopDatabase();
|
||||
|
||||
return Context.Implementers.FirstOrDefault(x =>
|
||||
(!string.IsNullOrEmpty(Model.ImplementerFIO) && x.ImplementerFIO == Model.ImplementerFIO && (!string.IsNullOrEmpty(Model.Password) ? x.Password == Model.Password : true)) ||
|
||||
(Model.Id.HasValue && x.Id == Model.Id))
|
||||
?.GetViewModel;
|
||||
}
|
||||
|
||||
public ImplementerViewModel? Insert(ImplementerBindingModel Model)
|
||||
{
|
||||
var NewImplementer = Implementer.Create(Model);
|
||||
if (NewImplementer == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
using var Context = new AutoWorkshopDatabase();
|
||||
|
||||
Context.Implementers.Add(NewImplementer);
|
||||
Context.SaveChanges();
|
||||
|
||||
return NewImplementer.GetViewModel;
|
||||
}
|
||||
|
||||
public ImplementerViewModel? Update(ImplementerBindingModel Model)
|
||||
{
|
||||
using var Context = new AutoWorkshopDatabase();
|
||||
|
||||
var Implementer = Context.Implementers.FirstOrDefault(x => x.Id == Model.Id);
|
||||
if (Implementer == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
Implementer.Update(Model);
|
||||
Context.SaveChanges();
|
||||
|
||||
return Implementer.GetViewModel;
|
||||
}
|
||||
|
||||
public ImplementerViewModel? Delete(ImplementerBindingModel Model)
|
||||
{
|
||||
using var Context = new AutoWorkshopDatabase();
|
||||
|
||||
var Implementer = Context.Implementers.FirstOrDefault(rec => rec.Id == Model.Id);
|
||||
if (Implementer == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
Context.Implementers.Remove(Implementer);
|
||||
Context.SaveChanges();
|
||||
|
||||
return Implementer.GetViewModel;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -16,6 +16,7 @@ namespace AutoWorkshopDatabaseImplement.Implements
|
||||
return Context.Orders
|
||||
.Include(x => x.Repair)
|
||||
.Include(x => x.Client)
|
||||
.Include(x => x.Implementer)
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
@@ -29,6 +30,7 @@ namespace AutoWorkshopDatabaseImplement.Implements
|
||||
return Context.Orders
|
||||
.Include(x => x.Repair)
|
||||
.Include(x => x.Client)
|
||||
.Include(x => x.Implementer)
|
||||
.Where(x => (x.DateCreate >= Model.DateFrom && x.DateCreate <= Model.DateTo) && (!Model.ClientId.HasValue || x.ClientId == Model.ClientId))
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
@@ -37,14 +39,18 @@ namespace AutoWorkshopDatabaseImplement.Implements
|
||||
return Context.Orders
|
||||
.Include(x => x.Repair)
|
||||
.Include(x => x.Client)
|
||||
.Where(x => (Model.Id.HasValue && x.Id == Model.Id) || (Model.ClientId.HasValue && x.ClientId == Model.ClientId))
|
||||
.Include (x => x.Implementer)
|
||||
.Where(x => (Model.Id.HasValue && x.Id == Model.Id)
|
||||
|| (Model.ClientId.HasValue && x.ClientId == Model.ClientId)
|
||||
|| (Model.ImplementerId.HasValue && x.ImplementerId == Model.ImplementerId)
|
||||
|| (Model.Status.HasValue && x.Status == Model.Status))
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public OrderViewModel? GetElement(OrderSearchModel Model)
|
||||
{
|
||||
if (!Model.Id.HasValue)
|
||||
if (!Model.Id.HasValue && !Model.ImplementerId.HasValue && !Model.Status.HasValue)
|
||||
return null;
|
||||
|
||||
using var Context = new AutoWorkshopDatabase();
|
||||
@@ -52,7 +58,9 @@ namespace AutoWorkshopDatabaseImplement.Implements
|
||||
return Context.Orders
|
||||
.Include(x => x.Repair)
|
||||
.Include(x => x.Client)
|
||||
.FirstOrDefault(x => Model.Id.HasValue && x.Id == Model.Id)?
|
||||
.Include(x => x.Implementer)
|
||||
.FirstOrDefault(x => (Model.Id.HasValue && x.Id == Model.Id)
|
||||
|| (Model.ImplementerId.HasValue && Model.Status.HasValue && x.ImplementerId == Model.ImplementerId && x.Status == Model.Status) )?
|
||||
.GetViewModel;
|
||||
}
|
||||
|
||||
@@ -70,7 +78,7 @@ namespace AutoWorkshopDatabaseImplement.Implements
|
||||
Context.Orders.Add(NewOrder);
|
||||
Context.SaveChanges();
|
||||
|
||||
return Context.Orders.Include(x => x.Repair).Include(x => x.Client).FirstOrDefault(x => x.Id == NewOrder.Id)?.GetViewModel;
|
||||
return Context.Orders.Include(x => x.Repair).Include(x => x.Client).Include(x => x.Implementer).FirstOrDefault(x => x.Id == NewOrder.Id)?.GetViewModel;
|
||||
}
|
||||
|
||||
public OrderViewModel? Update(OrderBindingModel Model)
|
||||
@@ -84,13 +92,13 @@ namespace AutoWorkshopDatabaseImplement.Implements
|
||||
Order.Update(Model);
|
||||
Context.SaveChanges();
|
||||
|
||||
return Context.Orders.Include(x => x.Repair).Include(x => x.Client).FirstOrDefault(x => x.Id == Model.Id)?.GetViewModel;
|
||||
return Context.Orders.Include(x => x.Repair).Include(x => x.Client).Include(x => x.Implementer).FirstOrDefault(x => x.Id == Model.Id)?.GetViewModel;
|
||||
}
|
||||
|
||||
public OrderViewModel? Delete(OrderBindingModel Model)
|
||||
{
|
||||
using var Context = new AutoWorkshopDatabase();
|
||||
var Order = Context.Orders.Include(x => x.Repair).Include(x => x.Client).FirstOrDefault(rec => rec.Id == Model.Id);
|
||||
var Order = Context.Orders.Include(x => x.Repair).Include(x => x.Client).Include(x => x.Implementer).FirstOrDefault(rec => rec.Id == Model.Id);
|
||||
|
||||
if (Order == null)
|
||||
return null;
|
||||
|
||||
221
AutoWorkshopDatabaseImplement/Implements/ShopStorage.cs
Normal file
221
AutoWorkshopDatabaseImplement/Implements/ShopStorage.cs
Normal file
@@ -0,0 +1,221 @@
|
||||
using AutoWorkshopContracts.BindingModels;
|
||||
using AutoWorkshopContracts.SearchModels;
|
||||
using AutoWorkshopContracts.StoragesContracts;
|
||||
using AutoWorkshopContracts.ViewModels;
|
||||
using AutoWorkshopDatabaseImplement.Models;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace AutoWorkshopDatabaseImplement.Implements
|
||||
{
|
||||
public class ShopStorage : IShopStorage
|
||||
{
|
||||
public List<ShopViewModel> GetFullList()
|
||||
{
|
||||
using var Context = new AutoWorkshopDatabase();
|
||||
return Context.Shops
|
||||
.Include(x => x.Repairs)
|
||||
.ThenInclude(x => x.Repair)
|
||||
.ToList()
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public List<ShopViewModel> GetFilteredList(ShopSearchModel Model)
|
||||
{
|
||||
if (string.IsNullOrEmpty(Model.ShopName))
|
||||
return new();
|
||||
|
||||
using var Context = new AutoWorkshopDatabase();
|
||||
|
||||
return Context.Shops
|
||||
.Include(x => x.Repairs)
|
||||
.ThenInclude(x => x.Repair)
|
||||
.Where(x => x.ShopName.Contains(Model.ShopName))
|
||||
.ToList()
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public ShopViewModel? GetElement(ShopSearchModel Model)
|
||||
{
|
||||
if (string.IsNullOrEmpty(Model.ShopName) && !Model.Id.HasValue)
|
||||
return new();
|
||||
|
||||
using var Context = new AutoWorkshopDatabase();
|
||||
|
||||
return Context.Shops
|
||||
.Include(x => x.Repairs)
|
||||
.ThenInclude(x => x.Repair)
|
||||
.FirstOrDefault(x => (!string.IsNullOrEmpty(Model.ShopName) && x.ShopName == Model.ShopName) ||
|
||||
(Model.Id.HasValue && x.Id == Model.Id))?
|
||||
.GetViewModel;
|
||||
}
|
||||
|
||||
public ShopViewModel? Insert(ShopBindingModel Model)
|
||||
{
|
||||
using var Context = new AutoWorkshopDatabase();
|
||||
|
||||
var NewShop = Shop.Create(Context, Model);
|
||||
if (NewShop == null)
|
||||
return null;
|
||||
|
||||
Context.Shops.Add(NewShop);
|
||||
Context.SaveChanges();
|
||||
|
||||
return NewShop.GetViewModel;
|
||||
}
|
||||
|
||||
public ShopViewModel? Update(ShopBindingModel Model)
|
||||
{
|
||||
using var Context = new AutoWorkshopDatabase();
|
||||
|
||||
using var Transaction = Context.Database.BeginTransaction();
|
||||
try
|
||||
{
|
||||
var Shop = Context.Shops.FirstOrDefault(x => x.Id == Model.Id);
|
||||
|
||||
if (Shop == null)
|
||||
return null;
|
||||
|
||||
Shop.Update(Model);
|
||||
Context.SaveChanges();
|
||||
Shop.UpdateRepairs(Context, Model);
|
||||
|
||||
Transaction.Commit();
|
||||
return Shop.GetViewModel;
|
||||
}
|
||||
catch
|
||||
{
|
||||
Transaction.Rollback();
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
public ShopViewModel? Delete(ShopBindingModel Model)
|
||||
{
|
||||
using var Context = new AutoWorkshopDatabase();
|
||||
|
||||
var Shop = Context.Shops
|
||||
.Include(x => x.Repairs)
|
||||
.FirstOrDefault(x => x.Id == Model.Id);
|
||||
|
||||
if (Shop == null)
|
||||
return null;
|
||||
|
||||
Context.Shops.Remove(Shop);
|
||||
Context.SaveChanges();
|
||||
|
||||
return Shop.GetViewModel;
|
||||
}
|
||||
|
||||
public bool Sell(SupplySearchModel Model)
|
||||
{
|
||||
using var Context = new AutoWorkshopDatabase();
|
||||
var Transaction = Context.Database.BeginTransaction();
|
||||
|
||||
try
|
||||
{
|
||||
var ShopsWithDesiredRepair = Context.Shops
|
||||
.Include(x => x.Repairs)
|
||||
.ThenInclude(x => x.Repair)
|
||||
.ToList()
|
||||
.Where(x => x.ShopRepairs.ContainsKey(Model.RepairId.Value))
|
||||
.OrderByDescending(x => x.ShopRepairs[Model.RepairId.Value].Item2)
|
||||
.ToList();
|
||||
|
||||
foreach (var Shop in ShopsWithDesiredRepair)
|
||||
{
|
||||
int Slack = Model.Count.Value - Shop.ShopRepairs[Model.RepairId.Value].Item2;
|
||||
|
||||
if (Slack > 0)
|
||||
{
|
||||
Shop.ShopRepairs.Remove(Model.RepairId.Value);
|
||||
Shop.RepairsDictionatyUpdate(Context);
|
||||
Context.SaveChanges();
|
||||
|
||||
Model.Count = Slack;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (Slack == 0)
|
||||
{
|
||||
Shop.ShopRepairs.Remove(Model.RepairId.Value);
|
||||
}
|
||||
else
|
||||
{
|
||||
var RepairAndCount = Shop.ShopRepairs[Model.RepairId.Value];
|
||||
RepairAndCount.Item2 = -Slack;
|
||||
Shop.ShopRepairs[Model.RepairId.Value] = RepairAndCount;
|
||||
}
|
||||
|
||||
Shop.RepairsDictionatyUpdate(Context);
|
||||
Transaction.Commit();
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
Transaction.Rollback();
|
||||
return false;
|
||||
}
|
||||
catch
|
||||
{
|
||||
Transaction.Rollback();
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
public bool RestockingShops(SupplyBindingModel Model)
|
||||
{
|
||||
using var Context = new AutoWorkshopDatabase();
|
||||
var Transaction = Context.Database.BeginTransaction();
|
||||
|
||||
var Shops = Context.Shops
|
||||
.Include(x => x.Repairs)
|
||||
.ThenInclude(x => x.Repair)
|
||||
.ToList()
|
||||
.Where(x => x.RepairsMaxCount > x.ShopRepairs
|
||||
.Select(x => x.Value.Item2).Sum())
|
||||
.ToList();
|
||||
|
||||
try
|
||||
{
|
||||
foreach (Shop Shop in Shops)
|
||||
{
|
||||
int FreeSpaceNum = Shop.RepairsMaxCount - Shop.ShopRepairs.Select(x => x.Value.Item2).Sum();
|
||||
|
||||
int Refill = Math.Min(FreeSpaceNum, Model.Count);
|
||||
Model.Count -= Refill;
|
||||
|
||||
if (Shop.ShopRepairs.ContainsKey(Model.RepairId))
|
||||
{
|
||||
var RepairAndCount = Shop.ShopRepairs[Model.RepairId];
|
||||
RepairAndCount.Item2 += Refill;
|
||||
Shop.ShopRepairs[Model.RepairId] = RepairAndCount;
|
||||
}
|
||||
else
|
||||
{
|
||||
var Repair = Context.Repairs.First(x => x.Id == Model.RepairId);
|
||||
Shop.ShopRepairs.Add(Model.RepairId, (Repair, Refill));
|
||||
}
|
||||
|
||||
Shop.RepairsDictionatyUpdate(Context);
|
||||
|
||||
if (Model.Count == 0)
|
||||
{
|
||||
Transaction.Commit();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
Transaction.Rollback();
|
||||
return false;
|
||||
}
|
||||
catch
|
||||
{
|
||||
Transaction.Rollback();
|
||||
throw;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -12,8 +12,8 @@ using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
|
||||
namespace AutoWorkshopDatabaseImplement.Migrations
|
||||
{
|
||||
[DbContext(typeof(AutoWorkshopDatabase))]
|
||||
[Migration("20240411091839_Clients")]
|
||||
partial class Clients
|
||||
[Migration("20240621132359_Lab6_Hard")]
|
||||
partial class Lab6_Hard
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||
@@ -70,6 +70,33 @@ namespace AutoWorkshopDatabaseImplement.Migrations
|
||||
b.ToTable("Components");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("AutoWorkshopDatabaseImplement.Models.Implementer", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<string>("ImplementerFIO")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("Password")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<int>("Qualification")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<int>("WorkExperience")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Implementers");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("AutoWorkshopDatabaseImplement.Models.Order", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
@@ -90,6 +117,9 @@ namespace AutoWorkshopDatabaseImplement.Migrations
|
||||
b.Property<DateTime?>("DateImplement")
|
||||
.HasColumnType("timestamp without time zone");
|
||||
|
||||
b.Property<int?>("ImplementerId")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<int>("RepairId")
|
||||
.HasColumnType("integer");
|
||||
|
||||
@@ -103,6 +133,8 @@ namespace AutoWorkshopDatabaseImplement.Migrations
|
||||
|
||||
b.HasIndex("ClientId");
|
||||
|
||||
b.HasIndex("ImplementerId");
|
||||
|
||||
b.HasIndex("RepairId");
|
||||
|
||||
b.ToTable("Orders");
|
||||
@@ -154,6 +186,59 @@ namespace AutoWorkshopDatabaseImplement.Migrations
|
||||
b.ToTable("RepairComponents");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("AutoWorkshopDatabaseImplement.Models.Shop", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<string>("Address")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<DateTime>("OpeningDate")
|
||||
.HasColumnType("timestamp without time zone");
|
||||
|
||||
b.Property<int>("RepairsMaxCount")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<string>("ShopName")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Shops");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("AutoWorkshopDatabaseImplement.Models.ShopRepair", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<int>("Count")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<int>("RepairId")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<int>("ShopId")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("RepairId");
|
||||
|
||||
b.HasIndex("ShopId");
|
||||
|
||||
b.ToTable("ShopRepairs");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("AutoWorkshopDatabaseImplement.Models.Order", b =>
|
||||
{
|
||||
b.HasOne("AutoWorkshopDatabaseImplement.Models.Client", "Client")
|
||||
@@ -162,6 +247,10 @@ namespace AutoWorkshopDatabaseImplement.Migrations
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("AutoWorkshopDatabaseImplement.Models.Implementer", "Implementer")
|
||||
.WithMany("Order")
|
||||
.HasForeignKey("ImplementerId");
|
||||
|
||||
b.HasOne("AutoWorkshopDatabaseImplement.Models.Repair", "Repair")
|
||||
.WithMany("Orders")
|
||||
.HasForeignKey("RepairId")
|
||||
@@ -170,6 +259,8 @@ namespace AutoWorkshopDatabaseImplement.Migrations
|
||||
|
||||
b.Navigation("Client");
|
||||
|
||||
b.Navigation("Implementer");
|
||||
|
||||
b.Navigation("Repair");
|
||||
});
|
||||
|
||||
@@ -192,6 +283,25 @@ namespace AutoWorkshopDatabaseImplement.Migrations
|
||||
b.Navigation("Repair");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("AutoWorkshopDatabaseImplement.Models.ShopRepair", b =>
|
||||
{
|
||||
b.HasOne("AutoWorkshopDatabaseImplement.Models.Repair", "Repair")
|
||||
.WithMany("Shops")
|
||||
.HasForeignKey("RepairId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("AutoWorkshopDatabaseImplement.Models.Shop", "Shop")
|
||||
.WithMany("Repairs")
|
||||
.HasForeignKey("ShopId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Repair");
|
||||
|
||||
b.Navigation("Shop");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("AutoWorkshopDatabaseImplement.Models.Client", b =>
|
||||
{
|
||||
b.Navigation("Orders");
|
||||
@@ -202,11 +312,23 @@ namespace AutoWorkshopDatabaseImplement.Migrations
|
||||
b.Navigation("RepairComponents");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("AutoWorkshopDatabaseImplement.Models.Implementer", b =>
|
||||
{
|
||||
b.Navigation("Order");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("AutoWorkshopDatabaseImplement.Models.Repair", b =>
|
||||
{
|
||||
b.Navigation("Components");
|
||||
|
||||
b.Navigation("Orders");
|
||||
|
||||
b.Navigation("Shops");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("AutoWorkshopDatabaseImplement.Models.Shop", b =>
|
||||
{
|
||||
b.Navigation("Repairs");
|
||||
});
|
||||
#pragma warning restore 612, 618
|
||||
}
|
||||
@@ -7,7 +7,7 @@ using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
|
||||
namespace AutoWorkshopDatabaseImplement.Migrations
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class Clients : Migration
|
||||
public partial class Lab6_Hard : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
@@ -41,6 +41,22 @@ namespace AutoWorkshopDatabaseImplement.Migrations
|
||||
table.PrimaryKey("PK_Components", x => x.Id);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "Implementers",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<int>(type: "integer", nullable: false)
|
||||
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
|
||||
ImplementerFIO = table.Column<string>(type: "text", nullable: false),
|
||||
Password = table.Column<string>(type: "text", nullable: false),
|
||||
WorkExperience = table.Column<int>(type: "integer", nullable: false),
|
||||
Qualification = table.Column<int>(type: "integer", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_Implementers", x => x.Id);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "Repairs",
|
||||
columns: table => new
|
||||
@@ -55,6 +71,22 @@ namespace AutoWorkshopDatabaseImplement.Migrations
|
||||
table.PrimaryKey("PK_Repairs", x => x.Id);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "Shops",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<int>(type: "integer", nullable: false)
|
||||
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
|
||||
ShopName = table.Column<string>(type: "text", nullable: false),
|
||||
Address = table.Column<string>(type: "text", nullable: false),
|
||||
OpeningDate = table.Column<DateTime>(type: "timestamp without time zone", nullable: false),
|
||||
RepairsMaxCount = table.Column<int>(type: "integer", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_Shops", x => x.Id);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "Orders",
|
||||
columns: table => new
|
||||
@@ -63,6 +95,7 @@ namespace AutoWorkshopDatabaseImplement.Migrations
|
||||
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
|
||||
RepairId = table.Column<int>(type: "integer", nullable: false),
|
||||
ClientId = table.Column<int>(type: "integer", nullable: false),
|
||||
ImplementerId = table.Column<int>(type: "integer", nullable: true),
|
||||
Count = table.Column<int>(type: "integer", nullable: false),
|
||||
Sum = table.Column<double>(type: "double precision", nullable: false),
|
||||
Status = table.Column<int>(type: "integer", nullable: false),
|
||||
@@ -78,6 +111,11 @@ namespace AutoWorkshopDatabaseImplement.Migrations
|
||||
principalTable: "Clients",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
table.ForeignKey(
|
||||
name: "FK_Orders_Implementers_ImplementerId",
|
||||
column: x => x.ImplementerId,
|
||||
principalTable: "Implementers",
|
||||
principalColumn: "Id");
|
||||
table.ForeignKey(
|
||||
name: "FK_Orders_Repairs_RepairId",
|
||||
column: x => x.RepairId,
|
||||
@@ -113,11 +151,43 @@ namespace AutoWorkshopDatabaseImplement.Migrations
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "ShopRepairs",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<int>(type: "integer", nullable: false)
|
||||
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
|
||||
RepairId = table.Column<int>(type: "integer", nullable: false),
|
||||
ShopId = table.Column<int>(type: "integer", nullable: false),
|
||||
Count = table.Column<int>(type: "integer", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_ShopRepairs", x => x.Id);
|
||||
table.ForeignKey(
|
||||
name: "FK_ShopRepairs_Repairs_RepairId",
|
||||
column: x => x.RepairId,
|
||||
principalTable: "Repairs",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
table.ForeignKey(
|
||||
name: "FK_ShopRepairs_Shops_ShopId",
|
||||
column: x => x.ShopId,
|
||||
principalTable: "Shops",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_Orders_ClientId",
|
||||
table: "Orders",
|
||||
column: "ClientId");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_Orders_ImplementerId",
|
||||
table: "Orders",
|
||||
column: "ImplementerId");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_Orders_RepairId",
|
||||
table: "Orders",
|
||||
@@ -132,6 +202,16 @@ namespace AutoWorkshopDatabaseImplement.Migrations
|
||||
name: "IX_RepairComponents_RepairId",
|
||||
table: "RepairComponents",
|
||||
column: "RepairId");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_ShopRepairs_RepairId",
|
||||
table: "ShopRepairs",
|
||||
column: "RepairId");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_ShopRepairs_ShopId",
|
||||
table: "ShopRepairs",
|
||||
column: "ShopId");
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
@@ -143,14 +223,23 @@ namespace AutoWorkshopDatabaseImplement.Migrations
|
||||
migrationBuilder.DropTable(
|
||||
name: "RepairComponents");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "ShopRepairs");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "Clients");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "Implementers");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "Components");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "Repairs");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "Shops");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -67,6 +67,33 @@ namespace AutoWorkshopDatabaseImplement.Migrations
|
||||
b.ToTable("Components");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("AutoWorkshopDatabaseImplement.Models.Implementer", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<string>("ImplementerFIO")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("Password")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<int>("Qualification")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<int>("WorkExperience")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Implementers");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("AutoWorkshopDatabaseImplement.Models.Order", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
@@ -87,6 +114,9 @@ namespace AutoWorkshopDatabaseImplement.Migrations
|
||||
b.Property<DateTime?>("DateImplement")
|
||||
.HasColumnType("timestamp without time zone");
|
||||
|
||||
b.Property<int?>("ImplementerId")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<int>("RepairId")
|
||||
.HasColumnType("integer");
|
||||
|
||||
@@ -100,6 +130,8 @@ namespace AutoWorkshopDatabaseImplement.Migrations
|
||||
|
||||
b.HasIndex("ClientId");
|
||||
|
||||
b.HasIndex("ImplementerId");
|
||||
|
||||
b.HasIndex("RepairId");
|
||||
|
||||
b.ToTable("Orders");
|
||||
@@ -151,6 +183,59 @@ namespace AutoWorkshopDatabaseImplement.Migrations
|
||||
b.ToTable("RepairComponents");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("AutoWorkshopDatabaseImplement.Models.Shop", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<string>("Address")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<DateTime>("OpeningDate")
|
||||
.HasColumnType("timestamp without time zone");
|
||||
|
||||
b.Property<int>("RepairsMaxCount")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<string>("ShopName")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Shops");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("AutoWorkshopDatabaseImplement.Models.ShopRepair", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<int>("Count")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<int>("RepairId")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<int>("ShopId")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("RepairId");
|
||||
|
||||
b.HasIndex("ShopId");
|
||||
|
||||
b.ToTable("ShopRepairs");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("AutoWorkshopDatabaseImplement.Models.Order", b =>
|
||||
{
|
||||
b.HasOne("AutoWorkshopDatabaseImplement.Models.Client", "Client")
|
||||
@@ -159,6 +244,10 @@ namespace AutoWorkshopDatabaseImplement.Migrations
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("AutoWorkshopDatabaseImplement.Models.Implementer", "Implementer")
|
||||
.WithMany("Order")
|
||||
.HasForeignKey("ImplementerId");
|
||||
|
||||
b.HasOne("AutoWorkshopDatabaseImplement.Models.Repair", "Repair")
|
||||
.WithMany("Orders")
|
||||
.HasForeignKey("RepairId")
|
||||
@@ -167,6 +256,8 @@ namespace AutoWorkshopDatabaseImplement.Migrations
|
||||
|
||||
b.Navigation("Client");
|
||||
|
||||
b.Navigation("Implementer");
|
||||
|
||||
b.Navigation("Repair");
|
||||
});
|
||||
|
||||
@@ -189,6 +280,25 @@ namespace AutoWorkshopDatabaseImplement.Migrations
|
||||
b.Navigation("Repair");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("AutoWorkshopDatabaseImplement.Models.ShopRepair", b =>
|
||||
{
|
||||
b.HasOne("AutoWorkshopDatabaseImplement.Models.Repair", "Repair")
|
||||
.WithMany("Shops")
|
||||
.HasForeignKey("RepairId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("AutoWorkshopDatabaseImplement.Models.Shop", "Shop")
|
||||
.WithMany("Repairs")
|
||||
.HasForeignKey("ShopId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Repair");
|
||||
|
||||
b.Navigation("Shop");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("AutoWorkshopDatabaseImplement.Models.Client", b =>
|
||||
{
|
||||
b.Navigation("Orders");
|
||||
@@ -199,11 +309,23 @@ namespace AutoWorkshopDatabaseImplement.Migrations
|
||||
b.Navigation("RepairComponents");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("AutoWorkshopDatabaseImplement.Models.Implementer", b =>
|
||||
{
|
||||
b.Navigation("Order");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("AutoWorkshopDatabaseImplement.Models.Repair", b =>
|
||||
{
|
||||
b.Navigation("Components");
|
||||
|
||||
b.Navigation("Orders");
|
||||
|
||||
b.Navigation("Shops");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("AutoWorkshopDatabaseImplement.Models.Shop", b =>
|
||||
{
|
||||
b.Navigation("Repairs");
|
||||
});
|
||||
#pragma warning restore 612, 618
|
||||
}
|
||||
|
||||
64
AutoWorkshopDatabaseImplement/Models/Implementer.cs
Normal file
64
AutoWorkshopDatabaseImplement/Models/Implementer.cs
Normal file
@@ -0,0 +1,64 @@
|
||||
using AutoWorkshopContracts.BindingModels;
|
||||
using AutoWorkshopContracts.ViewModels;
|
||||
using AutoWorkshopDataModels.Models;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
|
||||
namespace AutoWorkshopDatabaseImplement.Models
|
||||
{
|
||||
public class Implementer : IImplementerModel
|
||||
{
|
||||
public int Id { get; set; }
|
||||
|
||||
[Required]
|
||||
public string ImplementerFIO { get; set; } = string.Empty;
|
||||
|
||||
[Required]
|
||||
public string Password { get; set; } = string.Empty;
|
||||
|
||||
[Required]
|
||||
public int WorkExperience { get; set; }
|
||||
|
||||
[Required]
|
||||
public int Qualification { get; set; }
|
||||
|
||||
[ForeignKey("ImplementerId")]
|
||||
public virtual List<Order> Order { get; set; } = new();
|
||||
|
||||
public static Implementer? Create(ImplementerBindingModel? Model)
|
||||
{
|
||||
if (Model == null)
|
||||
return null;
|
||||
|
||||
return new Implementer()
|
||||
{
|
||||
Id = Model.Id,
|
||||
ImplementerFIO = Model.ImplementerFIO,
|
||||
Password = Model.Password,
|
||||
WorkExperience = Model.WorkExperience,
|
||||
Qualification = Model.Qualification
|
||||
};
|
||||
}
|
||||
|
||||
public void Update(ImplementerBindingModel Model)
|
||||
{
|
||||
if (Model == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
ImplementerFIO = Model.ImplementerFIO;
|
||||
Password = Model.Password;
|
||||
WorkExperience = Model.WorkExperience;
|
||||
Qualification = Model.Qualification;
|
||||
}
|
||||
|
||||
public ImplementerViewModel GetViewModel => new()
|
||||
{
|
||||
Id = Id,
|
||||
ImplementerFIO = ImplementerFIO,
|
||||
Password = Password,
|
||||
WorkExperience = WorkExperience,
|
||||
Qualification = Qualification
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -20,6 +20,10 @@ namespace AutoWorkshopDatabaseImplement.Models
|
||||
|
||||
public virtual Client Client { get; set; }
|
||||
|
||||
public int? ImplementerId { get; private set; }
|
||||
|
||||
public virtual Implementer? Implementer { get; set; }
|
||||
|
||||
[Required]
|
||||
public int Count { get; private set; }
|
||||
|
||||
@@ -44,6 +48,7 @@ namespace AutoWorkshopDatabaseImplement.Models
|
||||
Id = Model.Id,
|
||||
RepairId = Model.RepairId,
|
||||
ClientId = Model.ClientId,
|
||||
ImplementerId = Model.ImplementerId,
|
||||
Count = Model.Count,
|
||||
Sum = Model.Sum,
|
||||
Status = Model.Status,
|
||||
@@ -57,6 +62,7 @@ namespace AutoWorkshopDatabaseImplement.Models
|
||||
if (Model is null)
|
||||
return;
|
||||
|
||||
ImplementerId = Model.ImplementerId;
|
||||
Status = Model.Status;
|
||||
DateImplement = Model.DateImplement;
|
||||
}
|
||||
@@ -66,8 +72,10 @@ namespace AutoWorkshopDatabaseImplement.Models
|
||||
Id = Id,
|
||||
RepairId = RepairId,
|
||||
ClientId = ClientId,
|
||||
ImplementerId = ImplementerId,
|
||||
RepairName = Repair.RepairName,
|
||||
ClientFIO = Client.ClientFIO,
|
||||
ImplementerFIO = Implementer?.ImplementerFIO,
|
||||
Count = Count,
|
||||
Sum = Sum,
|
||||
Status = Status,
|
||||
|
||||
@@ -38,7 +38,10 @@ namespace AutoWorkshopDatabaseImplement.Models
|
||||
|
||||
[ForeignKey("RepairId")]
|
||||
public virtual List<Order> Orders { get; set; } = new();
|
||||
|
||||
|
||||
[ForeignKey("RepairId")]
|
||||
public virtual List<ShopRepair> Shops { get; set; } = new();
|
||||
|
||||
public static Repair Create(AutoWorkshopDatabase Context, RepairBindingModel Model)
|
||||
{
|
||||
return new Repair()
|
||||
|
||||
131
AutoWorkshopDatabaseImplement/Models/Shop.cs
Normal file
131
AutoWorkshopDatabaseImplement/Models/Shop.cs
Normal file
@@ -0,0 +1,131 @@
|
||||
using AutoWorkshopContracts.BindingModels;
|
||||
using AutoWorkshopContracts.ViewModels;
|
||||
using AutoWorkshopDataModels.Models;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
|
||||
namespace AutoWorkshopDatabaseImplement.Models
|
||||
{
|
||||
public class Shop : IShopModel
|
||||
{
|
||||
public int Id { get; set; }
|
||||
|
||||
[Required]
|
||||
public string ShopName { get; set; } = string.Empty;
|
||||
|
||||
[Required]
|
||||
public string Address { get; set; } = string.Empty;
|
||||
|
||||
[Required]
|
||||
public DateTime OpeningDate { get; set; }
|
||||
|
||||
[Required]
|
||||
public int RepairsMaxCount { get; set; }
|
||||
|
||||
[ForeignKey("ShopId")]
|
||||
public List<ShopRepair> Repairs { get; set; } = new();
|
||||
|
||||
private Dictionary<int, (IRepairModel, int)>? _shopRepairs = null;
|
||||
|
||||
[NotMapped]
|
||||
public Dictionary<int, (IRepairModel, int)> ShopRepairs
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_shopRepairs == null)
|
||||
{
|
||||
if (_shopRepairs == null)
|
||||
{
|
||||
_shopRepairs = Repairs.ToDictionary(ShopRep => ShopRep.RepairId, ShopRep => (ShopRep.Repair as IRepairModel, ShopRep.Count));
|
||||
}
|
||||
return _shopRepairs;
|
||||
}
|
||||
|
||||
return _shopRepairs;
|
||||
}
|
||||
}
|
||||
|
||||
public static Shop Create(AutoWorkshopDatabase Context, ShopBindingModel Model)
|
||||
{
|
||||
return new Shop()
|
||||
{
|
||||
Id = Model.Id,
|
||||
ShopName = Model.ShopName,
|
||||
Address = Model.Address,
|
||||
OpeningDate = Model.OpeningDate,
|
||||
Repairs = Model.ShopRepairs.Select(x => new ShopRepair
|
||||
{
|
||||
Repair = Context.Repairs.First(y => y.Id == x.Key),
|
||||
Count = x.Value.Item2
|
||||
}).ToList(),
|
||||
RepairsMaxCount = Model.RepairsMaxCount
|
||||
};
|
||||
}
|
||||
|
||||
public void Update(ShopBindingModel Model)
|
||||
{
|
||||
ShopName = Model.ShopName;
|
||||
Address = Model.Address;
|
||||
OpeningDate = Model.OpeningDate;
|
||||
RepairsMaxCount = Model.RepairsMaxCount;
|
||||
}
|
||||
|
||||
public ShopViewModel GetViewModel => new()
|
||||
{
|
||||
Id = Id,
|
||||
ShopName = ShopName,
|
||||
Address = Address,
|
||||
OpeningDate = OpeningDate,
|
||||
ShopRepairs = ShopRepairs,
|
||||
RepairsMaxCount = RepairsMaxCount
|
||||
};
|
||||
|
||||
public void UpdateRepairs(AutoWorkshopDatabase Context, ShopBindingModel Model)
|
||||
{
|
||||
var ShopRepairs = Context.ShopRepairs
|
||||
.Where(rec => rec.ShopId == Model.Id)
|
||||
.ToList();
|
||||
|
||||
if (ShopRepairs != null && ShopRepairs.Count > 0)
|
||||
{
|
||||
Context.ShopRepairs.RemoveRange(ShopRepairs.Where(rec => !Model.ShopRepairs.ContainsKey(rec.RepairId)));
|
||||
Context.SaveChanges();
|
||||
|
||||
ShopRepairs = Context.ShopRepairs.Where(rec => rec.ShopId == Model.Id).ToList();
|
||||
|
||||
foreach (var RepairToUpdate in ShopRepairs)
|
||||
{
|
||||
RepairToUpdate.Count = Model.ShopRepairs[RepairToUpdate.RepairId].Item2;
|
||||
Model.ShopRepairs.Remove(RepairToUpdate.RepairId);
|
||||
}
|
||||
|
||||
Context.SaveChanges();
|
||||
}
|
||||
|
||||
var Shop = Context.Shops.First(x => x.Id == Id);
|
||||
|
||||
foreach (var ShopRepair in Model.ShopRepairs)
|
||||
{
|
||||
Context.ShopRepairs.Add(new ShopRepair
|
||||
{
|
||||
Shop = Shop,
|
||||
Repair = Context.Repairs.First(x => x.Id == ShopRepair.Key),
|
||||
Count = ShopRepair.Value.Item2
|
||||
});
|
||||
|
||||
Context.SaveChanges();
|
||||
}
|
||||
|
||||
_shopRepairs = null;
|
||||
}
|
||||
|
||||
public void RepairsDictionatyUpdate(AutoWorkshopDatabase Context)
|
||||
{
|
||||
UpdateRepairs(Context, new ShopBindingModel
|
||||
{
|
||||
Id = Id,
|
||||
ShopRepairs = ShopRepairs
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
22
AutoWorkshopDatabaseImplement/Models/ShopRepair.cs
Normal file
22
AutoWorkshopDatabaseImplement/Models/ShopRepair.cs
Normal file
@@ -0,0 +1,22 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace AutoWorkshopDatabaseImplement.Models
|
||||
{
|
||||
public class ShopRepair
|
||||
{
|
||||
public int Id { get; set; }
|
||||
|
||||
[Required]
|
||||
public int RepairId { get; set; }
|
||||
|
||||
[Required]
|
||||
public int ShopId { get; set; }
|
||||
|
||||
[Required]
|
||||
public int Count { get; set; }
|
||||
|
||||
public virtual Shop Shop { get; set; } = new();
|
||||
|
||||
public virtual Repair Repair { get; set; } = new();
|
||||
}
|
||||
}
|
||||
@@ -10,22 +10,30 @@ namespace AutoWorkshopFileImplement
|
||||
private readonly string ComponentFileName = "Component.xml";
|
||||
private readonly string OrderFileName = "Order.xml";
|
||||
private readonly string RepairFileName = "Repair.xml";
|
||||
private readonly string ShopFileName = "Shop.xml";
|
||||
private readonly string ClientFileName = "Client.xml";
|
||||
private readonly string ImplementerFileName = "Implementer.xml";
|
||||
|
||||
public List<Component> Components { get; private set; }
|
||||
|
||||
public List<Order> Orders { get; private set; }
|
||||
|
||||
public List<Repair> Repairs { get; private set; }
|
||||
|
||||
public List<Shop> Shops { get; private set; }
|
||||
|
||||
public List<Client> Clients { get; private set; }
|
||||
|
||||
public List<Implementer> Implementers { get; private set; }
|
||||
|
||||
private DataFileSingleton()
|
||||
{
|
||||
Components = LoadData(ComponentFileName, "Component", x => Component.Create(x)!)!;
|
||||
Repairs = LoadData(RepairFileName, "Repair", x => Repair.Create(x)!)!;
|
||||
Orders = LoadData(OrderFileName, "Order", x => Order.Create(x)!)!;
|
||||
Shops = LoadData(ShopFileName, "Shop", x => Shop.Create(x)!)!;
|
||||
Clients = LoadData(ClientFileName, "Client", x => Client.Create(x)!)!;
|
||||
Implementers = LoadData(ImplementerFileName, "Implementer", x => Implementer.Create(x)!)!;
|
||||
}
|
||||
|
||||
public static DataFileSingleton GetInstance()
|
||||
@@ -41,7 +49,9 @@ namespace AutoWorkshopFileImplement
|
||||
public void SaveComponents() => SaveData(Components, ComponentFileName, "Components", x => x.GetXElement);
|
||||
public void SaveRepairs() => SaveData(Repairs, RepairFileName, "Repairs", x => x.GetXElement);
|
||||
public void SaveOrders() => SaveData(Orders, OrderFileName, "Orders", x => x.GetXElement);
|
||||
public void SaveShops() => SaveData(Shops, ShopFileName, "Shops", x => x.GetXElement);
|
||||
public void SaveClients() => SaveData(Clients, ClientFileName, "Clients", x => x.GetXElement);
|
||||
public void SaveImplementers() => SaveData(Implementers, ImplementerFileName, "Implementers", x => x.GetXElement);
|
||||
|
||||
private static List<T>? LoadData<T>(string FileName, string XmlNodeName, Func<XElement, T> SelectFunction)
|
||||
{
|
||||
|
||||
97
AutoWorkshopFileImplement/Implements/ImplementerStorage.cs
Normal file
97
AutoWorkshopFileImplement/Implements/ImplementerStorage.cs
Normal file
@@ -0,0 +1,97 @@
|
||||
using AutoWorkshopContracts.BindingModels;
|
||||
using AutoWorkshopContracts.SearchModels;
|
||||
using AutoWorkshopContracts.StoragesContracts;
|
||||
using AutoWorkshopContracts.ViewModels;
|
||||
using AutoWorkshopFileImplement.Models;
|
||||
|
||||
namespace AutoWorkshopFileImplement.Implements
|
||||
{
|
||||
public class ImplementerStorage : IImplementerStorage
|
||||
{
|
||||
private readonly DataFileSingleton _source;
|
||||
|
||||
public ImplementerStorage()
|
||||
{
|
||||
_source = DataFileSingleton.GetInstance();
|
||||
}
|
||||
|
||||
public List<ImplementerViewModel> GetFullList()
|
||||
{
|
||||
return _source.Implementers.Select(x => x.GetViewModel).ToList();
|
||||
}
|
||||
|
||||
public List<ImplementerViewModel> GetFilteredList(ImplementerSearchModel Model)
|
||||
{
|
||||
if (Model == null)
|
||||
return new();
|
||||
|
||||
if (Model.Id.HasValue)
|
||||
{
|
||||
var Res = GetElement(Model);
|
||||
return Res != null ? new() { Res } : new();
|
||||
}
|
||||
|
||||
if (Model.ImplementerFIO != null)
|
||||
{
|
||||
return _source.Implementers
|
||||
.Where(x => x.ImplementerFIO.Equals(Model.ImplementerFIO))
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
return new();
|
||||
}
|
||||
|
||||
public ImplementerViewModel? GetElement(ImplementerSearchModel Model)
|
||||
{
|
||||
if (Model.Id.HasValue)
|
||||
return _source.Implementers.FirstOrDefault(x => x.Id == Model.Id)?.GetViewModel;
|
||||
|
||||
if (Model.ImplementerFIO != null && Model.Password != null)
|
||||
return _source.Implementers.FirstOrDefault(x => x.ImplementerFIO.Equals(Model.ImplementerFIO) && x.Password.Equals(Model.Password))?.GetViewModel;
|
||||
|
||||
if (Model.ImplementerFIO != null)
|
||||
return _source.Implementers.FirstOrDefault(x => x.ImplementerFIO.Equals(Model.ImplementerFIO))?.GetViewModel;
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public ImplementerViewModel? Insert(ImplementerBindingModel Model)
|
||||
{
|
||||
Model.Id = _source.Implementers.Count > 0 ? _source.Implementers.Max(x => x.Id) + 1 : 1;
|
||||
|
||||
var Res = Implementer.Create(Model);
|
||||
if (Res != null)
|
||||
{
|
||||
_source.Implementers.Add(Res);
|
||||
_source.SaveImplementers();
|
||||
}
|
||||
|
||||
return Res?.GetViewModel;
|
||||
}
|
||||
|
||||
public ImplementerViewModel? Update(ImplementerBindingModel Model)
|
||||
{
|
||||
var Res = _source.Implementers.FirstOrDefault(x => x.Id == Model.Id);
|
||||
if (Res != null)
|
||||
{
|
||||
Res.Update(Model);
|
||||
_source.SaveImplementers();
|
||||
}
|
||||
|
||||
return Res?.GetViewModel;
|
||||
}
|
||||
|
||||
public ImplementerViewModel? Delete(ImplementerBindingModel Model)
|
||||
{
|
||||
var Res = _source.Implementers.FirstOrDefault(x => x.Id == Model.Id);
|
||||
if (Res != null)
|
||||
{
|
||||
_source.Implementers.Remove(Res);
|
||||
_source.SaveImplementers();
|
||||
}
|
||||
|
||||
return Res?.GetViewModel;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -26,14 +26,16 @@ namespace AutoWorkshopFileImplement.Implements
|
||||
if (Model.DateFrom.HasValue)
|
||||
{
|
||||
return _source.Orders
|
||||
.Where(x => (x.DateCreate >= Model.DateFrom && x.DateCreate <= Model.DateTo) && (!Model.ClientId.HasValue || x.ClientId == Model.ClientId))
|
||||
.Select(x => AddClientFIO(AddRepairName(x.GetViewModel)))
|
||||
.Where(x => (x.DateCreate >= Model.DateFrom && x.DateCreate <= Model.DateTo) && (!Model.ClientId.HasValue || x.ClientId == Model.ClientId)
|
||||
&& (!Model.ImplementerId.HasValue || x.ImplementerId == Model.ImplementerId))
|
||||
.Select(x => AddImplementerFIO(AddClientFIO(AddRepairName(x.GetViewModel))))
|
||||
.ToList();
|
||||
}
|
||||
|
||||
return _source.Orders
|
||||
.Where(x => (Model.Id.HasValue && x.Id == Model.Id) || (Model.ClientId.HasValue && x.ClientId == Model.ClientId))
|
||||
.Select(x => AddClientFIO(AddRepairName(x.GetViewModel)))
|
||||
.Where(x => (Model.Id.HasValue && x.Id == Model.Id) || (Model.ClientId.HasValue && x.ClientId == Model.ClientId)
|
||||
|| (Model.ImplementerId.HasValue && x.ImplementerId == Model.ImplementerId))
|
||||
.Select(x => AddImplementerFIO(AddClientFIO(AddRepairName(x.GetViewModel))))
|
||||
.ToList();
|
||||
}
|
||||
|
||||
@@ -54,15 +56,17 @@ namespace AutoWorkshopFileImplement.Implements
|
||||
|
||||
public OrderViewModel? GetElement(OrderSearchModel Model)
|
||||
{
|
||||
if (!Model.Id.HasValue)
|
||||
if (!Model.Id.HasValue && !Model.ImplementerId.HasValue && !Model.Status.HasValue)
|
||||
return null;
|
||||
|
||||
var Order = _source.Orders.FirstOrDefault(x => (Model.Id.HasValue && x.Id == Model.Id));
|
||||
|
||||
var Order = _source.Orders.FirstOrDefault(x =>
|
||||
(Model.Id.HasValue && x.Id == Model.Id)
|
||||
|| (Model.ImplementerId.HasValue && Model.Status.HasValue && x.ImplementerId == Model.ImplementerId && x.Status == Model.Status) );
|
||||
|
||||
if (Order == null)
|
||||
return null;
|
||||
|
||||
return AddRepairName(Order.GetViewModel);
|
||||
return AddImplementerFIO(AddClientFIO(AddRepairName(Order.GetViewModel)));
|
||||
}
|
||||
|
||||
public OrderViewModel? Insert(OrderBindingModel Model)
|
||||
@@ -108,5 +112,16 @@ namespace AutoWorkshopFileImplement.Implements
|
||||
Model.ClientFIO = SelectedClient?.ClientFIO ?? string.Empty;
|
||||
return Model;
|
||||
}
|
||||
|
||||
public OrderViewModel AddImplementerFIO(OrderViewModel Model)
|
||||
{
|
||||
var SelectedImplementer = _source.Implementers.FirstOrDefault(x => x.Id == Model.ImplementerId);
|
||||
|
||||
if (SelectedImplementer != null)
|
||||
{
|
||||
Model.ImplementerFIO = SelectedImplementer.ImplementerFIO;
|
||||
}
|
||||
return Model;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
168
AutoWorkshopFileImplement/Implements/ShopStorage.cs
Normal file
168
AutoWorkshopFileImplement/Implements/ShopStorage.cs
Normal file
@@ -0,0 +1,168 @@
|
||||
using AutoWorkshopContracts.BindingModels;
|
||||
using AutoWorkshopContracts.SearchModels;
|
||||
using AutoWorkshopContracts.StoragesContracts;
|
||||
using AutoWorkshopContracts.ViewModels;
|
||||
using AutoWorkshopFileImplement.Models;
|
||||
|
||||
namespace AutoWorkshopFileImplement.Implements
|
||||
{
|
||||
public class ShopStorage : IShopStorage
|
||||
{
|
||||
private readonly DataFileSingleton _source;
|
||||
|
||||
public ShopStorage()
|
||||
{
|
||||
_source = DataFileSingleton.GetInstance();
|
||||
}
|
||||
|
||||
public List<ShopViewModel> GetFullList()
|
||||
{
|
||||
return _source.Shops.Select(x => x.GetViewModel).ToList();
|
||||
}
|
||||
|
||||
public List<ShopViewModel> GetFilteredList(ShopSearchModel Model)
|
||||
{
|
||||
if (string.IsNullOrEmpty(Model.ShopName))
|
||||
return new();
|
||||
|
||||
return _source.Shops
|
||||
.Where(x => x.ShopName
|
||||
.Contains(Model.ShopName))
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public ShopViewModel? GetElement(ShopSearchModel Model)
|
||||
{
|
||||
if (string.IsNullOrEmpty(Model.ShopName) && !Model.Id.HasValue)
|
||||
return null;
|
||||
|
||||
return _source.Shops.FirstOrDefault(x =>
|
||||
(!string.IsNullOrEmpty(Model.ShopName) && x.ShopName == Model.ShopName) ||
|
||||
(Model.Id.HasValue && x.Id == Model.Id))?
|
||||
.GetViewModel;
|
||||
}
|
||||
|
||||
public ShopViewModel? Insert(ShopBindingModel Model)
|
||||
{
|
||||
Model.Id = _source.Shops.Count > 0 ? _source.Shops.Max(x => x.Id) + 1 : 1;
|
||||
|
||||
var NewShop = Shop.Create(Model);
|
||||
if (NewShop == null)
|
||||
return null;
|
||||
|
||||
_source.Shops.Add(NewShop);
|
||||
_source.SaveShops();
|
||||
|
||||
return NewShop.GetViewModel;
|
||||
}
|
||||
|
||||
public ShopViewModel? Update(ShopBindingModel Model)
|
||||
{
|
||||
var Shop = _source.Shops.FirstOrDefault(x => x.Id == Model.Id);
|
||||
if (Shop == null)
|
||||
return null;
|
||||
|
||||
Shop.Update(Model);
|
||||
_source.SaveShops();
|
||||
|
||||
return Shop.GetViewModel;
|
||||
}
|
||||
|
||||
public ShopViewModel? Delete(ShopBindingModel Model)
|
||||
{
|
||||
var Shop = _source.Shops.FirstOrDefault(x => x.Id == Model.Id);
|
||||
|
||||
if (Shop == null)
|
||||
return null;
|
||||
|
||||
_source.Shops.Remove(Shop);
|
||||
_source.SaveShops();
|
||||
|
||||
return Shop.GetViewModel;
|
||||
}
|
||||
|
||||
public bool Sell(SupplySearchModel Model)
|
||||
{
|
||||
if (Model == null || !Model.RepairId.HasValue || !Model.Count.HasValue)
|
||||
return false;
|
||||
|
||||
int TotalRepairsNum = _source.Shops
|
||||
.Select(x => x.Repairs.ContainsKey(Model.RepairId.Value) ? x.Repairs[Model.RepairId.Value] : 0)
|
||||
.Sum();
|
||||
if (TotalRepairsNum < Model.Count)
|
||||
return false;
|
||||
|
||||
var ShopsWithDesiredRepair = _source.Shops
|
||||
.Where(x => x.Repairs.ContainsKey(Model.RepairId.Value))
|
||||
.OrderByDescending(x => x.Repairs[Model.RepairId.Value])
|
||||
.ToList();
|
||||
|
||||
foreach (var Shop in ShopsWithDesiredRepair)
|
||||
{
|
||||
int Slack = Model.Count.Value - Shop.Repairs[Model.RepairId.Value];
|
||||
|
||||
if (Slack > 0)
|
||||
{
|
||||
Shop.Repairs.Remove(Model.RepairId.Value);
|
||||
Shop.RepairsUpdate();
|
||||
|
||||
Model.Count = Slack;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (Slack == 0)
|
||||
Shop.Repairs.Remove(Model.RepairId.Value);
|
||||
else
|
||||
Shop.Repairs[Model.RepairId.Value] = -Slack;
|
||||
|
||||
Shop.RepairsUpdate();
|
||||
_source.SaveShops();
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
_source.SaveShops();
|
||||
return false;
|
||||
}
|
||||
|
||||
public bool RestockingShops(SupplyBindingModel Model)
|
||||
{
|
||||
int TotalFreeSpaceNum = _source.Shops
|
||||
.Select(x => x.RepairsMaxCount - x.ShopRepairs
|
||||
.Select(y => y.Value.Item2)
|
||||
.Sum())
|
||||
.Sum();
|
||||
|
||||
if (TotalFreeSpaceNum < Model.Count)
|
||||
return false;
|
||||
|
||||
foreach (Shop Shop in _source.Shops)
|
||||
{
|
||||
int FreeSpaceNum = Shop.RepairsMaxCount - Shop.ShopRepairs.Select(x => x.Value.Item2).Sum();
|
||||
|
||||
if (FreeSpaceNum <= 0)
|
||||
continue;
|
||||
|
||||
FreeSpaceNum = Math.Min(FreeSpaceNum, Model.Count);
|
||||
Model.Count -= FreeSpaceNum;
|
||||
|
||||
if (Shop.Repairs.ContainsKey(Model.RepairId))
|
||||
Shop.Repairs[Model.RepairId] += FreeSpaceNum;
|
||||
else
|
||||
Shop.Repairs.Add(Model.RepairId, FreeSpaceNum);
|
||||
|
||||
Shop.RepairsUpdate();
|
||||
|
||||
if (Model.Count == 0)
|
||||
{
|
||||
_source.SaveShops();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
79
AutoWorkshopFileImplement/Models/Implementer.cs
Normal file
79
AutoWorkshopFileImplement/Models/Implementer.cs
Normal file
@@ -0,0 +1,79 @@
|
||||
using AutoWorkshopContracts.BindingModels;
|
||||
using AutoWorkshopContracts.ViewModels;
|
||||
using AutoWorkshopDataModels.Models;
|
||||
using System.Xml.Linq;
|
||||
|
||||
namespace AutoWorkshopFileImplement.Models
|
||||
{
|
||||
public class Implementer : IImplementerModel
|
||||
{
|
||||
public int Id { get; private set; }
|
||||
|
||||
public string ImplementerFIO { get; private set; } = string.Empty;
|
||||
|
||||
public string Password { get; private set; } = string.Empty;
|
||||
|
||||
public int WorkExperience { get; private set; }
|
||||
|
||||
public int Qualification { get; private set; }
|
||||
|
||||
public static Implementer? Create(ImplementerBindingModel Model)
|
||||
{
|
||||
if (Model == null)
|
||||
return null;
|
||||
|
||||
return new()
|
||||
{
|
||||
Id = Model.Id,
|
||||
ImplementerFIO = Model.ImplementerFIO,
|
||||
Password = Model.Password,
|
||||
WorkExperience = Model.WorkExperience,
|
||||
Qualification = Model.Qualification,
|
||||
};
|
||||
}
|
||||
|
||||
public static Implementer? Create(XElement Element)
|
||||
{
|
||||
if (Element == null)
|
||||
return null;
|
||||
|
||||
return new()
|
||||
{
|
||||
Id = Convert.ToInt32(Element.Attribute("Id")!.Value),
|
||||
ImplementerFIO = Element.Element("ImplementerFIO")!.Value,
|
||||
Password = Element.Element("Password")!.Value,
|
||||
WorkExperience = Convert.ToInt32(Element.Element("WorkExperience")!.Value),
|
||||
Qualification = Convert.ToInt32(Element.Element("Qualification")!.Value),
|
||||
};
|
||||
}
|
||||
|
||||
public void Update(ImplementerBindingModel Model)
|
||||
{
|
||||
if (Model == null)
|
||||
return;
|
||||
|
||||
ImplementerFIO = Model.ImplementerFIO;
|
||||
Password = Model.Password;
|
||||
WorkExperience = Model.WorkExperience;
|
||||
Qualification = Model.Qualification;
|
||||
}
|
||||
|
||||
public ImplementerViewModel GetViewModel => new()
|
||||
{
|
||||
Id = Id,
|
||||
ImplementerFIO = ImplementerFIO,
|
||||
Password = Password,
|
||||
WorkExperience = WorkExperience,
|
||||
Qualification = Qualification,
|
||||
};
|
||||
|
||||
public XElement GetXElement => new(
|
||||
"Implementer",
|
||||
new XAttribute("Id", Id),
|
||||
new XElement("ImplementerFIO", ImplementerFIO),
|
||||
new XElement("Password", Password),
|
||||
new XElement("WorkExperience", WorkExperience),
|
||||
new XElement("Qualification", Qualification)
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -14,6 +14,8 @@ namespace AutoWorkshopFileImplement.Models
|
||||
|
||||
public int ClientId { get; private set; }
|
||||
|
||||
public int? ImplementerId { get; set; }
|
||||
|
||||
public int Count { get; private set; }
|
||||
|
||||
public double Sum { get; private set; }
|
||||
@@ -34,6 +36,7 @@ namespace AutoWorkshopFileImplement.Models
|
||||
Id = Model.Id,
|
||||
RepairId = Model.RepairId,
|
||||
ClientId = Model.ClientId,
|
||||
ImplementerId = Model.ImplementerId,
|
||||
Count = Model.Count,
|
||||
Sum = Model.Sum,
|
||||
Status = Model.Status,
|
||||
@@ -52,6 +55,7 @@ namespace AutoWorkshopFileImplement.Models
|
||||
Id = Convert.ToInt32(Element.Attribute("Id")!.Value),
|
||||
RepairId = Convert.ToInt32(Element.Element("RepairId")!.Value),
|
||||
ClientId = Convert.ToInt32(Element.Element("ClientId")!.Value),
|
||||
ImplementerId = Convert.ToInt32(Element.Element("ImplementerId")!.Value),
|
||||
Count = Convert.ToInt32(Element.Element("Count")!.Value),
|
||||
Sum = Convert.ToDouble(Element.Element("Sum")!.Value),
|
||||
Status = (OrderStatus)Enum.Parse(typeof(OrderStatus), Element.Element("Status")!.Value),
|
||||
@@ -65,6 +69,7 @@ namespace AutoWorkshopFileImplement.Models
|
||||
if (Model is null)
|
||||
return;
|
||||
|
||||
ImplementerId = Model.ImplementerId;
|
||||
Status = Model.Status;
|
||||
DateImplement = Model.DateImplement;
|
||||
}
|
||||
@@ -74,6 +79,7 @@ namespace AutoWorkshopFileImplement.Models
|
||||
Id = Id,
|
||||
RepairId = RepairId,
|
||||
ClientId = ClientId,
|
||||
ImplementerId = ImplementerId,
|
||||
Count = Count,
|
||||
Sum = Sum,
|
||||
Status = Status,
|
||||
@@ -86,6 +92,7 @@ namespace AutoWorkshopFileImplement.Models
|
||||
new XAttribute("Id", Id),
|
||||
new XElement("RepairId", RepairId),
|
||||
new XElement("ClientId", ClientId),
|
||||
new XElement("ImplementerId", ImplementerId),
|
||||
new XElement("Count", Count.ToString()),
|
||||
new XElement("Sum", Sum.ToString()),
|
||||
new XElement("Status", Status.ToString()),
|
||||
|
||||
110
AutoWorkshopFileImplement/Models/Shop.cs
Normal file
110
AutoWorkshopFileImplement/Models/Shop.cs
Normal file
@@ -0,0 +1,110 @@
|
||||
using AutoWorkshopContracts.BindingModels;
|
||||
using AutoWorkshopContracts.ViewModels;
|
||||
using AutoWorkshopDataModels.Models;
|
||||
using System.Xml.Linq;
|
||||
|
||||
namespace AutoWorkshopFileImplement.Models
|
||||
{
|
||||
public class Shop : IShopModel
|
||||
{
|
||||
public int Id { get; private set; }
|
||||
|
||||
public string ShopName { get; private set; } = string.Empty;
|
||||
|
||||
public string Address { get; private set; } = string.Empty;
|
||||
|
||||
public DateTime OpeningDate { get; private set; }
|
||||
|
||||
public Dictionary<int, int> Repairs { get; private set; } = new();
|
||||
|
||||
private Dictionary<int, (IRepairModel, int)>? _shopRepairs = null;
|
||||
|
||||
public Dictionary<int, (IRepairModel, int)> ShopRepairs
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_shopRepairs == null)
|
||||
{
|
||||
var Source = DataFileSingleton.GetInstance();
|
||||
_shopRepairs = Repairs.ToDictionary(x => x.Key, y => ((Source.Repairs.FirstOrDefault(z => z.Id == y.Key) as IRepairModel)!, y.Value));
|
||||
}
|
||||
|
||||
return _shopRepairs;
|
||||
}
|
||||
}
|
||||
|
||||
public int RepairsMaxCount { get; private set; }
|
||||
|
||||
public static Shop? Create(ShopBindingModel? Model)
|
||||
{
|
||||
if (Model == null)
|
||||
return null;
|
||||
|
||||
return new Shop()
|
||||
{
|
||||
Id = Model.Id,
|
||||
ShopName = Model.ShopName,
|
||||
Address = Model.Address,
|
||||
OpeningDate = Model.OpeningDate,
|
||||
Repairs = Model.ShopRepairs.ToDictionary(x => x.Key, x => x.Value.Item2),
|
||||
RepairsMaxCount = Model.RepairsMaxCount
|
||||
};
|
||||
}
|
||||
|
||||
public static Shop? Create(XElement Element)
|
||||
{
|
||||
if (Element == null)
|
||||
return null;
|
||||
|
||||
return new Shop()
|
||||
{
|
||||
Id = Convert.ToInt32(Element.Attribute("Id")!.Value),
|
||||
ShopName = Element.Element("ShopName")!.Value,
|
||||
Address = Element.Element("Address")!.Value,
|
||||
OpeningDate = Convert.ToDateTime(Element.Element("OpeningDate")!.Value),
|
||||
Repairs = Element.Element("ShopRepairs")!.Elements("ShopRepair")!.ToDictionary(x => Convert.ToInt32(x.Element("Key")?.Value),
|
||||
x => Convert.ToInt32(x.Element("Value")?.Value)),
|
||||
RepairsMaxCount = Convert.ToInt32(Element.Element("RepairsMaxCount")!.Value)
|
||||
};
|
||||
}
|
||||
|
||||
public void Update(ShopBindingModel? Model)
|
||||
{
|
||||
if (Model == null)
|
||||
return;
|
||||
|
||||
ShopName = Model.ShopName;
|
||||
Address = Model.Address;
|
||||
OpeningDate = Model.OpeningDate;
|
||||
RepairsMaxCount = Model.RepairsMaxCount;
|
||||
Repairs = Model.ShopRepairs.ToDictionary(x => x.Key, x => x.Value.Item2);
|
||||
_shopRepairs = null;
|
||||
}
|
||||
|
||||
public ShopViewModel GetViewModel => new()
|
||||
{
|
||||
Id = Id,
|
||||
ShopName = ShopName,
|
||||
Address = Address,
|
||||
OpeningDate = OpeningDate,
|
||||
ShopRepairs = ShopRepairs,
|
||||
RepairsMaxCount = RepairsMaxCount
|
||||
};
|
||||
|
||||
public XElement GetXElement => new(
|
||||
"Shop",
|
||||
new XAttribute("Id", Id),
|
||||
new XElement("ShopName", ShopName),
|
||||
new XElement("Address", Address),
|
||||
new XElement("OpeningDate", OpeningDate.ToString()),
|
||||
new XElement("ShopRepairs", Repairs.Select(
|
||||
x => new XElement("ShopRepair", new XElement("Key", x.Key), new XElement("Value", x.Value))).ToArray()),
|
||||
new XElement("RepairsMaxCount", RepairsMaxCount.ToString())
|
||||
);
|
||||
|
||||
public void RepairsUpdate()
|
||||
{
|
||||
_shopRepairs = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -12,14 +12,21 @@ namespace AutoWorkshopListImplement
|
||||
|
||||
public List<Repair> Repairs { get; set; }
|
||||
|
||||
public List<Shop> Shops { get; set; }
|
||||
|
||||
|
||||
public List<Client> Clients { get; set; }
|
||||
|
||||
public List<Implementer> Implementers { get; set; }
|
||||
|
||||
private DataListSingleton()
|
||||
{
|
||||
Components = new List<Component>();
|
||||
Orders = new List<Order>();
|
||||
Repairs = new List<Repair>();
|
||||
Shops = new List<Shop>();
|
||||
Clients = new List<Client>();
|
||||
Implementers = new List<Implementer>();
|
||||
}
|
||||
|
||||
public static DataListSingleton GetInstance()
|
||||
|
||||
104
AutoWorkshopImplement/Implements/ImplementerStorage.cs
Normal file
104
AutoWorkshopImplement/Implements/ImplementerStorage.cs
Normal file
@@ -0,0 +1,104 @@
|
||||
using AutoWorkshopContracts.BindingModels;
|
||||
using AutoWorkshopContracts.SearchModels;
|
||||
using AutoWorkshopContracts.StoragesContracts;
|
||||
using AutoWorkshopContracts.ViewModels;
|
||||
using AutoWorkshopListImplement.Models;
|
||||
|
||||
namespace AutoWorkshopListImplement.Implements
|
||||
{
|
||||
public class ImplementerStorage : IImplementerStorage
|
||||
{
|
||||
private readonly DataListSingleton _source;
|
||||
|
||||
public ImplementerStorage()
|
||||
{
|
||||
_source = DataListSingleton.GetInstance();
|
||||
}
|
||||
|
||||
public List<ImplementerViewModel> GetFullList()
|
||||
{
|
||||
var Result = new List<ImplementerViewModel>();
|
||||
|
||||
foreach (var Implementer in _source.Implementers)
|
||||
{
|
||||
Result.Add(Implementer.GetViewModel);
|
||||
}
|
||||
|
||||
return Result;
|
||||
}
|
||||
|
||||
public List<ImplementerViewModel> GetFilteredList(ImplementerSearchModel Model)
|
||||
{
|
||||
if (string.IsNullOrEmpty(Model.ImplementerFIO))
|
||||
return new();
|
||||
|
||||
return _source.Implementers
|
||||
.Where(x => (!string.IsNullOrEmpty(Model.ImplementerFIO) && x.ImplementerFIO.Contains(Model.ImplementerFIO)))
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public ImplementerViewModel? GetElement(ImplementerSearchModel Model)
|
||||
{
|
||||
foreach (var Implementer in _source.Implementers)
|
||||
{
|
||||
if ((Model.Id.HasValue && Implementer.Id == Model.Id) ||
|
||||
(!string.IsNullOrEmpty(Model.ImplementerFIO) && Implementer.ImplementerFIO == Model.ImplementerFIO))
|
||||
{
|
||||
return Implementer.GetViewModel;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public ImplementerViewModel? Insert(ImplementerBindingModel Model)
|
||||
{
|
||||
Model.Id = 1;
|
||||
foreach (var Implementer in _source.Implementers)
|
||||
{
|
||||
if (Model.Id <= Implementer.Id)
|
||||
{
|
||||
Model.Id = Implementer.Id + 1;
|
||||
}
|
||||
}
|
||||
|
||||
var NewImplementer = Implementer.Create(Model);
|
||||
if (NewImplementer == null)
|
||||
return null;
|
||||
|
||||
_source.Implementers.Add(NewImplementer);
|
||||
return NewImplementer.GetViewModel;
|
||||
}
|
||||
|
||||
public ImplementerViewModel? Update(ImplementerBindingModel Model)
|
||||
{
|
||||
foreach (var Implementer in _source.Implementers)
|
||||
{
|
||||
if (Implementer.Id == Model.Id)
|
||||
{
|
||||
Implementer.Update(Model);
|
||||
return Implementer.GetViewModel;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public ImplementerViewModel? Delete(ImplementerBindingModel Model)
|
||||
{
|
||||
for (int i = 0; i < _source.Implementers.Count; ++i)
|
||||
{
|
||||
if (_source.Implementers[i].Id == Model.Id)
|
||||
{
|
||||
var Implementer = _source.Implementers[i];
|
||||
_source.Implementers.RemoveAt(i);
|
||||
|
||||
return Implementer.GetViewModel;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -32,27 +32,30 @@ namespace AutoWorkshopListImplement.Implements
|
||||
if (Model.DateFrom.HasValue)
|
||||
{
|
||||
return _source.Orders
|
||||
.Where(x => (x.DateCreate >= Model.DateFrom && x.DateCreate <= Model.DateTo) && (!Model.ClientId.HasValue || x.ClientId == Model.ClientId))
|
||||
.Select(x => JoinClientFIO(JoinRepairName(x.GetViewModel)))
|
||||
.Where(x => (x.DateCreate >= Model.DateFrom && x.DateCreate <= Model.DateTo) && (!Model.ClientId.HasValue || x.ClientId == Model.ClientId)
|
||||
&& (!Model.ImplementerId.HasValue || x.ImplementerId == Model.ImplementerId))
|
||||
.Select(x => JoinImplementerFIO(JoinClientFIO(JoinRepairName(x.GetViewModel))))
|
||||
.ToList();
|
||||
}
|
||||
|
||||
return _source.Orders
|
||||
.Where(x => (Model.Id.HasValue && x.Id == Model.Id) || (Model.ClientId.HasValue && x.ClientId == Model.ClientId))
|
||||
.Select(x => JoinClientFIO(JoinRepairName(x.GetViewModel)))
|
||||
.Where(x => (Model.Id.HasValue && x.Id == Model.Id) || (Model.ClientId.HasValue && x.ClientId == Model.ClientId)
|
||||
|| (Model.ImplementerId.HasValue && x.ImplementerId == Model.ImplementerId))
|
||||
.Select(x => JoinImplementerFIO(JoinClientFIO(JoinRepairName(x.GetViewModel))))
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public OrderViewModel? GetElement(OrderSearchModel Model)
|
||||
{
|
||||
if (!Model.Id.HasValue)
|
||||
if (!Model.Id.HasValue && !Model.ImplementerId.HasValue && !Model.Status.HasValue)
|
||||
return null;
|
||||
|
||||
foreach (var Order in _source.Orders)
|
||||
{
|
||||
if (Order.Id == Model.Id)
|
||||
if ((Model.Id.HasValue && Order.Id == Model.Id)
|
||||
|| (Model.ImplementerId.HasValue && Model.Status.HasValue && Order.ImplementerId == Model.ImplementerId && Order.Status == Model.Status))
|
||||
{
|
||||
return JoinRepairName(Order.GetViewModel);
|
||||
return JoinImplementerFIO(JoinClientFIO(JoinRepairName(Order.GetViewModel)));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -130,5 +133,16 @@ namespace AutoWorkshopListImplement.Implements
|
||||
}
|
||||
return Model;
|
||||
}
|
||||
|
||||
public OrderViewModel JoinImplementerFIO(OrderViewModel Model)
|
||||
{
|
||||
var SelectedImplementer = _source.Implementers.FirstOrDefault(x => x.Id == Model.ImplementerId);
|
||||
|
||||
if (SelectedImplementer != null)
|
||||
{
|
||||
Model.ImplementerFIO = SelectedImplementer.ImplementerFIO;
|
||||
}
|
||||
return Model;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
122
AutoWorkshopImplement/Implements/ShopStorage.cs
Normal file
122
AutoWorkshopImplement/Implements/ShopStorage.cs
Normal file
@@ -0,0 +1,122 @@
|
||||
using AutoWorkshopContracts.BindingModels;
|
||||
using AutoWorkshopContracts.SearchModels;
|
||||
using AutoWorkshopContracts.StoragesContracts;
|
||||
using AutoWorkshopContracts.ViewModels;
|
||||
using AutoWorkshopListImplement.Models;
|
||||
|
||||
namespace AutoWorkshopListImplement.Implements
|
||||
{
|
||||
public class ShopStorage : IShopStorage
|
||||
{
|
||||
private readonly DataListSingleton _source;
|
||||
|
||||
public ShopStorage()
|
||||
{
|
||||
_source = DataListSingleton.GetInstance();
|
||||
}
|
||||
|
||||
public List<ShopViewModel> GetFullList()
|
||||
{
|
||||
var Result = new List<ShopViewModel>();
|
||||
|
||||
foreach (var Shop in _source.Shops)
|
||||
{
|
||||
Result.Add(Shop.GetViewModel);
|
||||
}
|
||||
|
||||
return Result;
|
||||
}
|
||||
|
||||
public List<ShopViewModel> GetFilteredList(ShopSearchModel Model)
|
||||
{
|
||||
var Result = new List<ShopViewModel>();
|
||||
|
||||
if (string.IsNullOrEmpty(Model.ShopName))
|
||||
return Result;
|
||||
|
||||
foreach (var Shop in _source.Shops)
|
||||
{
|
||||
if (Shop.ShopName.Contains(Model.ShopName))
|
||||
Result.Add(Shop.GetViewModel);
|
||||
}
|
||||
|
||||
return Result;
|
||||
}
|
||||
|
||||
public ShopViewModel? GetElement(ShopSearchModel Model)
|
||||
{
|
||||
if (string.IsNullOrEmpty(Model.ShopName) && !Model.Id.HasValue)
|
||||
return null;
|
||||
|
||||
foreach (var Shop in _source.Shops)
|
||||
{
|
||||
if ((!string.IsNullOrEmpty(Model.ShopName) && Shop.ShopName == Model.ShopName) ||
|
||||
(Model.Id.HasValue && Shop.Id == Model.Id))
|
||||
{
|
||||
return Shop.GetViewModel;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public ShopViewModel? Insert(ShopBindingModel Model)
|
||||
{
|
||||
Model.Id = 1;
|
||||
|
||||
foreach (var Shop in _source.Shops)
|
||||
{
|
||||
if (Model.Id <= Shop.Id)
|
||||
Model.Id = Shop.Id + 1;
|
||||
}
|
||||
|
||||
var NewShop = Shop.Create(Model);
|
||||
|
||||
if (NewShop is null)
|
||||
return null;
|
||||
|
||||
_source.Shops.Add(NewShop);
|
||||
return NewShop.GetViewModel;
|
||||
}
|
||||
|
||||
public ShopViewModel? Update(ShopBindingModel Model)
|
||||
{
|
||||
foreach (var Shop in _source.Shops)
|
||||
{
|
||||
if (Shop.Id == Model.Id)
|
||||
{
|
||||
Shop.Update(Model);
|
||||
return Shop.GetViewModel;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public ShopViewModel? Delete(ShopBindingModel Model)
|
||||
{
|
||||
for (int i = 0; i < _source.Shops.Count; ++i)
|
||||
{
|
||||
if (_source.Shops[i].Id == Model.Id)
|
||||
{
|
||||
var Shop = _source.Shops[i];
|
||||
_source.Shops.RemoveAt(i);
|
||||
|
||||
return Shop.GetViewModel;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public bool Sell(SupplySearchModel Model)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public bool RestockingShops(SupplyBindingModel Model)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
54
AutoWorkshopImplement/Models/Implementer.cs
Normal file
54
AutoWorkshopImplement/Models/Implementer.cs
Normal file
@@ -0,0 +1,54 @@
|
||||
using AutoWorkshopContracts.BindingModels;
|
||||
using AutoWorkshopContracts.ViewModels;
|
||||
using AutoWorkshopDataModels.Models;
|
||||
|
||||
namespace AutoWorkshopListImplement.Models
|
||||
{
|
||||
public class Implementer : IImplementerModel
|
||||
{
|
||||
public int Id { get; private set; }
|
||||
|
||||
public string ImplementerFIO { get; private set; } = string.Empty;
|
||||
|
||||
public string Password { get; private set; } = string.Empty;
|
||||
|
||||
public int WorkExperience { get; private set; }
|
||||
|
||||
public int Qualification { get; private set; }
|
||||
|
||||
public static Implementer? Create(ImplementerBindingModel Model)
|
||||
{
|
||||
if (Model == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return new()
|
||||
{
|
||||
Id = Model.Id,
|
||||
Password = Model.Password,
|
||||
Qualification = Model.Qualification,
|
||||
ImplementerFIO = Model.ImplementerFIO,
|
||||
WorkExperience = Model.WorkExperience,
|
||||
};
|
||||
}
|
||||
|
||||
public void Update(ImplementerBindingModel Model)
|
||||
{
|
||||
if (Model == null)
|
||||
return;
|
||||
|
||||
Password = Model.Password;
|
||||
Qualification = Model.Qualification;
|
||||
ImplementerFIO = Model.ImplementerFIO;
|
||||
WorkExperience = Model.WorkExperience;
|
||||
}
|
||||
|
||||
public ImplementerViewModel GetViewModel => new()
|
||||
{
|
||||
Id = Id,
|
||||
Password = Password,
|
||||
Qualification = Qualification,
|
||||
ImplementerFIO = ImplementerFIO,
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -13,6 +13,8 @@ namespace AutoWorkshopListImplement.Models
|
||||
|
||||
public int ClientId { get; private set; }
|
||||
|
||||
public int? ImplementerId { get; private set; }
|
||||
|
||||
public int Count { get; private set; }
|
||||
|
||||
public double Sum { get; private set; }
|
||||
@@ -33,6 +35,7 @@ namespace AutoWorkshopListImplement.Models
|
||||
Id = Model.Id,
|
||||
RepairId = Model.RepairId,
|
||||
ClientId = Model.ClientId,
|
||||
ImplementerId = Model.ImplementerId,
|
||||
Count = Model.Count,
|
||||
Sum = Model.Sum,
|
||||
Status = Model.Status,
|
||||
@@ -46,11 +49,7 @@ namespace AutoWorkshopListImplement.Models
|
||||
if (Model == null)
|
||||
return;
|
||||
|
||||
RepairId = Model.RepairId;
|
||||
Count = Model.Count;
|
||||
Sum = Model.Sum;
|
||||
Status = Model.Status;
|
||||
DateCreate = Model.DateCreate;
|
||||
DateImplement = Model.DateImplement;
|
||||
}
|
||||
|
||||
@@ -59,6 +58,7 @@ namespace AutoWorkshopListImplement.Models
|
||||
Id = Id,
|
||||
RepairId = RepairId,
|
||||
ClientId = ClientId,
|
||||
ImplementerId = ImplementerId,
|
||||
Count = Count,
|
||||
Sum = Sum,
|
||||
Status = Status,
|
||||
|
||||
57
AutoWorkshopImplement/Models/Shop.cs
Normal file
57
AutoWorkshopImplement/Models/Shop.cs
Normal file
@@ -0,0 +1,57 @@
|
||||
using AutoWorkshopContracts.BindingModels;
|
||||
using AutoWorkshopContracts.ViewModels;
|
||||
using AutoWorkshopDataModels.Models;
|
||||
|
||||
namespace AutoWorkshopListImplement.Models
|
||||
{
|
||||
public class Shop : IShopModel
|
||||
{
|
||||
public int Id { get; private set; }
|
||||
|
||||
public string ShopName { get; private set; } = string.Empty;
|
||||
|
||||
public string Address { get; private set; } = string.Empty;
|
||||
|
||||
public DateTime OpeningDate { get; private set; }
|
||||
|
||||
public Dictionary<int, (IRepairModel, int)> ShopRepairs { get; private set; } = new();
|
||||
|
||||
public int RepairsMaxCount { get; private set; }
|
||||
|
||||
public static Shop? Create(ShopBindingModel? Model)
|
||||
{
|
||||
if (Model is null)
|
||||
return null;
|
||||
|
||||
return new Shop()
|
||||
{
|
||||
Id = Model.Id,
|
||||
ShopName = Model.ShopName,
|
||||
Address = Model.Address,
|
||||
OpeningDate = Model.OpeningDate,
|
||||
RepairsMaxCount = Model.RepairsMaxCount,
|
||||
};
|
||||
}
|
||||
|
||||
public void Update(ShopBindingModel? Model)
|
||||
{
|
||||
if (Model is null)
|
||||
return;
|
||||
|
||||
ShopName = Model.ShopName;
|
||||
Address = Model.Address;
|
||||
OpeningDate = Model.OpeningDate;
|
||||
RepairsMaxCount = Model.RepairsMaxCount;
|
||||
}
|
||||
|
||||
public ShopViewModel GetViewModel => new()
|
||||
{
|
||||
Id = Id,
|
||||
ShopName = ShopName,
|
||||
Address = Address,
|
||||
OpeningDate = OpeningDate,
|
||||
ShopRepairs = ShopRepairs,
|
||||
RepairsMaxCount = RepairsMaxCount,
|
||||
};
|
||||
}
|
||||
}
|
||||
108
AutoWorkshopRestApi/Controllers/ImplementerController.cs
Normal file
108
AutoWorkshopRestApi/Controllers/ImplementerController.cs
Normal file
@@ -0,0 +1,108 @@
|
||||
using AutoWorkshopContracts.BindingModels;
|
||||
using AutoWorkshopContracts.BusinessLogicContracts;
|
||||
using AutoWorkshopContracts.BusinessLogicsContracts;
|
||||
using AutoWorkshopContracts.SearchModels;
|
||||
using AutoWorkshopContracts.ViewModels;
|
||||
using AutoWorkshopDataModels.Enums;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace AutoWorkshopRestApi.Controllers
|
||||
{
|
||||
[Route("api/[controller]/[action]")]
|
||||
[ApiController]
|
||||
public class ImplementerController : Controller
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
|
||||
private readonly IOrderLogic _order;
|
||||
|
||||
private readonly IImplementerLogic _logic;
|
||||
|
||||
public ImplementerController(IOrderLogic Order, IImplementerLogic Logic, ILogger<ImplementerController> Logger)
|
||||
{
|
||||
_logger = Logger;
|
||||
_order = Order;
|
||||
_logic = Logic;
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public ImplementerViewModel? Login(string login, string password)
|
||||
{
|
||||
try
|
||||
{
|
||||
return _logic.ReadElement(new ImplementerSearchModel
|
||||
{
|
||||
ImplementerFIO = login,
|
||||
Password = password
|
||||
});
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка авторизации сотрудника");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public List<OrderViewModel>? GetNewOrders()
|
||||
{
|
||||
try
|
||||
{
|
||||
return _order.ReadList(new OrderSearchModel
|
||||
{
|
||||
Status = OrderStatus.Accepted
|
||||
});
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка получения новых заказов");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public OrderViewModel? GetImplementerOrder(int implementerId)
|
||||
{
|
||||
try
|
||||
{
|
||||
return _order.ReadElement(new OrderSearchModel
|
||||
{
|
||||
ImplementerId = implementerId
|
||||
});
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка получения текущего заказа исполнителя");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public void TakeOrderInWork(OrderBindingModel Model)
|
||||
{
|
||||
try
|
||||
{
|
||||
_order.TakeOrderInWork(Model);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка перевода заказа с №{Id} в работу", Model.Id);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public void FinishOrder(OrderBindingModel Model)
|
||||
{
|
||||
try
|
||||
{
|
||||
_order.FinishOrder(Model);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка отметки о готовности заказа с №{Id}", Model.Id);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
125
AutoWorkshopRestApi/Controllers/ShopController.cs
Normal file
125
AutoWorkshopRestApi/Controllers/ShopController.cs
Normal file
@@ -0,0 +1,125 @@
|
||||
using AutoWorkshopContracts.BindingModels;
|
||||
using AutoWorkshopContracts.BusinessLogicsContracts;
|
||||
using AutoWorkshopContracts.SearchModels;
|
||||
using AutoWorkshopContracts.ViewModels;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace AutoWorkshopRestApi.Controllers
|
||||
{
|
||||
[Route("api/[controller]/[action]")]
|
||||
[ApiController]
|
||||
public class ShopController : Controller
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly IShopLogic _shopLogic;
|
||||
|
||||
public ShopController(ILogger<ShopController> Logger, IShopLogic ShopLogic)
|
||||
{
|
||||
_logger = Logger;
|
||||
_shopLogic = ShopLogic;
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public List<ShopViewModel>? GetShopList()
|
||||
{
|
||||
try
|
||||
{
|
||||
return _shopLogic.ReadList(null);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка получения списка магазинов");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public ShopRepairsViewModel? GetShop(int ShopId)
|
||||
{
|
||||
try
|
||||
{
|
||||
var Shop = _shopLogic.ReadElement(new ShopSearchModel { Id = ShopId });
|
||||
|
||||
if (Shop == null)
|
||||
return null;
|
||||
|
||||
return new ShopRepairsViewModel
|
||||
{
|
||||
Shop = Shop,
|
||||
ShopRepairs = Shop.ShopRepairs.ToDictionary(x => x.Key, x => new RepairCount
|
||||
{
|
||||
Repair = new RepairViewModel()
|
||||
{
|
||||
Id = x.Value.Item1.Id,
|
||||
RepairName = x.Value.Item1.RepairName,
|
||||
RepairComponents = x.Value.Item1.RepairComponents,
|
||||
Price = x.Value.Item1.Price,
|
||||
},
|
||||
Count = x.Value.Item2
|
||||
})
|
||||
};
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка получения магазина");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public void CreateShop(ShopBindingModel Model)
|
||||
{
|
||||
try
|
||||
{
|
||||
_shopLogic.Create(Model);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка создания магазина");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public void UpdateShop(ShopBindingModel Model)
|
||||
{
|
||||
try
|
||||
{
|
||||
_shopLogic.Update(Model);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка обновления магазина");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public void DeleteShop(ShopBindingModel Model)
|
||||
{
|
||||
try
|
||||
{
|
||||
_shopLogic.Delete(Model);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка удаления магазина");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public void MakeSupply(SupplyBindingModel Model)
|
||||
{
|
||||
try
|
||||
{
|
||||
_shopLogic.MakeSupply(Model);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка создания поставки в магазин");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
using AutoWorkshopBusinessLogic.BusinessLogics;
|
||||
using AutoWorkshopContracts.BusinessLogicContracts;
|
||||
using AutoWorkshopContracts.BusinessLogicsContracts;
|
||||
using AutoWorkshopContracts.StoragesContracts;
|
||||
using AutoWorkshopDatabaseImplement.Implements;
|
||||
using Microsoft.OpenApi.Models;
|
||||
@@ -12,9 +13,17 @@ Builder.Logging.AddLog4Net("log4net.config");
|
||||
Builder.Services.AddTransient<IClientStorage, ClientStorage>();
|
||||
Builder.Services.AddTransient<IOrderStorage, OrderStorage>();
|
||||
Builder.Services.AddTransient<IRepairStorage, RepairStorage>();
|
||||
Builder.Services.AddTransient<IImplementerStorage, ImplementerStorage>();
|
||||
|
||||
Builder.Services.AddTransient<IShopStorage, ShopStorage>();
|
||||
|
||||
Builder.Services.AddTransient<IOrderLogic, OrderLogic>();
|
||||
Builder.Services.AddTransient<IClientLogic, ClientLogic>();
|
||||
Builder.Services.AddTransient<IRepairLogic, RepairLogic>();
|
||||
Builder.Services.AddTransient<IImplementerLogic, ImplementerLogic>();
|
||||
|
||||
Builder.Services.AddTransient<IShopLogic, ShopLogic>();
|
||||
|
||||
Builder.Services.AddControllers();
|
||||
|
||||
Builder.Services.AddEndpointsApiExplorer();
|
||||
|
||||
60
AutoWorkshopShopApp/ApiClient.cs
Normal file
60
AutoWorkshopShopApp/ApiClient.cs
Normal file
@@ -0,0 +1,60 @@
|
||||
using Newtonsoft.Json;
|
||||
using System.Net.Http.Headers;
|
||||
using System.Text;
|
||||
|
||||
namespace AutoWorkshopShopApp
|
||||
{
|
||||
public class ApiClient
|
||||
{
|
||||
private static readonly HttpClient _client = new();
|
||||
|
||||
public static string? Password { get; set; }
|
||||
public static bool IsAuthenticated { get; private set; } = false;
|
||||
|
||||
public static bool TryAuthenticate(string Password)
|
||||
{
|
||||
if (Password == ApiClient.Password)
|
||||
{
|
||||
IsAuthenticated = true;
|
||||
}
|
||||
return IsAuthenticated;
|
||||
}
|
||||
|
||||
public static void Connect(IConfiguration Configuration)
|
||||
{
|
||||
Password = Configuration["Password"];
|
||||
_client.BaseAddress = new Uri(Configuration["IPAddress"]);
|
||||
_client.DefaultRequestHeaders.Accept.Clear();
|
||||
_client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
|
||||
}
|
||||
|
||||
public static T? GetRequest<T>(string RequestUrl)
|
||||
{
|
||||
var Response = _client.GetAsync(RequestUrl);
|
||||
var Result = Response.Result.Content.ReadAsStringAsync().Result;
|
||||
|
||||
if (Response.Result.IsSuccessStatusCode)
|
||||
{
|
||||
return JsonConvert.DeserializeObject<T>(Result);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Exception(Result);
|
||||
}
|
||||
}
|
||||
|
||||
public static void PostRequest<T>(string RequestUrl, T Model)
|
||||
{
|
||||
var Json = JsonConvert.SerializeObject(Model);
|
||||
var Data = new StringContent(Json, Encoding.UTF8, "application/json");
|
||||
|
||||
var Response = _client.PostAsync(RequestUrl, Data);
|
||||
|
||||
var Result = Response.Result.Content.ReadAsStringAsync().Result;
|
||||
if (!Response.Result.IsSuccessStatusCode)
|
||||
{
|
||||
throw new Exception(Result);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
18
AutoWorkshopShopApp/AutoWorkshopShopApp.csproj
Normal file
18
AutoWorkshopShopApp/AutoWorkshopShopApp.csproj
Normal file
@@ -0,0 +1,18 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\AutoWorkshopContracts\AutoWorkshopContracts.csproj" />
|
||||
<ProjectReference Include="..\AutoWorkshopDataModels\AutoWorkshopDataModels.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
175
AutoWorkshopShopApp/Controllers/HomeController.cs
Normal file
175
AutoWorkshopShopApp/Controllers/HomeController.cs
Normal file
@@ -0,0 +1,175 @@
|
||||
using AutoWorkshopContracts.BindingModels;
|
||||
using AutoWorkshopContracts.ViewModels;
|
||||
using AutoWorkshopShopApp.Models;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace AutoWorkshopShopApp.Controllers
|
||||
{
|
||||
public class HomeController : Controller
|
||||
{
|
||||
private readonly ILogger<HomeController> _logger;
|
||||
|
||||
public HomeController(ILogger<HomeController> Logger)
|
||||
{
|
||||
_logger = Logger;
|
||||
}
|
||||
|
||||
public IActionResult Index()
|
||||
{
|
||||
if (!ApiClient.IsAuthenticated)
|
||||
{
|
||||
return Redirect("~/Home/Enter");
|
||||
}
|
||||
return View(ApiClient.GetRequest<List<ShopViewModel>>("api/shop/getshoplist"));
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public IActionResult Enter()
|
||||
{
|
||||
return View();
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public void Enter(string Password)
|
||||
{
|
||||
if (string.IsNullOrEmpty(Password))
|
||||
{
|
||||
throw new Exception("Введите пароль");
|
||||
}
|
||||
if (!ApiClient.TryAuthenticate(Password))
|
||||
{
|
||||
throw new Exception("Неверный пароль");
|
||||
}
|
||||
|
||||
Response.Redirect("Index");
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public IActionResult Create()
|
||||
{
|
||||
if (!ApiClient.IsAuthenticated)
|
||||
{
|
||||
return Redirect("~/Home/Enter");
|
||||
}
|
||||
return View("Shop");
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public void Create(int Id, string ShopName, string Address, DateTime OpeningDate, int MaxCount)
|
||||
{
|
||||
if (!ApiClient.IsAuthenticated)
|
||||
{
|
||||
throw new Exception("Вход только авторизованным");
|
||||
}
|
||||
|
||||
if (string.IsNullOrEmpty(ShopName) || string.IsNullOrEmpty(Address))
|
||||
{
|
||||
throw new Exception("Название или адрес не может быть пустым");
|
||||
}
|
||||
if (MaxCount <= 0)
|
||||
{
|
||||
throw new Exception("Вместимость магазина должна быть больше нуля");
|
||||
}
|
||||
|
||||
ApiClient.PostRequest("api/shop/createshop", new ShopBindingModel
|
||||
{
|
||||
Id = Id,
|
||||
ShopName = ShopName,
|
||||
Address = Address,
|
||||
OpeningDate = OpeningDate,
|
||||
RepairsMaxCount = MaxCount
|
||||
});
|
||||
Response.Redirect("Index");
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public IActionResult Update(int Id)
|
||||
{
|
||||
if (!ApiClient.IsAuthenticated)
|
||||
{
|
||||
return Redirect("~/Home/Enter");
|
||||
}
|
||||
return View("Shop", ApiClient.GetRequest<ShopRepairsViewModel>($"api/shop/getshop?shopId={Id}"));
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public void Update(int Id, string ShopName, string Address, DateTime OpeningDate, int MaxCount)
|
||||
{
|
||||
if (!ApiClient.IsAuthenticated)
|
||||
{
|
||||
throw new Exception("Вход только авторизованным");
|
||||
}
|
||||
|
||||
if (string.IsNullOrEmpty(ShopName) || string.IsNullOrEmpty(Address))
|
||||
{
|
||||
throw new Exception("Название или адрес не может быть пустым");
|
||||
}
|
||||
if (MaxCount <= 0)
|
||||
{
|
||||
throw new Exception("Вместимость магазина должна быть больше нуля");
|
||||
}
|
||||
|
||||
ApiClient.PostRequest("api/shop/updateshop", new ShopBindingModel
|
||||
{
|
||||
Id = Id,
|
||||
ShopName = ShopName,
|
||||
Address = Address,
|
||||
OpeningDate = OpeningDate,
|
||||
RepairsMaxCount = MaxCount
|
||||
});
|
||||
Response.Redirect("Index");
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public void Delete(int Id)
|
||||
{
|
||||
if (!ApiClient.IsAuthenticated)
|
||||
{
|
||||
throw new Exception("Вход только авторизованным");
|
||||
}
|
||||
|
||||
ApiClient.PostRequest("api/shop/deleteshop", new ShopBindingModel
|
||||
{
|
||||
Id = Id,
|
||||
});
|
||||
Response.Redirect("Index");
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public IActionResult Supply()
|
||||
{
|
||||
if (!ApiClient.IsAuthenticated)
|
||||
{
|
||||
return Redirect("~/Home/Enter");
|
||||
}
|
||||
|
||||
ViewBag.Shops = ApiClient.GetRequest<List<ShopViewModel>>("api/shop/getshoplist");
|
||||
ViewBag.Repairs = ApiClient.GetRequest<List<RepairViewModel>>("api/main/getrepairlist");
|
||||
return View();
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public void Supply(int Shop, int Repair, int Count)
|
||||
{
|
||||
if (!ApiClient.IsAuthenticated)
|
||||
{
|
||||
throw new Exception("Вход только авторизованным");
|
||||
}
|
||||
|
||||
ApiClient.PostRequest("api/shop/makesupply", new SupplyBindingModel
|
||||
{
|
||||
ShopId = Shop,
|
||||
RepairId = Repair,
|
||||
Count = Count
|
||||
});
|
||||
Response.Redirect("Index");
|
||||
}
|
||||
|
||||
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
|
||||
public IActionResult Error()
|
||||
{
|
||||
return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
|
||||
}
|
||||
}
|
||||
}
|
||||
9
AutoWorkshopShopApp/Models/ErrorViewModel.cs
Normal file
9
AutoWorkshopShopApp/Models/ErrorViewModel.cs
Normal file
@@ -0,0 +1,9 @@
|
||||
namespace AutoWorkshopShopApp.Models
|
||||
{
|
||||
public class ErrorViewModel
|
||||
{
|
||||
public string? RequestId { get; set; }
|
||||
|
||||
public bool ShowRequestId => !string.IsNullOrEmpty(RequestId);
|
||||
}
|
||||
}
|
||||
30
AutoWorkshopShopApp/Program.cs
Normal file
30
AutoWorkshopShopApp/Program.cs
Normal file
@@ -0,0 +1,30 @@
|
||||
using AutoWorkshopShopApp;
|
||||
|
||||
var Builder = WebApplication.CreateBuilder(args);
|
||||
|
||||
// Add services to the container.
|
||||
Builder.Services.AddControllersWithViews();
|
||||
|
||||
var App = Builder.Build();
|
||||
ApiClient.Connect(Builder.Configuration);
|
||||
|
||||
// Configure the HTTP request pipeline.
|
||||
if (!App.Environment.IsDevelopment())
|
||||
{
|
||||
App.UseExceptionHandler("/Home/Error");
|
||||
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
|
||||
App.UseHsts();
|
||||
}
|
||||
|
||||
App.UseHttpsRedirection();
|
||||
App.UseStaticFiles();
|
||||
|
||||
App.UseRouting();
|
||||
|
||||
App.UseAuthorization();
|
||||
|
||||
App.MapControllerRoute(
|
||||
name: "default",
|
||||
pattern: "{controller=Home}/{action=Index}/{id?}");
|
||||
|
||||
App.Run();
|
||||
28
AutoWorkshopShopApp/Properties/launchSettings.json
Normal file
28
AutoWorkshopShopApp/Properties/launchSettings.json
Normal file
@@ -0,0 +1,28 @@
|
||||
{
|
||||
"iisSettings": {
|
||||
"windowsAuthentication": false,
|
||||
"anonymousAuthentication": true,
|
||||
"iisExpress": {
|
||||
"applicationUrl": "http://localhost:23243",
|
||||
"sslPort": 44379
|
||||
}
|
||||
},
|
||||
"profiles": {
|
||||
"AutoWorkshopShopApp": {
|
||||
"commandName": "Project",
|
||||
"dotnetRunMessages": true,
|
||||
"launchBrowser": true,
|
||||
"applicationUrl": "https://localhost:7068;http://localhost:5001",
|
||||
"environmentVariables": {
|
||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||
}
|
||||
},
|
||||
"IIS Express": {
|
||||
"commandName": "IISExpress",
|
||||
"launchBrowser": true,
|
||||
"environmentVariables": {
|
||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
15
AutoWorkshopShopApp/Views/Home/Enter.cshtml
Normal file
15
AutoWorkshopShopApp/Views/Home/Enter.cshtml
Normal file
@@ -0,0 +1,15 @@
|
||||
@{
|
||||
ViewData["Title"] = "Enter";
|
||||
}
|
||||
|
||||
<div class="text-center">
|
||||
<h2 class="display-4">Вход в систему</h2>
|
||||
</div>
|
||||
|
||||
<form method="post">
|
||||
<div class="mb-3">
|
||||
<label class="form-label">Пароль</label>
|
||||
<input class="form-control" type="password" name="password">
|
||||
</div>
|
||||
<input type="submit" value="Вход" class="btn btn-primary" />
|
||||
</form>
|
||||
68
AutoWorkshopShopApp/Views/Home/Index.cshtml
Normal file
68
AutoWorkshopShopApp/Views/Home/Index.cshtml
Normal file
@@ -0,0 +1,68 @@
|
||||
@using AutoWorkshopContracts.ViewModels
|
||||
|
||||
@model List<ShopViewModel>
|
||||
|
||||
@{
|
||||
ViewData["Title"] = "Home Page";
|
||||
}
|
||||
|
||||
<div class="text-center">
|
||||
<h1 class="display-4">Магазины</h1>
|
||||
</div>
|
||||
|
||||
|
||||
<div class="text-center ">
|
||||
<p>
|
||||
<a asp-action="Create">Создать магазин</a>
|
||||
</p>
|
||||
|
||||
<table class="table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>
|
||||
Номер
|
||||
</th>
|
||||
<th>
|
||||
Название
|
||||
</th>
|
||||
<th>
|
||||
Адрес
|
||||
</th>
|
||||
<th>
|
||||
Дата открытия
|
||||
</th>
|
||||
<th>
|
||||
Максимальная вместимость
|
||||
</th>
|
||||
<th>
|
||||
|
||||
</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@foreach (var Item in Model)
|
||||
{
|
||||
<tr>
|
||||
<td>
|
||||
@Html.DisplayFor(ModelItem => Item.Id)
|
||||
</td>
|
||||
<td>
|
||||
@Html.DisplayFor(ModelItem => Item.ShopName)
|
||||
</td>
|
||||
<td>
|
||||
@Html.DisplayFor(ModelItem => Item.Address)
|
||||
</td>
|
||||
<td>
|
||||
@Html.DisplayFor(ModelItem => Item.OpeningDate)
|
||||
</td>
|
||||
<td>
|
||||
@Html.DisplayFor(ModelItem => Item.RepairsMaxCount)
|
||||
</td>
|
||||
<td>
|
||||
<a class="btn btn-primary" asp-action="Update" asp-route-Id="@(Item.Id)" role="button">Изменить</a>
|
||||
</td>
|
||||
</tr>
|
||||
}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
75
AutoWorkshopShopApp/Views/Home/Shop.cshtml
Normal file
75
AutoWorkshopShopApp/Views/Home/Shop.cshtml
Normal file
@@ -0,0 +1,75 @@
|
||||
@using AutoWorkshopDataModels.Models;
|
||||
@using AutoWorkshopContracts.ViewModels;
|
||||
|
||||
@model ShopRepairsViewModel
|
||||
|
||||
@{
|
||||
ViewData["Title"] = "Shop";
|
||||
}
|
||||
|
||||
<div class="text-center">
|
||||
@{
|
||||
if (Model == null)
|
||||
{
|
||||
<h2 class="display-4">Создание магазина</h2>
|
||||
}
|
||||
else
|
||||
{
|
||||
<h2 class="display-4">Изменение магазина</h2>
|
||||
}
|
||||
}
|
||||
</div>
|
||||
|
||||
<form method="post">
|
||||
<div class="mb-3">
|
||||
<label class="form-label">Название</label>
|
||||
<input type="text" class="form-control" name="shopname" id="shopname" value="@(Model==null ? "" : Model.Shop?.ShopName)" />
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label class="form-label">Адрес</label>
|
||||
<input type="text" class="form-control" name="address" id="address" value="@(Model==null ? "" : Model.Shop?.Address)" />
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="startDate">Дата открытия</label>
|
||||
<input class="form-control" type="date" name="openingdate" id="openingdate" value="@(Model==null ? "" : Model.Shop?.OpeningDate.ToString("yyyy-MM-dd"))" />
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label class="form-label">Вместимость</label>
|
||||
<input type="number" min="0" step="1" pattern="[0-9]" class="form-control" name="maxcount" id="maxcount" value="@(Model==null ? "" : Model.Shop?.RepairsMaxCount)" />
|
||||
</div>
|
||||
<div class="mb-3 ">
|
||||
<input class="btn btn-primary" type="submit" value="Сохранить">
|
||||
@{
|
||||
if (Model != null && Model.Shop != null)
|
||||
{
|
||||
<input class="btn btn-danger" asp-action="Delete" type="submit" value="Удалить" asp-route-Id="@(Model==null ? 0 : Model.Shop.Id.ToString())">
|
||||
}
|
||||
}
|
||||
</div>
|
||||
</form>
|
||||
@{
|
||||
if (Model != null && Model.Shop != null)
|
||||
{
|
||||
<div>
|
||||
<h6>Содержимое магазина</h6>
|
||||
</div>
|
||||
<table class="table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Название</th>
|
||||
<th>Количество</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@foreach (var item in Model.ShopRepairs)
|
||||
{
|
||||
<tr>
|
||||
<td>@Html.DisplayFor(modelItem => item.Value.Repair.RepairName)</td>
|
||||
<td>@Html.DisplayFor(modelItem => item.Value.Count)</td>
|
||||
</tr>
|
||||
}
|
||||
</tbody>
|
||||
|
||||
</table>
|
||||
}
|
||||
}
|
||||
22
AutoWorkshopShopApp/Views/Home/Supply.cshtml
Normal file
22
AutoWorkshopShopApp/Views/Home/Supply.cshtml
Normal file
@@ -0,0 +1,22 @@
|
||||
@{
|
||||
ViewData["Title"] = "Supply";
|
||||
}
|
||||
<div class="text-center">
|
||||
<h2 class="display-4">Создание поставки</h2>
|
||||
</div>
|
||||
<form method="post">
|
||||
<div class="mb-3">
|
||||
<label class="form-label">Магазин</label>
|
||||
<select class="form-select form-select-lg" id="shop" name="shop" asp-items="@(new SelectList(@ViewBag.Shops,"Id", "ShopName"))"></select>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label class="form-label">Ремонт</label>
|
||||
<select class="form-select form-select-lg" id="repair" name="repair" asp-items="@(new SelectList(@ViewBag.Repairs,"Id", "RepairName"))"></select>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label class="form-label">Количество</label>
|
||||
<input type="number" min="0" step="1" pattern="[0-9]" class="form-control" name="count" id="count">
|
||||
</div>
|
||||
<input class="btn btn-success" type="submit" value="Создать поставку">
|
||||
<a class="btn btn-primary" href="./Index" role="button">Отмена</a>
|
||||
</form>
|
||||
25
AutoWorkshopShopApp/Views/Shared/Error.cshtml
Normal file
25
AutoWorkshopShopApp/Views/Shared/Error.cshtml
Normal file
@@ -0,0 +1,25 @@
|
||||
@model ErrorViewModel
|
||||
@{
|
||||
ViewData["Title"] = "Error";
|
||||
}
|
||||
|
||||
<h1 class="text-danger">Error.</h1>
|
||||
<h2 class="text-danger">An error occurred while processing your request.</h2>
|
||||
|
||||
@if (Model.ShowRequestId)
|
||||
{
|
||||
<p>
|
||||
<strong>Request ID:</strong> <code>@Model.RequestId</code>
|
||||
</p>
|
||||
}
|
||||
|
||||
<h3>Development Mode</h3>
|
||||
<p>
|
||||
Swapping to <strong>Development</strong> environment will display more detailed information about the error that occurred.
|
||||
</p>
|
||||
<p>
|
||||
<strong>The Development environment shouldn't be enabled for deployed applications.</strong>
|
||||
It can result in displaying sensitive information from exceptions to end users.
|
||||
For local debugging, enable the <strong>Development</strong> environment by setting the <strong>ASPNETCORE_ENVIRONMENT</strong> environment variable to <strong>Development</strong>
|
||||
and restarting the app.
|
||||
</p>
|
||||
49
AutoWorkshopShopApp/Views/Shared/_Layout.cshtml
Normal file
49
AutoWorkshopShopApp/Views/Shared/_Layout.cshtml
Normal file
@@ -0,0 +1,49 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>@ViewData["Title"] - AutoWorkshopShopApp</title>
|
||||
<link rel="stylesheet" href="~/lib/bootstrap/dist/css/bootstrap.min.css" />
|
||||
<link rel="stylesheet" href="~/css/site.css" asp-append-version="true" />
|
||||
<link rel="stylesheet" href="~/AutoWorkshopShopApp.styles.css" asp-append-version="true" />
|
||||
</head>
|
||||
<body>
|
||||
<header>
|
||||
<nav class="navbar navbar-expand-sm navbar-toggleable-sm navbar-light bg-white border-bottom box-shadow mb-3">
|
||||
<div class="container-fluid">
|
||||
<a class="navbar-brand" asp-area="" asp-controller="Home" asp-action="Index">AutoWorkshopShopsApi</a>
|
||||
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target=".navbar-collapse" aria-controls="navbarSupportedContent"
|
||||
aria-expanded="false" aria-label="Toggle navigation">
|
||||
<span class="navbar-toggler-icon"></span>
|
||||
</button>
|
||||
<div class="navbar-collapse collapse d-sm-inline-flex justify-content-between">
|
||||
<ul class="navbar-nav flex-grow-1">
|
||||
<li class="nav-item">
|
||||
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="Index">Главная</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="Supply">Поставка</a>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</nav>
|
||||
</header>
|
||||
<div class="container">
|
||||
<main role="main" class="pb-3">
|
||||
@RenderBody()
|
||||
</main>
|
||||
</div>
|
||||
|
||||
<footer class="border-top footer text-muted">
|
||||
<div class="container">
|
||||
© 2024 - AutoWorkshop - <a asp-area="" asp-controller="Home" asp-action="Index">Главная</a>
|
||||
</div>
|
||||
</footer>
|
||||
<script src="~/lib/jquery/dist/jquery.min.js"></script>
|
||||
<script src="~/lib/bootstrap/dist/js/bootstrap.bundle.min.js"></script>
|
||||
<script src="~/js/site.js" asp-append-version="true"></script>
|
||||
@await RenderSectionAsync("Scripts", required: false)
|
||||
</body>
|
||||
</html>
|
||||
49
AutoWorkshopShopApp/Views/Shared/_Layout.cshtml.css
Normal file
49
AutoWorkshopShopApp/Views/Shared/_Layout.cshtml.css
Normal file
@@ -0,0 +1,49 @@
|
||||
/* Please see documentation at https://docs.microsoft.com/aspnet/core/client-side/bundling-and-minification
|
||||
for details on configuring this project to bundle and minify static web assets. */
|
||||
|
||||
a.navbar-brand {
|
||||
white-space: normal;
|
||||
text-align: center;
|
||||
word-break: break-all;
|
||||
}
|
||||
|
||||
a {
|
||||
color: #0077cc;
|
||||
}
|
||||
|
||||
.btn-primary {
|
||||
color: #fff;
|
||||
background-color: #1b6ec2;
|
||||
border-color: #1861ac;
|
||||
}
|
||||
|
||||
.nav-pills .nav-link.active, .nav-pills .show > .nav-link {
|
||||
color: #fff;
|
||||
background-color: #1b6ec2;
|
||||
border-color: #1861ac;
|
||||
}
|
||||
|
||||
.border-top {
|
||||
border-top: 1px solid #e5e5e5;
|
||||
}
|
||||
|
||||
.border-bottom {
|
||||
border-bottom: 1px solid #e5e5e5;
|
||||
}
|
||||
|
||||
.box-shadow {
|
||||
box-shadow: 0 .25rem .75rem rgba(0, 0, 0, .05);
|
||||
}
|
||||
|
||||
button.accept-policy {
|
||||
font-size: 1rem;
|
||||
line-height: inherit;
|
||||
}
|
||||
|
||||
.footer {
|
||||
position: absolute;
|
||||
bottom: 0;
|
||||
width: 100%;
|
||||
white-space: nowrap;
|
||||
line-height: 60px;
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
<script src="~/lib/jquery-validation/dist/jquery.validate.min.js"></script>
|
||||
<script src="~/lib/jquery-validation-unobtrusive/jquery.validate.unobtrusive.min.js"></script>
|
||||
3
AutoWorkshopShopApp/Views/_ViewImports.cshtml
Normal file
3
AutoWorkshopShopApp/Views/_ViewImports.cshtml
Normal file
@@ -0,0 +1,3 @@
|
||||
@using AutoWorkshopShopApp
|
||||
@using AutoWorkshopShopApp.Models
|
||||
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
|
||||
3
AutoWorkshopShopApp/Views/_ViewStart.cshtml
Normal file
3
AutoWorkshopShopApp/Views/_ViewStart.cshtml
Normal file
@@ -0,0 +1,3 @@
|
||||
@{
|
||||
Layout = "_Layout";
|
||||
}
|
||||
8
AutoWorkshopShopApp/appsettings.Development.json
Normal file
8
AutoWorkshopShopApp/appsettings.Development.json
Normal file
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
"Default": "Information",
|
||||
"Microsoft.AspNetCore": "Warning"
|
||||
}
|
||||
}
|
||||
}
|
||||
11
AutoWorkshopShopApp/appsettings.json
Normal file
11
AutoWorkshopShopApp/appsettings.json
Normal file
@@ -0,0 +1,11 @@
|
||||
{
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
"Default": "Information",
|
||||
"Microsoft.AspNetCore": "Warning"
|
||||
}
|
||||
},
|
||||
"AllowedHosts": "*",
|
||||
"IPAddress": "http://localhost:5224/",
|
||||
"Password": "admin"
|
||||
}
|
||||
18
AutoWorkshopShopApp/wwwroot/css/site.css
Normal file
18
AutoWorkshopShopApp/wwwroot/css/site.css
Normal file
@@ -0,0 +1,18 @@
|
||||
html {
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
@media (min-width: 768px) {
|
||||
html {
|
||||
font-size: 16px;
|
||||
}
|
||||
}
|
||||
|
||||
html {
|
||||
position: relative;
|
||||
min-height: 100%;
|
||||
}
|
||||
|
||||
body {
|
||||
margin-bottom: 60px;
|
||||
}
|
||||
BIN
AutoWorkshopShopApp/wwwroot/favicon.ico
Normal file
BIN
AutoWorkshopShopApp/wwwroot/favicon.ico
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 5.3 KiB |
4
AutoWorkshopShopApp/wwwroot/js/site.js
Normal file
4
AutoWorkshopShopApp/wwwroot/js/site.js
Normal file
@@ -0,0 +1,4 @@
|
||||
// Please see documentation at https://docs.microsoft.com/aspnet/core/client-side/bundling-and-minification
|
||||
// for details on configuring this project to bundle and minify static web assets.
|
||||
|
||||
// Write your JavaScript code.
|
||||
22
AutoWorkshopShopApp/wwwroot/lib/bootstrap/LICENSE
Normal file
22
AutoWorkshopShopApp/wwwroot/lib/bootstrap/LICENSE
Normal file
@@ -0,0 +1,22 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2011-2021 Twitter, Inc.
|
||||
Copyright (c) 2011-2021 The Bootstrap Authors
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
4997
AutoWorkshopShopApp/wwwroot/lib/bootstrap/dist/css/bootstrap-grid.css
vendored
Normal file
4997
AutoWorkshopShopApp/wwwroot/lib/bootstrap/dist/css/bootstrap-grid.css
vendored
Normal file
File diff suppressed because it is too large
Load Diff
1
AutoWorkshopShopApp/wwwroot/lib/bootstrap/dist/css/bootstrap-grid.css.map
vendored
Normal file
1
AutoWorkshopShopApp/wwwroot/lib/bootstrap/dist/css/bootstrap-grid.css.map
vendored
Normal file
File diff suppressed because one or more lines are too long
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user