AutoWorkshopImplement project

This commit is contained in:
ShabOl 2024-02-20 23:14:51 +04:00
parent 05d759ac94
commit 63a6e7f705
26 changed files with 1044 additions and 42 deletions

View File

@ -5,9 +5,13 @@ VisualStudioVersion = 17.8.34511.84
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AutoWorkshop", "AutoWorkshop\AutoWorkshop.csproj", "{54087BAE-4821-4266-9968-190F9F4355C8}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AutoWorkshopDataModels", "AutoWorkshopDataModels\AutoWorkshopDataModels.csproj", "{D52094D2-A57E-4BAD-B049-3B64065463DA}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AutoWorkshopDataModels", "AutoWorkshopDataModels\AutoWorkshopDataModels.csproj", "{D52094D2-A57E-4BAD-B049-3B64065463DA}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AutoWorkshopContracts", "AutoWorkshopContracts\AutoWorkshopContracts.csproj", "{93CF1C25-57B5-4E95-A394-E01AE440E138}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AutoWorkshopContracts", "AutoWorkshopContracts\AutoWorkshopContracts.csproj", "{93CF1C25-57B5-4E95-A394-E01AE440E138}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AutoWorkshopBusinessLogic", "AutoWorkshopBusinessLogic\AutoWorkshopBusinessLogic.csproj", "{132C30F4-07B1-4D1A-99C0-0A8E538EB2D8}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AutoWorkshopImplement", "AutoWorkshopImplement\AutoWorkshopImplement.csproj", "{B564F5E8-2F14-4816-8481-1F9649F1F414}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@ -27,6 +31,14 @@ Global
{93CF1C25-57B5-4E95-A394-E01AE440E138}.Debug|Any CPU.Build.0 = Debug|Any CPU
{93CF1C25-57B5-4E95-A394-E01AE440E138}.Release|Any CPU.ActiveCfg = Release|Any CPU
{93CF1C25-57B5-4E95-A394-E01AE440E138}.Release|Any CPU.Build.0 = Release|Any CPU
{132C30F4-07B1-4D1A-99C0-0A8E538EB2D8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{132C30F4-07B1-4D1A-99C0-0A8E538EB2D8}.Debug|Any CPU.Build.0 = Debug|Any CPU
{132C30F4-07B1-4D1A-99C0-0A8E538EB2D8}.Release|Any CPU.ActiveCfg = Release|Any CPU
{132C30F4-07B1-4D1A-99C0-0A8E538EB2D8}.Release|Any CPU.Build.0 = Release|Any CPU
{B564F5E8-2F14-4816-8481-1F9649F1F414}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{B564F5E8-2F14-4816-8481-1F9649F1F414}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B564F5E8-2F14-4816-8481-1F9649F1F414}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B564F5E8-2F14-4816-8481-1F9649F1F414}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE

View File

@ -0,0 +1,17 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Logging" Version="8.0.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\AutoWorkshopContracts\AutoWorkshopContracts.csproj" />
</ItemGroup>
</Project>

View File

@ -0,0 +1,125 @@
using AutoWorkshopContracts.BindingModels;
using AutoWorkshopContracts.BusinessLogicContracts;
using AutoWorkshopContracts.SearchModels;
using AutoWorkshopContracts.StoragesContracts;
using AutoWorkshopContracts.ViewModels;
using Microsoft.Extensions.Logging;
namespace AutoWorkshopBusinessLogic.BusinessLogics
{
public class ComponentLogic : IComponentLogic
{
private readonly ILogger _logger;
private readonly IComponentStorage _componentStorage;
public ComponentLogic(ILogger<ComponentLogic> Logger, IComponentStorage ComponentStorage)
{
_logger = Logger;
_componentStorage = ComponentStorage;
}
public List<ComponentViewModel>? ReadList(ComponentSearchModel? Model)
{
_logger.LogInformation("ReadList. ComponentName:{ComponentName}. Id:{Id}",
Model?.ComponentName, Model?.Id);
var List = Model is null ? _componentStorage.GetFullList() : _componentStorage.GetFilteredList(Model);
if (List is null)
{
_logger.LogWarning("ReadList return null list");
return null;
}
_logger.LogInformation("ReadList. Count:{Count}", List.Count);
return List;
}
public ComponentViewModel? ReadElement(ComponentSearchModel? Model)
{
if (Model is null)
throw new ArgumentNullException(nameof(Model));
_logger.LogInformation("ReadElement. ComponentName:{ComponentName}. Id:{Id}",
Model.ComponentName, Model.Id);
var Element = _componentStorage.GetElement(Model);
if (Element is null)
{
_logger.LogWarning("ReadElement element not found");
return null;
}
_logger.LogInformation("ReadElement element found. Id:{Id}", Element.Id);
return Element;
}
public bool Create(ComponentBindingModel Model)
{
CheckModel(Model);
if (_componentStorage.Insert(Model) is null)
{
_logger.LogWarning("Insert operation failed");
return false;
}
return true;
}
public bool Update(ComponentBindingModel Model)
{
CheckModel(Model);
if (_componentStorage.Update(Model) is null)
{
_logger.LogWarning("Update operation failed");
return false;
}
return true;
}
public bool Delete(ComponentBindingModel Model)
{
CheckModel(Model);
_logger.LogInformation("Delete. Id:{Id}", Model.Id);
if (_componentStorage.Delete(Model) is null)
{
_logger.LogWarning("Delete operation failed");
return false;
}
return true;
}
private void CheckModel(ComponentBindingModel Model, bool WithParams = true)
{
if (Model == null)
throw new ArgumentNullException(nameof(Model));
if (!WithParams)
return;
if (string.IsNullOrEmpty(Model.ComponentName))
throw new ArgumentNullException("Нет названия компонента", nameof(Model.ComponentName));
if (Model.Cost <= 0)
throw new ArgumentNullException("Цена компонента должна быть больше 0", nameof(Model.Cost));
_logger.LogInformation("Repair. ComponentName:{ComponentName}. Cost:{Cost}. Id:{Id}",
Model.ComponentName, Model.Cost, Model.Id);
var Element = _componentStorage.GetElement(new ComponentSearchModel
{
ComponentName = Model.ComponentName
});
if (Element != null && Element.Id != Model.Id)
throw new InvalidOperationException("Компонент с таким названием уже есть");
}
}
}

View File

@ -0,0 +1,152 @@
using AutoWorkshopContracts.BindingModels;
using AutoWorkshopContracts.BusinessLogicContracts;
using AutoWorkshopContracts.SearchModels;
using AutoWorkshopContracts.StoragesContracts;
using AutoWorkshopContracts.ViewModels;
using AutoWorkshopDataModels.Enums;
using Microsoft.Extensions.Logging;
namespace AutoWorkshopBusinessLogic.BusinessLogics
{
public class OrderLogic : IOrderLogic
{
private readonly ILogger _logger;
private readonly IOrderStorage _orderStorage;
public OrderLogic(ILogger<RepairLogic> Logger, IOrderStorage OrderStorage)
{
_logger = Logger;
_orderStorage = OrderStorage;
}
public List<OrderViewModel>? ReadList(OrderSearchModel? Model)
{
_logger.LogInformation("ReadList. Id:{Id}", 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);
if (_orderStorage.Insert(Model) is null)
{
_logger.LogWarning("Insert operation failed");
return false;
}
return true;
}
public bool TakeOrderInWork(OrderBindingModel Model)
{
CheckModel(Model);
var Element = _orderStorage.GetElement(new OrderSearchModel
{
Id = Model.Id
});
if (Element is null)
throw new InvalidOperationException("Заказ с таким идентификатором не существует");
if (Element.Status != OrderStatus.Accepted)
{
_logger.LogWarning("TakeOrderInWork. Invalid status");
return false;
}
if (_orderStorage.Update(Model) is null)
{
_logger.LogWarning("Update operation failed");
return false;
}
return true;
}
public bool FinishOrder(OrderBindingModel Model)
{
CheckModel(Model);
var Element = _orderStorage.GetElement(new OrderSearchModel
{
Id = Model.Id
});
if (Element is null)
throw new InvalidOperationException("Заказ с таким идентификатором не существует");
if (Element.Status != OrderStatus.BeingProcessed)
{
_logger.LogWarning("FinishOrder. Invalid status");
return false;
}
if (_orderStorage.Update(Model) is null)
{
_logger.LogWarning("Update operation failed");
return false;
}
return true;
}
public bool DeliveryOrder(OrderBindingModel Model)
{
CheckModel(Model);
var Element = _orderStorage.GetElement(new OrderSearchModel
{
Id = Model.Id
});
if (Element is null)
throw new InvalidOperationException("Заказ с таким идентификатором не существует");
if (Element.Status != OrderStatus.Ready)
{
_logger.LogWarning("DeliveryOrder. Invalid status");
return false;
}
if (_orderStorage.Update(Model) is null)
{
_logger.LogWarning("Update operation failed");
return false;
}
return true;
}
private void CheckModel(OrderBindingModel Model, bool WithParams = true)
{
if (Model == null)
throw new ArgumentNullException(nameof(Model));
if (!WithParams)
return;
if (Model.Count <= 0)
throw new ArgumentNullException("Количество ремонтов в заказе быть больше 0", nameof(Model.Count));
if (Model.Sum <= 0)
throw new ArgumentNullException("Стоимость заказа должна быть больше 0", nameof(Model.Sum));
_logger.LogInformation("Order. RepairId:{RepairId}. Count:{Count}. Sum:{Sum}. " +
"Status:{Status}. DateCreate:{DateCreate}. DateImplement:{DateImplement}. Id: {Id}",
Model.RepairId, Model.Count, Model.Sum, Model.Status, Model.DateCreate,
Model.DateImplement, Model.Id);
}
}
}

View File

@ -0,0 +1,125 @@
using AutoWorkshopContracts.BindingModels;
using AutoWorkshopContracts.BusinessLogicContracts;
using AutoWorkshopContracts.SearchModels;
using AutoWorkshopContracts.StoragesContracts;
using AutoWorkshopContracts.ViewModels;
using Microsoft.Extensions.Logging;
namespace AutoWorkshopBusinessLogic.BusinessLogics
{
public class RepairLogic : IRepairLogic
{
private readonly ILogger _logger;
private readonly IRepairStorage _repairStorage;
public RepairLogic(ILogger<RepairLogic> Logger, IRepairStorage RepairStorage)
{
_logger = Logger;
_repairStorage = RepairStorage;
}
public List<RepairViewModel>? ReadList(RepairSearchModel? Model)
{
_logger.LogInformation("ReadList. RepairName:{RepairName}. Id:{Id}",
Model?.RepairName, Model?.Id);
var List = Model is null ? _repairStorage.GetFullList() : _repairStorage.GetFilteredList(Model);
if (List is null)
{
_logger.LogWarning("ReadList return null list");
return null;
}
_logger.LogInformation("ReadList. Count:{Count}", List.Count);
return List;
}
public RepairViewModel? ReadElement(RepairSearchModel? Model)
{
if (Model is null)
throw new ArgumentNullException(nameof(Model));
_logger.LogInformation("ReadElement. RepairName:{RepairName}. Id:{Id}",
Model.RepairName, Model.Id);
var Element = _repairStorage.GetElement(Model);
if (Element is null)
{
_logger.LogWarning("ReadElement element not found");
return null;
}
_logger.LogInformation("ReadElement element found. Id:{Id}", Element.Id);
return Element;
}
public bool Create(RepairBindingModel Model)
{
CheckModel(Model);
if (_repairStorage.Insert(Model) is null)
{
_logger.LogWarning("Insert operation failed");
return false;
}
return true;
}
public bool Update(RepairBindingModel Model)
{
CheckModel(Model);
if (_repairStorage.Update(Model) is null)
{
_logger.LogWarning("Update operation failed");
return false;
}
return true;
}
public bool Delete(RepairBindingModel Model)
{
CheckModel(Model);
_logger.LogInformation("Delete. Id:{Id}", Model.Id);
if (_repairStorage.Delete(Model) is null)
{
_logger.LogWarning("Delete operation failed");
return false;
}
return true;
}
private void CheckModel(RepairBindingModel Model, bool WithParams = true)
{
if (Model == null)
throw new ArgumentNullException(nameof(Model));
if (!WithParams)
return;
if (string.IsNullOrEmpty(Model.RepairName))
throw new ArgumentNullException("Нет названия ремонта", nameof(Model.RepairName));
if (Model.Price <= 0)
throw new ArgumentNullException("Стоимость ремонта должна быть больше 0", nameof(Model.Price));
_logger.LogInformation("Repair. RepairName:{RepairName}. Price:{Price}. Id: {Id}",
Model.RepairName, Model.Price, Model.Id);
var Element = _repairStorage.GetElement(new RepairSearchModel
{
RepairName = Model.RepairName
});
if (Element != null && Element.Id != Model.Id)
throw new InvalidOperationException("Ремонт с таким названием уже есть");
}
}
}

View File

@ -6,7 +6,7 @@ namespace AutoWorkshopContracts.BindingModels
public class OrderBindingModel : IOrderModel
{
public int Id { get; set; }
public int ProductId { get; set; }
public int RepairId { get; set; }
public int Count { get; set; }
public double Sum { get; set; }
public OrderStatus Status { get; set; } = OrderStatus.Undefined;

View File

@ -6,11 +6,10 @@ namespace AutoWorkshopContracts.BusinessLogicContracts
{
public interface IComponentLogic
{
List<ComponentViewModel>? ReadList(ComponentSearchModel? model);
ComponentViewModel? ReadElement(ComponentSearchModel model);
bool Create(ComponentBindingModel model);
bool Update(ComponentBindingModel model);
bool Delete(ComponentBindingModel model);
List<ComponentViewModel>? ReadList(ComponentSearchModel? Model);
ComponentViewModel? ReadElement(ComponentSearchModel Model);
bool Create(ComponentBindingModel Model);
bool Update(ComponentBindingModel Model);
bool Delete(ComponentBindingModel Model);
}
}

View File

@ -6,10 +6,10 @@ namespace AutoWorkshopContracts.BusinessLogicContracts
{
public interface IOrderLogic
{
List<OrderViewModel>? ReadList(OrderSearchModel? model);
bool CreateOrder(OrderBindingModel model);
bool TakeOrderInWork(OrderBindingModel model);
bool FinishOrder(OrderBindingModel model);
bool DeliveryOrder(OrderBindingModel model);
List<OrderViewModel>? ReadList(OrderSearchModel? Model);
bool CreateOrder(OrderBindingModel Model);
bool TakeOrderInWork(OrderBindingModel Model);
bool FinishOrder(OrderBindingModel Model);
bool DeliveryOrder(OrderBindingModel Model);
}
}

View File

@ -6,10 +6,10 @@ namespace AutoWorkshopContracts.BusinessLogicContracts
{
public interface IRepairLogic
{
List<RepairViewModel>? ReadList(RepairSearchModel? model);
RepairViewModel? ReadElement(RepairSearchModel model);
bool Create(RepairBindingModel model);
bool Update(RepairBindingModel model);
bool Delete(RepairBindingModel model);
List<RepairViewModel>? ReadList(RepairSearchModel? Model);
RepairViewModel? ReadElement(RepairSearchModel Model);
bool Create(RepairBindingModel Model);
bool Update(RepairBindingModel Model);
bool Delete(RepairBindingModel Model);
}
}

View File

@ -7,11 +7,10 @@ namespace AutoWorkshopContracts.StoragesContracts
public interface IComponentStorage
{
List<ComponentViewModel> GetFullList();
List<ComponentViewModel> GetFilteredList(ComponentSearchModel model);
ComponentViewModel? GetElement(ComponentSearchModel model);
ComponentViewModel? Insert(ComponentBindingModel model);
ComponentViewModel? Update(ComponentBindingModel model);
ComponentViewModel? Delete(ComponentBindingModel model);
List<ComponentViewModel> GetFilteredList(ComponentSearchModel Model);
ComponentViewModel? GetElement(ComponentSearchModel Model);
ComponentViewModel? Insert(ComponentBindingModel Model);
ComponentViewModel? Update(ComponentBindingModel Model);
ComponentViewModel? Delete(ComponentBindingModel Model);
}
}

View File

@ -7,10 +7,10 @@ namespace AutoWorkshopContracts.StoragesContracts
public interface IOrderStorage
{
List<OrderViewModel> GetFullList();
List<OrderViewModel> GetFilteredList(OrderSearchModel model);
OrderViewModel? GetElement(OrderSearchModel model);
OrderViewModel? Insert(OrderBindingModel model);
OrderViewModel? Update(OrderBindingModel model);
OrderViewModel? Delete(OrderBindingModel model);
List<OrderViewModel> GetFilteredList(OrderSearchModel Model);
OrderViewModel? GetElement(OrderSearchModel Model);
OrderViewModel? Insert(OrderBindingModel Model);
OrderViewModel? Update(OrderBindingModel Model);
OrderViewModel? Delete(OrderBindingModel Model);
}
}

View File

@ -1,15 +1,16 @@
using AutoWorkshopContracts.SearchModels;
using AutoWorkshopContracts.BindingModels;
using AutoWorkshopContracts.SearchModels;
using AutoWorkshopContracts.ViewModels;
namespace AutoWorkshopContracts.StoragesContracts
{
public interface IProductStorage
public interface IRepairStorage
{
List<RepairViewModel> GetFullList();
List<RepairViewModel> GetFilteredList(RepairSearchModel model);
RepairViewModel? GetElement(RepairSearchModel model);
RepairViewModel? Insert(RepairSearchModel model);
RepairViewModel? Update(RepairSearchModel model);
RepairViewModel? Delete(RepairSearchModel model);
List<RepairViewModel> GetFilteredList(RepairSearchModel Model);
RepairViewModel? GetElement(RepairSearchModel Model);
RepairViewModel? Insert(RepairBindingModel Model);
RepairViewModel? Update(RepairBindingModel Model);
RepairViewModel? Delete(RepairBindingModel Model);
}
}

View File

@ -9,10 +9,10 @@ namespace AutoWorkshopContracts.ViewModels
[DisplayName("Номер")]
public int Id { get; set; }
public int ProductId { get; set; }
public int RepairId { get; set; }
[DisplayName("Изделие")]
public string ProductName { get; set; } = string.Empty;
[DisplayName("Ремонт")]
public string RepairName { get; set; } = string.Empty;
[DisplayName("Количество")]
public int Count { get; set; }

View File

@ -6,6 +6,6 @@
Accepted,
BeingProcessed,
Ready,
Issued,
Delivered,
}
}

View File

@ -4,7 +4,7 @@ namespace AutoWorkshopDataModels.Models
{
public interface IOrderModel : IId
{
int ProductId { get; }
int RepairId { get; }
int Count { get; }
double Sum { get; }
OrderStatus Status { get; }

View File

@ -0,0 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\AutoWorkshopContracts\AutoWorkshopContracts.csproj" />
<ProjectReference Include="..\AutoWorkshopDataModels\AutoWorkshopDataModels.csproj" />
</ItemGroup>
</Project>

View File

@ -0,0 +1,32 @@
using AutoWorkshopImplement.Models;
namespace AutoWorkshopImplement
{
public class DataListSingleton
{
private static DataListSingleton? _instance;
public List<Component> Components { get; set; }
public List<Order> Orders { get; set; }
public List<Repair> Repairs { get; set; }
private DataListSingleton()
{
Components = new List<Component>();
Orders = new List<Order>();
Repairs = new List<Repair>();
}
public static DataListSingleton GetInstance()
{
if (_instance == null)
{
_instance = new DataListSingleton();
}
return _instance;
}
}
}

View File

@ -0,0 +1,116 @@
using AutoWorkshopContracts.BindingModels;
using AutoWorkshopContracts.SearchModels;
using AutoWorkshopContracts.StoragesContracts;
using AutoWorkshopContracts.ViewModels;
using AutoWorkshopImplement.Models;
namespace AutoWorkshopImplement.Implements
{
public class ComponentStorage : IComponentStorage
{
private readonly DataListSingleton _source;
public ComponentStorage()
{
_source = DataListSingleton.GetInstance();
}
public List<ComponentViewModel> GetFullList()
{
var Result = new List<ComponentViewModel>();
foreach (var Component in _source.Components)
{
Result.Add(Component.GetViewModel);
}
return Result;
}
public List<ComponentViewModel> GetFilteredList(ComponentSearchModel Model)
{
var Result = new List<ComponentViewModel>();
if (string.IsNullOrEmpty(Model.ComponentName))
return Result;
foreach (var Component in _source.Components)
{
if (Component.ComponentName.Contains(Model.ComponentName))
{
Result.Add(Component.GetViewModel);
}
}
return Result;
}
public ComponentViewModel? GetElement(ComponentSearchModel Model)
{
if (string.IsNullOrEmpty(Model.ComponentName) && !Model.Id.HasValue)
return null;
foreach (var Component in _source.Components)
{
if ((!string.IsNullOrEmpty(Model.ComponentName)
&& Component.ComponentName == Model.ComponentName)
|| (Model.Id.HasValue && Component.Id == Model.Id))
{
return Component.GetViewModel;
}
}
return null;
}
public ComponentViewModel? Insert(ComponentBindingModel Model)
{
Model.Id = 1;
foreach (var Component in _source.Components)
{
if (Model.Id <= Component.Id)
{
Model.Id = Component.Id + 1;
}
}
var NewComponent = Component.Create(Model);
if (NewComponent == null)
return null;
_source.Components.Add(NewComponent);
return NewComponent.GetViewModel;
}
public ComponentViewModel? Update(ComponentBindingModel Model)
{
foreach (var Component in _source.Components)
{
if (Component.Id == Model.Id)
{
Component.Update(Model);
return Component.GetViewModel;
}
}
return null;
}
public ComponentViewModel? Delete(ComponentBindingModel Model)
{
for (int i = 0; i < _source.Components.Count; ++i)
{
if (_source.Components[i].Id == Model.Id)
{
var Element = _source.Components[i];
_source.Components.RemoveAt(i);
return Element.GetViewModel;
}
}
return null;
}
}
}

View File

@ -0,0 +1,116 @@
using AutoWorkshopContracts.BindingModels;
using AutoWorkshopContracts.SearchModels;
using AutoWorkshopContracts.StoragesContracts;
using AutoWorkshopContracts.ViewModels;
using AutoWorkshopImplement.Models;
namespace AutoWorkshopImplement.Implements
{
public class OrderStorage : IOrderStorage
{
private readonly DataListSingleton _source;
public OrderStorage()
{
_source = DataListSingleton.GetInstance();
}
public List<OrderViewModel> GetFullList()
{
var Result = new List<OrderViewModel>();
foreach (var Order in _source.Orders)
{
Result.Add(Order.GetViewModel);
}
return Result;
}
public List<OrderViewModel> GetFilteredList(OrderSearchModel Model)
{
var Result = new List<OrderViewModel>();
if (!Model.Id.HasValue)
return Result;
foreach (var Order in _source.Orders)
{
if (Order.Id == Model.Id)
{
Result.Add(Order.GetViewModel);
break;
}
}
return Result;
}
public OrderViewModel? GetElement(OrderSearchModel Model)
{
if (!Model.Id.HasValue)
return null;
foreach (var Order in _source.Orders)
{
if (Order.Id == Model.Id)
{
return Order.GetViewModel;
}
}
return null;
}
public OrderViewModel? Insert(OrderBindingModel Model)
{
Model.Id = 1;
foreach (var Order in _source.Orders)
{
if (Model.Id <= Order.Id)
{
Model.Id = Order.Id + 1;
}
}
var NewOrder = Order.Create(Model);
if (NewOrder == null)
return null;
_source.Orders.Add(NewOrder);
return NewOrder.GetViewModel;
}
public OrderViewModel? Update(OrderBindingModel Model)
{
foreach (var Order in _source.Orders)
{
if (Order.Id == Model.Id)
{
Order.Update(Model);
return Order.GetViewModel;
}
}
return null;
}
public OrderViewModel? Delete(OrderBindingModel Model)
{
for (int i = 0; i < _source.Orders.Count; ++i)
{
if (_source.Orders[i].Id == Model.Id)
{
var Element = _source.Orders[i];
_source.Orders.RemoveAt(i);
return Element.GetViewModel;
}
}
return null;
}
}
}

View File

@ -0,0 +1,116 @@
using AutoWorkshopContracts.BindingModels;
using AutoWorkshopContracts.SearchModels;
using AutoWorkshopContracts.StoragesContracts;
using AutoWorkshopContracts.ViewModels;
using AutoWorkshopImplement.Models;
namespace AutoWorkshopImplement.Implements
{
public class RepairStorage : IRepairStorage
{
private readonly DataListSingleton _source;
public RepairStorage()
{
_source = DataListSingleton.GetInstance();
}
public List<RepairViewModel> GetFullList()
{
var Result = new List<RepairViewModel>();
foreach (var Repair in _source.Repairs)
{
Result.Add(Repair.GetViewModel);
}
return Result;
}
public List<RepairViewModel> GetFilteredList(RepairSearchModel Model)
{
var Result = new List<RepairViewModel>();
if (string.IsNullOrEmpty(Model.RepairName))
return Result;
foreach (var Repair in _source.Repairs)
{
if (Repair.RepairName.Contains(Model.RepairName))
{
Result.Add(Repair.GetViewModel);
}
}
return Result;
}
public RepairViewModel? GetElement(RepairSearchModel Model)
{
if (string.IsNullOrEmpty(Model.RepairName) && !Model.Id.HasValue)
return null;
foreach (var Repair in _source.Repairs)
{
if ((!string.IsNullOrEmpty(Model.RepairName)
&& Repair.RepairName == Model.RepairName)
|| (Model.Id.HasValue && Repair.Id == Model.Id))
{
return Repair.GetViewModel;
}
}
return null;
}
public RepairViewModel? Insert(RepairBindingModel Model)
{
Model.Id = 1;
foreach (var Repair in _source.Repairs)
{
if (Model.Id <= Repair.Id)
{
Model.Id = Repair.Id + 1;
}
}
var NewRepair = Repair.Create(Model);
if (NewRepair == null)
return null;
_source.Repairs.Add(NewRepair);
return NewRepair.GetViewModel;
}
public RepairViewModel? Update(RepairBindingModel Model)
{
foreach (var Repair in _source.Repairs)
{
if (Repair.Id == Model.Id)
{
Repair.Update(Model);
return Repair.GetViewModel;
}
}
return null;
}
public RepairViewModel? Delete(RepairBindingModel Model)
{
for (int i = 0; i < _source.Repairs.Count; ++i)
{
if (_source.Repairs[i].Id == Model.Id)
{
var Element = _source.Repairs[i];
_source.Repairs.RemoveAt(i);
return Element.GetViewModel;
}
}
return null;
}
}
}

View File

@ -0,0 +1,44 @@
using AutoWorkshopContracts.BindingModels;
using AutoWorkshopContracts.ViewModels;
using AutoWorkshopDataModels.Models;
namespace AutoWorkshopImplement.Models
{
public class Component : IComponentModel
{
public int Id { get; private set; }
public string ComponentName { get; private set; } = string.Empty;
public double Cost { get; set; }
public static Component? Create(ComponentBindingModel? Model)
{
if (Model is null)
return null;
return new Component()
{
Id = Model.Id,
ComponentName = Model.ComponentName,
Cost = Model.Cost
};
}
public void Update(ComponentBindingModel? Model)
{
if (Model is null)
return;
ComponentName = Model.ComponentName;
Cost = Model.Cost;
}
public ComponentViewModel GetViewModel => new()
{
Id = Id,
ComponentName = ComponentName,
Cost = Cost
};
}
}

View File

@ -0,0 +1,66 @@
using AutoWorkshopContracts.BindingModels;
using AutoWorkshopContracts.ViewModels;
using AutoWorkshopDataModels.Enums;
using AutoWorkshopDataModels.Models;
using System.Diagnostics;
namespace AutoWorkshopImplement.Models
{
public class Order : IOrderModel
{
public int Id { get; private set; }
public int RepairId { get; private set; }
public int Count { get; private set; }
public double Sum { get; private set; }
public OrderStatus Status { get; private set; } = OrderStatus.Undefined;
public DateTime DateCreate { get; private set; }
public DateTime? DateImplement { get; private set; }
public static Order? Create(OrderBindingModel? Model)
{
if (Model is null)
return null;
return new Order()
{
Id = Model.Id,
RepairId = Model.RepairId,
Count = Model.Count,
Sum = Model.Sum,
Status = Model.Status,
DateCreate = Model.DateCreate,
DateImplement = Model.DateImplement
};
}
public void Update(OrderBindingModel? Model)
{
if (Model == null)
return;
RepairId = Model.RepairId;
Count = Model.Count;
Sum = Model.Sum;
Status = Model.Status;
DateCreate = Model.DateCreate;
DateImplement = Model.DateImplement;
}
public OrderViewModel GetViewModel => new()
{
Id = Id,
RepairId = RepairId,
Count = Count,
Sum = Sum,
Status = Status,
DateCreate = DateCreate,
DateImplement = DateImplement
};
}
}

View File

@ -0,0 +1,53 @@
using AutoWorkshopContracts.BindingModels;
using AutoWorkshopContracts.ViewModels;
using AutoWorkshopDataModels.Models;
namespace AutoWorkshopImplement.Models
{
public class Repair : IRepairModel
{
public int Id { get; private set; }
public string RepairName { get; private set; } = string.Empty;
public double Price { get; private set; }
public Dictionary<int, (IComponentModel, int)> RepairComponents
{
get;
private set;
} = new Dictionary<int, (IComponentModel, int)>();
public static Repair? Create(RepairBindingModel? Model)
{
if (Model is null)
return null;
return new Repair()
{
Id = Model.Id,
RepairName = Model.RepairName,
Price = Model.Price,
RepairComponents = Model.RepairComponents
};
}
public void Update(RepairBindingModel? Model)
{
if (Model is null)
return;
RepairName = Model.RepairName;
Price = Model.Price;
RepairComponents = Model.RepairComponents;
}
public RepairViewModel GetViewModel => new()
{
Id = Id,
RepairName = RepairName,
Price = Price,
RepairComponents = RepairComponents
};
}
}

View File

@ -0,0 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0-windows</TargetFramework>
<Nullable>enable</Nullable>
<UseWindowsForms>true</UseWindowsForms>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>
</Project>

View File

@ -0,0 +1,5 @@
namespace AutoWorkshopView;
public class Class1
{
}

BIN
Задание.pdf Normal file

Binary file not shown.