Реализация бизнес-логики и хранения

This commit is contained in:
Володя 2023-02-12 16:08:29 +03:00
parent 87d085de2f
commit d81b8cb987
35 changed files with 1014 additions and 50 deletions

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="7.0.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\AbstractAutoContracts\AutomobilePlantContracts.csproj" />
</ItemGroup>
</Project>

View File

@ -0,0 +1,114 @@
using AutomobilePlantContracts.BindingModels;
using AutomobilePlantContracts.BusinessLogicsContracts;
using AutomobilePlantContracts.SearchModel;
using AutomobilePlantContracts.StoragesContracts;
using AutomobilePlantContracts.ViewModel;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Extensions.Logging;
namespace AutomobilePlantBusinessLogic.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 == null ? _componentStorage.GetFullList() :_componentStorage.GetFilteredList(model);
if (list == 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 == null)
{
throw new ArgumentNullException(nameof(model));
}
_logger.LogInformation("ReadElement. ComponentName:{ComponentName}. Id:{ Id}", model.ComponentName, model.Id);
var element = _componentStorage.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(ComponentBindingModel model)
{
CheckModel(model);
if (_componentStorage.Insert(model) == null)
{
_logger.LogWarning("Insert operation failed");
return false;
}
return true;
}
public bool Update(ComponentBindingModel model)
{
CheckModel(model);
if (_componentStorage.Update(model) == null)
{
_logger.LogWarning("Update operation failed");
return false;
}
return true;
}
public bool Delete(ComponentBindingModel model)
{
CheckModel(model, false);
_logger.LogInformation("Delete. Id:{Id}", model.Id);
if (_componentStorage.Delete(model) == 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("Component. 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,132 @@
using AutomobilePlantContracts.BindingModels;
using AutomobilePlantContracts.BusinessLogicsContracts;
using AutomobilePlantContracts.SearchModel;
using AutomobilePlantContracts.StoragesContracts;
using AutomobilePlantContracts.ViewModel;
using AutomobilePlantDataModels.Enums;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AutomobilePlantBusinessLogic.BusinessLogics
{
public class OrderLogic : IOrderLogic
{
private readonly ILogger _logger;
private readonly IOrderStorage _orderStorage;
public OrderLogic(ILogger<ComponentLogic> logger, IOrderStorage orderStorage)
{
_logger = logger;
_orderStorage = orderStorage;
}
public bool CreateOrder(OrderBindingModel model)
{
CheckModel(model);
if (model.Status != OrderStatus.Неизвестен)
{
_logger.LogWarning("Insert operation failed. Order status incorrect.");
return false;
}
model.Status = OrderStatus.Принят;
if (_orderStorage.Insert(model) == null)
{
model.Status = OrderStatus.Неизвестен;
_logger.LogWarning("Insert operation failed");
return false;
}
return true;
}
public bool StatusUpdate(OrderBindingModel model, OrderStatus newStatus)
{
CheckModel(model);
if (model.Status + 1 != newStatus)
{
_logger.LogWarning("Status update to " + newStatus.ToString() + " operation failed. Order status incorrect.");
return false;
}
model.Status = newStatus;
if (model.Status == OrderStatus.Выдан)
model.DateImplement = DateTime.Now;
if (_orderStorage.Update(model) == null)
{
model.Status--;
_logger.LogWarning("Update operation failed");
return false;
}
return true;
}
public bool DeliveryOrder(OrderBindingModel model)
{
return StatusUpdate(model, OrderStatus.Готов);
}
public bool FinishOrder(OrderBindingModel model)
{
return StatusUpdate(model, OrderStatus.Выдан);
}
public bool TakeOrderInWork(OrderBindingModel model)
{
return StatusUpdate(model, OrderStatus.Выполняется);
}
public List<OrderViewModel>? ReadList(OrderSearchModel? model)
{
_logger.LogInformation("Order. OrderId:{Id}", model?.Id);
var list = model == null ? _orderStorage.GetFullList() : _orderStorage.GetFilteredList(model);
if (list == null)
{
_logger.LogWarning("ReadList return null list");
return null;
}
_logger.LogInformation("ReadList. Count:{Count}", list.Count);
return list;
}
private void CheckModel(OrderBindingModel model, bool withParams = true)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
if (!withParams)
{
return;
}
if (model.Id < 0)
{
throw new ArgumentNullException("Некорректный идентификатор изделия", nameof(model.Id));
}
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. OrderId:{Id}.Sum:{ Sum}. WorkId: { WorkId}", model.Id, model.Sum, model.Id);
}
}
}

View File

@ -0,0 +1,113 @@
using AutomobilePlantContracts.BindingModels;
using AutomobilePlantContracts.BusinessLogicsContracts;
using AutomobilePlantContracts.SearchModel;
using AutomobilePlantContracts.StoragesContracts;
using AutomobilePlantContracts.ViewModel;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AutomobilePlantBusinessLogic.BusinessLogics
{
public class ProductLogic : IProductLogic
{
private readonly ILogger _logger;
private readonly IProductStorage _productStorage;
public ProductLogic(ILogger<ProductLogic> logger, IProductStorage productStorage)
{
_logger = logger;
_productStorage = productStorage;
}
public List<ProductViewModel>? ReadList(ProductSearchModel? model)
{
_logger.LogInformation("ReadList. ProductName:{ProductName}.Id:{ Id}", model?.ProductName, model?.Id);
var list = model == null ? _productStorage.GetFullList() : _productStorage.GetFilteredList(model);
if (list == null)
{
_logger.LogWarning("ReadList return null list");
return null;
}
_logger.LogInformation("ReadList. Count:{Count}", list.Count);
return list;
}
public ProductViewModel? ReadElement(ProductSearchModel model)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
_logger.LogInformation("ReadElement. ProductName:{ProductName}. Id:{ Id}", model.ProductName, model.Id);
var element = _productStorage.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(ProductBindingModel model)
{
CheckModel(model);
if (_productStorage.Insert(model) == null)
{
_logger.LogWarning("Insert operation failed");
return false;
}
return true;
}
public bool Update(ProductBindingModel model)
{
CheckModel(model);
if (_productStorage.Update(model) == null)
{
_logger.LogWarning("Update operation failed");
return false;
}
return true;
}
public bool Delete(ProductBindingModel model)
{
CheckModel(model, false);
_logger.LogInformation("Delete. Id:{Id}", model.Id);
if (_productStorage.Delete(model) == null)
{
_logger.LogWarning("Delete operation failed");
return false;
}
return true;
}
private void CheckModel(ProductBindingModel model, bool withParams =
true)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
if (!withParams)
{
return;
}
if (string.IsNullOrEmpty(model.ProductName))
{
throw new ArgumentNullException("Нет названия изделия", nameof(model.ProductName));
}
if (model.Price <= 0)
{
throw new ArgumentNullException("Цена изделия должна быть больше 0", nameof(model.Price));
}
_logger.LogInformation("Product. ProductName:{ProductName}.Cost:{ Cost}. Id: { Id}", model.ProductName, model.Price, model.Id);
var element = _productStorage.GetElement(new ProductSearchModel
{
ProductName = model.ProductName
});
if (element != null && element.Id != model.Id)
{
throw new InvalidOperationException("Изделие с таким названием уже есть");
}
}
}
}

View File

@ -7,7 +7,7 @@
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\AbstractAutoDataModels\AbstractAutoDataModels.csproj" /> <ProjectReference Include="..\AbstractAutoDataModels\AutomobilePlantDataModels.csproj" />
</ItemGroup> </ItemGroup>
</Project> </Project>

View File

@ -3,9 +3,9 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using AbstractAutoDataModels.Models; using AutomobilePlantDataModels.Models;
namespace AbstractAutoContracts.BindingModels namespace AutomobilePlantContracts.BindingModels
{ {
public class ComponentBindingModel : IComponentModel public class ComponentBindingModel : IComponentModel
{ {

View File

@ -3,15 +3,16 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using AbstractAutoDataModels.Enums; using AutomobilePlantDataModels.Enums;
using AbstractAutoDataModels.Models; using AutomobilePlantDataModels.Models;
namespace AbstractAutoContracts.BindingModels namespace AutomobilePlantContracts.BindingModels
{ {
public class OrderBindingModel : IOrderModel public class OrderBindingModel : IOrderModel
{ {
public int Id { get; set; } public int Id { get; set; }
public int ProductId { get; set; } public int ProductId { get; set; }
public string ProductName { get; set; } = string.Empty;
public int Count { get; set; } public int Count { get; set; }
public double Sum { get; set; } public double Sum { get; set; }
public OrderStatus Status { get; set; } = OrderStatus.Неизвестен; public OrderStatus Status { get; set; } = OrderStatus.Неизвестен;

View File

@ -3,9 +3,9 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using AbstractAutoDataModels.Models; using AutomobilePlantDataModels.Models;
namespace AbstractAutoContracts.BindingModels namespace AutomobilePlantContracts.BindingModels
{ {
public class ProductBindingModel : IProductModel public class ProductBindingModel : IProductModel
{ {

View File

@ -1,13 +1,13 @@
using AbstractAutoContracts.BindingModels; using AutomobilePlantContracts.BindingModels;
using AbstractAutoContracts.SearchModel; using AutomobilePlantContracts.SearchModel;
using AbstractAutoContracts.ViewModel; using AutomobilePlantContracts.ViewModel;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace AbstractAutoContracts.BusinessLogicsContracts namespace AutomobilePlantContracts.BusinessLogicsContracts
{ {
public interface IComponentLogic public interface IComponentLogic
{ {

View File

@ -1,13 +1,13 @@
using AbstractAutoContracts.BindingModels; using AutomobilePlantContracts.BindingModels;
using AbstractAutoContracts.SearchModel; using AutomobilePlantContracts.SearchModel;
using AbstractAutoContracts.ViewModel; using AutomobilePlantContracts.ViewModel;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace AbstractAutoContracts.BusinessLogicsContracts namespace AutomobilePlantContracts.BusinessLogicsContracts
{ {
public interface IOrderLogic public interface IOrderLogic
{ {

View File

@ -1,13 +1,13 @@
using AbstractAutoContracts.BindingModels; using AutomobilePlantContracts.BindingModels;
using AbstractAutoContracts.SearchModel; using AutomobilePlantContracts.SearchModel;
using AbstractAutoContracts.ViewModel; using AutomobilePlantContracts.ViewModel;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace AbstractAutoContracts.BusinessLogicsContracts namespace AutomobilePlantContracts.BusinessLogicsContracts
{ {
public interface IProductLogic public interface IProductLogic
{ {

View File

@ -4,7 +4,7 @@ using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace AbstractAutoContracts.SearchModel namespace AutomobilePlantContracts.SearchModel
{ {
public class ComponentSearchModel public class ComponentSearchModel
{ {

View File

@ -4,7 +4,7 @@ using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace AbstractAutoContracts.SearchModel namespace AutomobilePlantContracts.SearchModel
{ {
public class OrderSearchModel public class OrderSearchModel
{ {

View File

@ -4,7 +4,7 @@ using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace AbstractAutoContracts.SearchModel namespace AutomobilePlantContracts.SearchModel
{ {
public class ProductSearchModel public class ProductSearchModel
{ {

View File

@ -1,13 +1,13 @@
using AbstractAutoContracts.BindingModels; using AutomobilePlantContracts.BindingModels;
using AbstractAutoContracts.SearchModel; using AutomobilePlantContracts.SearchModel;
using AbstractAutoContracts.ViewModel; using AutomobilePlantContracts.ViewModel;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace AbstractAutoContracts.StoragesContracts namespace AutomobilePlantContracts.StoragesContracts
{ {
public interface IComponentStorage public interface IComponentStorage
{ {

View File

@ -1,13 +1,13 @@
using AbstractAutoContracts.BindingModels; using AutomobilePlantContracts.BindingModels;
using AbstractAutoContracts.SearchModel; using AutomobilePlantContracts.SearchModel;
using AbstractAutoContracts.ViewModel; using AutomobilePlantContracts.ViewModel;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace AbstractAutoContracts.StoragesContracts namespace AutomobilePlantContracts.StoragesContracts
{ {
public interface IOrderStorage public interface IOrderStorage
{ {

View File

@ -1,13 +1,13 @@
using AbstractAutoContracts.BindingModels; using AutomobilePlantContracts.BindingModels;
using AbstractAutoContracts.SearchModel; using AutomobilePlantContracts.SearchModel;
using AbstractAutoContracts.ViewModel; using AutomobilePlantContracts.ViewModel;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace AbstractAutoContracts.StoragesContracts namespace AutomobilePlantContracts.StoragesContracts
{ {
public interface IProductStorage public interface IProductStorage
{ {

View File

@ -1,11 +1,11 @@
using AbstractAutoDataModels.Models; using AutomobilePlantDataModels.Models;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.ComponentModel; using System.ComponentModel;
namespace AbstractAutoContracts.ViewModel namespace AutomobilePlantContracts.ViewModel
{ {
public class ComponentViewModel : IComponentModel public class ComponentViewModel : IComponentModel
{ {

View File

@ -1,13 +1,13 @@
using AbstractAutoDataModels.Models; using AutomobilePlantDataModels.Models;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.ComponentModel; using System.ComponentModel;
using AbstractAutoDataModels.Enums; using AutomobilePlantDataModels.Enums;
namespace AbstractAutoContracts.ViewModel namespace AutomobilePlantContracts.ViewModel
{ {
public class OrderViewModel : IOrderModel public class OrderViewModel : IOrderModel
{ {

View File

@ -1,11 +1,11 @@
using AbstractAutoDataModels.Models; using AutomobilePlantDataModels.Models;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.ComponentModel; using System.ComponentModel;
namespace AbstractAutoContracts.ViewModel namespace AutomobilePlantContracts.ViewModel
{ {
public class ProductViewModel : IProductModel public class ProductViewModel : IProductModel
{ {

View File

@ -4,7 +4,7 @@ using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace AbstractAutoDataModels.Enums namespace AutomobilePlantDataModels.Enums
{ {
public enum OrderStatus public enum OrderStatus
{ {

View File

@ -4,7 +4,7 @@ using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace AbstractAutoDataModels namespace AutomobilePlantDataModels
{ {
public interface IId public interface IId
{ {

View File

@ -4,7 +4,7 @@ using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace AbstractAutoDataModels.Models namespace AutomobilePlantDataModels.Models
{ {
public interface IComponentModel : IId public interface IComponentModel : IId
{ {

View File

@ -1,15 +1,16 @@
using AbstractAutoDataModels.Enums; using AutomobilePlantDataModels.Enums;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace AbstractAutoDataModels.Models namespace AutomobilePlantDataModels.Models
{ {
public interface IOrderModel : IId public interface IOrderModel : IId
{ {
int ProductId { get; } int ProductId { get; }
string ProductName { get; }
int Count { get; } int Count { get; }
double Sum { get; } double Sum { get; }
OrderStatus Status { get; } OrderStatus Status { get; }

View File

@ -4,7 +4,7 @@ using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace AbstractAutoDataModels.Models namespace AutomobilePlantDataModels.Models
{ {
public interface IProductModel : IId public interface IProductModel : IId
{ {

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="..\AbstractAutoContracts\AutomobilePlantContracts.csproj" />
<ProjectReference Include="..\AbstractAutoDataModels\AutomobilePlantDataModels.csproj" />
</ItemGroup>
</Project>

View File

@ -0,0 +1,31 @@
using AutomobilePlantListImplement.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AutomobilePlantListImplement
{
public class DataListSingleton
{
private static DataListSingleton? _instance;
public List<Component> Components { get; set; }
public List<Order> Orders { get; set; }
public List<Product> Products { get; set; }
private DataListSingleton()
{
Components = new List<Component>();
Orders = new List<Order>();
Products = new List<Product>();
}
public static DataListSingleton GetInstance()
{
if (_instance == null)
{
_instance = new DataListSingleton();
}
return _instance;
}
}
}

View File

@ -0,0 +1,108 @@
using AutomobilePlantContracts.BindingModels;
using AutomobilePlantContracts.SearchModel;
using AutomobilePlantContracts.StoragesContracts;
using AutomobilePlantContracts.ViewModel;
using AutomobilePlantListImplement.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AutomobilePlantListImplement.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,124 @@
using AutomobilePlantContracts.StoragesContracts;
using AutomobilePlantContracts.ViewModel;
using AutomobilePlantContracts.BindingModels;
using AutomobilePlantContracts.SearchModel;
using AutomobilePlantListImplement.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AutomobilePlantListImplement.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 (model.Id.HasValue && order.Id == model.Id)
{
result.Add(order.GetViewModel);
}
}
return result;
}
public OrderViewModel? GetElement(OrderSearchModel model)
{
if (!model.Id.HasValue)
{
return null;
}
foreach (var order in _source.Orders)
{
if (model.Id.HasValue && 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,126 @@
using AutomobilePlantContracts.StoragesContracts;
using AutomobilePlantContracts.ViewModel;
using AutomobilePlantContracts.BindingModels;
using AutomobilePlantContracts.SearchModel;
using AutomobilePlantListImplement.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AutomobilePlantListImplement.Implements
{
public class ProductStorage : IProductStorage
{
private readonly DataListSingleton _source;
public ProductStorage()
{
_source = DataListSingleton.GetInstance();
}
public List<ProductViewModel> GetFullList()
{
var result = new List<ProductViewModel>();
foreach (var product in _source.Products)
{
result.Add(product.GetViewModel);
}
return result;
}
public List<ProductViewModel> GetFilteredList(ProductSearchModel model)
{
var result = new List<ProductViewModel>();
if (string.IsNullOrEmpty(model.ProductName))
{
return result;
}
foreach (var product in _source.Products)
{
if (product.ProductName.Contains(model.ProductName))
{
result.Add(product.GetViewModel);
}
}
return result;
}
public ProductViewModel? GetElement(ProductSearchModel model)
{
if (string.IsNullOrEmpty(model.ProductName) && !model.Id.HasValue)
{
return null;
}
foreach (var product in _source.Products)
{
if ((!string.IsNullOrEmpty(model.ProductName) && product.ProductName == model.ProductName) || (model.Id.HasValue && product.Id == model.Id))
{
return product.GetViewModel;
}
}
return null;
}
public ProductViewModel? Insert(ProductBindingModel model)
{
model.Id = 1;
foreach (var product in _source.Products)
{
if (model.Id <= product.Id)
{
model.Id = product.Id + 1;
}
}
var newProduct = Product.Create(model);
if (newProduct == null)
{
return null;
}
_source.Products.Add(newProduct);
return newProduct.GetViewModel;
}
public ProductViewModel? Update(ProductBindingModel model)
{
foreach (var product in _source.Products)
{
if (product.Id == model.Id)
{
product.Update(model);
return product.GetViewModel;
}
}
return null;
}
public ProductViewModel? Delete(ProductBindingModel model)
{
for (int i = 0; i < _source.Products.Count; ++i)
{
if (_source.Products[i].Id == model.Id)
{
var element = _source.Products[i];
_source.Products.RemoveAt(i);
return element.GetViewModel;
}
}
return null;
}
}
}

View File

@ -0,0 +1,46 @@
using AutomobilePlantContracts.BindingModels;
using AutomobilePlantContracts.ViewModel;
using AutomobilePlantDataModels.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AutomobilePlantListImplement.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 == null)
{
return null;
}
return new Component()
{
Id = model.Id,
ComponentName = model.ComponentName,
Cost = model.Cost
};
}
public void Update(ComponentBindingModel? model)
{
if (model == null)
{
return;
}
ComponentName = model.ComponentName;
Cost = model.Cost;
}
public ComponentViewModel GetViewModel => new()
{
Id = Id,
ComponentName = ComponentName,
Cost = Cost
};
}
}

View File

@ -0,0 +1,70 @@
using AutomobilePlantContracts.BindingModels;
using AutomobilePlantContracts.ViewModel;
using AutomobilePlantDataModels.Enums;
using AutomobilePlantDataModels.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AutomobilePlantListImplement.Models
{
public class Order : IOrderModel
{
public int Id { get; private set; }
public int ProductId { get; private set; }
public string ProductName { get; private set; }
public int Count { get; private set; }
public double Sum { get; private set; }
public OrderStatus Status { get; private set; } = OrderStatus.Неизвестен;
public DateTime DateCreate { get; private set; } = DateTime.Now;
public DateTime? DateImplement { get; private set; }
public static Order? Create(OrderBindingModel? model)
{
if (model == null)
{
return null;
}
return new Order()
{
Id = model.Id,
ProductId = model.ProductId,
ProductName = model.ProductName,
Count = model.Count,
Sum = model.Sum,
Status = model.Status,
DateCreate = model.DateCreate,
DateImplement = model.DateImplement
};
}
public void Update(OrderBindingModel? model)
{
if (model == null)
{
return;
}
ProductId = model.ProductId;
ProductName = model.ProductName;
Count = model.Count;
Sum = model.Sum;
Status = model.Status;
DateCreate = model.DateCreate;
DateImplement = model.DateImplement;
}
public OrderViewModel GetViewModel => new()
{
Id = Id,
ProductId = ProductId,
ProductName = ProductName,
Count = Count,
Sum = Sum,
Status = Status,
DateCreate = DateCreate,
DateImplement = DateImplement
};
}
}

View File

@ -0,0 +1,55 @@
using AutomobilePlantContracts.BindingModels;
using AutomobilePlantContracts.ViewModel;
using AutomobilePlantDataModels.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AutomobilePlantListImplement.Models
{
public class Product : IProductModel
{
public int Id { get; private set; }
public string ProductName { get; private set; } = string.Empty;
public double Price { get; private set; }
public Dictionary<int, (IComponentModel, int)> ProductComponents
{
get;
private set;
} = new Dictionary<int, (IComponentModel, int)>();
public static Product? Create(ProductBindingModel? model)
{
if (model == null)
{
return null;
}
return new Product()
{
Id = model.Id,
ProductName = model.ProductName,
Price = model.Price,
ProductComponents = model.ProductComponents
};
}
public void Update(ProductBindingModel? model)
{
if (model == null)
{
return;
}
ProductName = model.ProductName;
Price = model.Price;
ProductComponents = model.ProductComponents;
}
public ProductViewModel GetViewModel => new()
{
Id = Id,
ProductName = ProductName,
Price = Price,
ProductComponents = ProductComponents
};
}
}

View File

@ -5,9 +5,13 @@ VisualStudioVersion = 17.3.32825.248
MinimumVisualStudioVersion = 10.0.40219.1 MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AutomobilePlant", "AutomobilePlant\AutomobilePlant.csproj", "{2A499DE6-B7DE-4A28-9906-12FC100451F0}" Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AutomobilePlant", "AutomobilePlant\AutomobilePlant.csproj", "{2A499DE6-B7DE-4A28-9906-12FC100451F0}"
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AbstractAutoDataModels", "AbstractAutoDataModels\AbstractAutoDataModels.csproj", "{DD7B0E1A-2EE9-441A-87C3-03AC0421746E}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AutomobilePlantDataModels", "AbstractAutoDataModels\AutomobilePlantDataModels.csproj", "{DD7B0E1A-2EE9-441A-87C3-03AC0421746E}"
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AbstractAutoContracts", "AbstractAutoContracts\AbstractAutoContracts.csproj", "{4B515980-8AD9-48F3-886E-3C2A6B1E9D90}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AutomobilePlantContracts", "AbstractAutoContracts\AutomobilePlantContracts.csproj", "{4B515980-8AD9-48F3-886E-3C2A6B1E9D90}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AutomobilePlantBusinessLogic", "AbstractAutoBusinessLogic\AutomobilePlantBusinessLogic.csproj", "{D57C726F-E5B4-4CB3-A754-D5F93295CE1E}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AutomobilePlantListImplement", "AbstractAutoListImplement\AutomobilePlantListImplement.csproj", "{305978E5-BFB5-47B0-94C9-2C5D06748BD6}"
EndProject EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution
@ -27,6 +31,14 @@ Global
{4B515980-8AD9-48F3-886E-3C2A6B1E9D90}.Debug|Any CPU.Build.0 = Debug|Any CPU {4B515980-8AD9-48F3-886E-3C2A6B1E9D90}.Debug|Any CPU.Build.0 = Debug|Any CPU
{4B515980-8AD9-48F3-886E-3C2A6B1E9D90}.Release|Any CPU.ActiveCfg = Release|Any CPU {4B515980-8AD9-48F3-886E-3C2A6B1E9D90}.Release|Any CPU.ActiveCfg = Release|Any CPU
{4B515980-8AD9-48F3-886E-3C2A6B1E9D90}.Release|Any CPU.Build.0 = Release|Any CPU {4B515980-8AD9-48F3-886E-3C2A6B1E9D90}.Release|Any CPU.Build.0 = Release|Any CPU
{D57C726F-E5B4-4CB3-A754-D5F93295CE1E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{D57C726F-E5B4-4CB3-A754-D5F93295CE1E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D57C726F-E5B4-4CB3-A754-D5F93295CE1E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D57C726F-E5B4-4CB3-A754-D5F93295CE1E}.Release|Any CPU.Build.0 = Release|Any CPU
{305978E5-BFB5-47B0-94C9-2C5D06748BD6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{305978E5-BFB5-47B0-94C9-2C5D06748BD6}.Debug|Any CPU.Build.0 = Debug|Any CPU
{305978E5-BFB5-47B0-94C9-2C5D06748BD6}.Release|Any CPU.ActiveCfg = Release|Any CPU
{305978E5-BFB5-47B0-94C9-2C5D06748BD6}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection EndGlobalSection
GlobalSection(SolutionProperties) = preSolution GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE HideSolutionNode = FALSE