вроде заработала вторая усложненка
This commit is contained in:
parent
5ac66dc71b
commit
5d93cf4a7f
@ -24,7 +24,7 @@ namespace ComputersShopBusinessLogic.BusinessLogics
|
||||
public List<ComponentViewModel>? ReadList(ComponentSearchModel? model)
|
||||
{
|
||||
_logger.LogInformation("ReadList. ComponentName:{ComponentName}. Id:{Id}", model?.ComponentName, model?.Id);
|
||||
var list = model == null ? _componentStorage.GetFullList() : _componentStorage.GetFiltredList(model);
|
||||
var list = model == null ? _componentStorage.GetFullList() : _componentStorage.GetFilteredList(model);
|
||||
if (list == null)
|
||||
{
|
||||
_logger.LogWarning("ReadList return null list");
|
||||
|
@ -15,33 +15,17 @@ namespace ComputersShopBusinessLogic.BusinessLogics
|
||||
public class ComputerLogic : IComputerLogic
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
|
||||
/// <summary>
|
||||
/// Взаимодействие с хранилищем изделий
|
||||
/// </summary>
|
||||
private readonly IComputerStorage _computerStorage;
|
||||
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
/// </summary>
|
||||
/// <param name="logger"></param>
|
||||
/// <param name="computerStorage"></param>
|
||||
public ComputerLogic(ILogger<ComputerLogic> logger, IComputerStorage computerStorage)
|
||||
{
|
||||
_logger = logger;
|
||||
_computerStorage = computerStorage;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Получение списка
|
||||
/// </summary>
|
||||
/// <param name="model"></param>
|
||||
/// <returns></returns>
|
||||
public List<ComputerViewModel>? ReadList(ComputerSearchModel? model)
|
||||
{
|
||||
_logger.LogInformation("ReadList. ComputerName:{ComputerName}.Id:{ Id}", model?.ComputerName, model?.Id);
|
||||
|
||||
var list = model == null ? _computerStorage.GetFullList() : _computerStorage.GetFiltredList(model);
|
||||
var list = model == null ? _computerStorage.GetFullList() : _computerStorage.GetFilteredList(model);
|
||||
if (list == null)
|
||||
{
|
||||
_logger.LogWarning("ReadList return null list");
|
||||
@ -51,13 +35,6 @@ namespace ComputersShopBusinessLogic.BusinessLogics
|
||||
_logger.LogInformation("ReadList. Count:{Count}", list.Count);
|
||||
return list;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Получение отдельной записи
|
||||
/// </summary>
|
||||
/// <param name="model"></param>
|
||||
/// <returns></returns>
|
||||
/// <exception cref="ArgumentNullException"></exception>
|
||||
public ComputerViewModel? ReadElement(ComputerSearchModel model)
|
||||
{
|
||||
if (model == null)
|
||||
@ -77,12 +54,6 @@ namespace ComputersShopBusinessLogic.BusinessLogics
|
||||
_logger.LogInformation("ReadElement find. Id:{Id}", element.Id);
|
||||
return element;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Создание записи
|
||||
/// </summary>
|
||||
/// <param name="model"></param>
|
||||
/// <returns></returns>
|
||||
public bool Create(ComputerBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
@ -94,12 +65,6 @@ namespace ComputersShopBusinessLogic.BusinessLogics
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Изменение записи
|
||||
/// </summary>
|
||||
/// <param name="model"></param>
|
||||
/// <returns></returns>
|
||||
public bool Update(ComputerBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
@ -111,12 +76,6 @@ namespace ComputersShopBusinessLogic.BusinessLogics
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Удаление записи
|
||||
/// </summary>
|
||||
/// <param name="model"></param>
|
||||
/// <returns></returns>
|
||||
public bool Delete(ComputerBindingModel model)
|
||||
{
|
||||
CheckModel(model, false);
|
||||
@ -129,12 +88,6 @@ namespace ComputersShopBusinessLogic.BusinessLogics
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Проверка модели изделия
|
||||
/// </summary>
|
||||
/// <param name="model"></param>
|
||||
/// <param name="withParams"></param>
|
||||
private void CheckModel(ComputerBindingModel model, bool withParams = true)
|
||||
{
|
||||
if (model == null)
|
||||
|
@ -17,32 +17,10 @@ namespace ComputersShopBusinessLogic.BusinessLogics
|
||||
public class OrderLogic : IOrderLogic
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
|
||||
/// <summary>
|
||||
/// Взаимодействие с хранилищем заказов
|
||||
/// </summary>
|
||||
private readonly IOrderStorage _orderStorage;
|
||||
|
||||
/// <summary>
|
||||
/// Взаимодействие с хранилищем магазинов
|
||||
/// </summary>
|
||||
private IShopStorage _shopStorage;
|
||||
|
||||
/// <summary>
|
||||
/// Бизнес-логика магазинов
|
||||
/// </summary>
|
||||
private IShopLogic _shopLogic;
|
||||
|
||||
/// <summary>
|
||||
/// Взаимодействие с хранилищем изделий
|
||||
/// </summary>
|
||||
private IComputerStorage _computerStorage;
|
||||
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
/// </summary>
|
||||
/// <param name="logger"></param>
|
||||
/// <param name="orderStorage"></param>
|
||||
public OrderLogic(ILogger<OrderLogic> logger, IOrderStorage orderStorage, IShopStorage shopStorage, IShopLogic shopLogic, IComputerStorage computerStorage)
|
||||
{
|
||||
_logger = logger;
|
||||
@ -51,12 +29,6 @@ namespace ComputersShopBusinessLogic.BusinessLogics
|
||||
_shopLogic = shopLogic;
|
||||
_computerStorage = computerStorage;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Получение списка
|
||||
/// </summary>
|
||||
/// <param name="model"></param>
|
||||
/// <returns></returns>
|
||||
public List<OrderViewModel>? ReadList(OrderSearchModel? model)
|
||||
{
|
||||
_logger.LogInformation("ReadList. Order.Id:{ Id}", model?.Id);
|
||||
@ -71,12 +43,6 @@ namespace ComputersShopBusinessLogic.BusinessLogics
|
||||
_logger.LogInformation("ReadList. Count:{Count}", list.Count);
|
||||
return list;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Создание заказа
|
||||
/// </summary>
|
||||
/// <param name="model"></param>
|
||||
/// <returns></returns>
|
||||
public bool CreateOrder(OrderBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
@ -95,42 +61,18 @@ namespace ComputersShopBusinessLogic.BusinessLogics
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Смена статуса заказа (Выполняется)
|
||||
/// </summary>
|
||||
/// <param name="model"></param>
|
||||
/// <returns></returns>
|
||||
public bool TakeOrderInWork(OrderBindingModel model)
|
||||
{
|
||||
return StatusUpdate(model, OrderStatus.Выполняется);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Смена статуса заказа (Выдан)
|
||||
/// </summary>
|
||||
/// <param name="model"></param>
|
||||
/// <returns></returns>
|
||||
public bool FinishOrder(OrderBindingModel model)
|
||||
{
|
||||
return StatusUpdate(model, OrderStatus.Выдан);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Смена статуса заказа (Готов)
|
||||
/// </summary>
|
||||
/// <param name="model"></param>
|
||||
/// <returns></returns>
|
||||
public bool DeliveryOrder(OrderBindingModel model)
|
||||
{
|
||||
return StatusUpdate(model, OrderStatus.Готов);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Проверка модели заказа
|
||||
/// </summary>
|
||||
/// <param name="model"></param>
|
||||
/// <param name="withParams"></param>
|
||||
private void CheckModel(OrderBindingModel model, bool withParams = true)
|
||||
{
|
||||
if (model == null)
|
||||
@ -155,13 +97,6 @@ namespace ComputersShopBusinessLogic.BusinessLogics
|
||||
}
|
||||
_logger.LogInformation("Order. OrderID:{Id}.Sum:{ Sum}. ComputerId: { ComputerId}", model.Id, model.Sum, model.ComputerId);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Смена статуса заказа
|
||||
/// </summary>
|
||||
/// <param name="model"></param>
|
||||
/// <param name="newStatus"></param>
|
||||
/// <returns></returns>
|
||||
private bool StatusUpdate(OrderBindingModel model, OrderStatus newStatus)
|
||||
{
|
||||
var element = _orderStorage.GetElement(new OrderSearchModel
|
||||
@ -211,13 +146,6 @@ namespace ComputersShopBusinessLogic.BusinessLogics
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Проверка заказа
|
||||
/// </summary>
|
||||
/// <param name="computer"></param>
|
||||
/// <param name="count"></param>
|
||||
/// <returns></returns>
|
||||
public bool CheckSupply(IComputerModel model, int count)
|
||||
{
|
||||
if (count <= 0)
|
||||
|
@ -16,28 +16,12 @@ namespace ComputersShopBusinessLogic.BusinessLogics
|
||||
public class ShopLogic : IShopLogic
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
|
||||
/// <summary>
|
||||
/// Взаимодействие с хранилищем магазинов
|
||||
/// </summary>
|
||||
private readonly IShopStorage _shopStorage;
|
||||
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
/// </summary>
|
||||
/// <param name="logger"></param>
|
||||
/// <param name="shopStorage"></param>
|
||||
public ShopLogic(ILogger<ShopLogic> logger, IShopStorage shopStorage)
|
||||
{
|
||||
_logger = logger;
|
||||
_shopStorage = shopStorage;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Получение списка
|
||||
/// </summary>
|
||||
/// <param name="model"></param>
|
||||
/// <returns></returns>
|
||||
public List<ShopViewModel>? ReadList(ShopSearchModel? model)
|
||||
{
|
||||
_logger.LogInformation("ReadList. ShopName:{ShopName}.Id:{ Id}", model?.ShopName, model?.Id);
|
||||
@ -52,13 +36,6 @@ namespace ComputersShopBusinessLogic.BusinessLogics
|
||||
_logger.LogInformation("ReadList. Count:{Count}", list.Count);
|
||||
return list;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Получение отдельной записи
|
||||
/// </summary>
|
||||
/// <param name="model"></param>
|
||||
/// <returns></returns>
|
||||
/// <exception cref="ArgumentNullException"></exception>
|
||||
public ShopViewModel? ReadElement(ShopSearchModel model)
|
||||
{
|
||||
if (model == null)
|
||||
@ -78,12 +55,6 @@ namespace ComputersShopBusinessLogic.BusinessLogics
|
||||
_logger.LogInformation("ReadElement find. Id:{Id}", element.Id);
|
||||
return element;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Создание записи
|
||||
/// </summary>
|
||||
/// <param name="model"></param>
|
||||
/// <returns></returns>
|
||||
public bool Create(ShopBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
@ -95,12 +66,6 @@ namespace ComputersShopBusinessLogic.BusinessLogics
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Изменение записи
|
||||
/// </summary>
|
||||
/// <param name="model"></param>
|
||||
/// <returns></returns>
|
||||
public bool Update(ShopBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
@ -112,12 +77,6 @@ namespace ComputersShopBusinessLogic.BusinessLogics
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Удаление записи
|
||||
/// </summary>
|
||||
/// <param name="model"></param>
|
||||
/// <returns></returns>
|
||||
public bool Delete(ShopBindingModel model)
|
||||
{
|
||||
CheckModel(model, false);
|
||||
@ -130,16 +89,6 @@ namespace ComputersShopBusinessLogic.BusinessLogics
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Добавление изделия в магазин
|
||||
/// </summary>
|
||||
/// <param name="model"></param>
|
||||
/// <param name="computer"></param>
|
||||
/// <param name="count"></param>
|
||||
/// <returns></returns>
|
||||
/// <exception cref="ArgumentNullException"></exception>
|
||||
/// <exception cref="ArgumentException"></exception>
|
||||
public bool AddComputerInShop(ShopSearchModel model, IComputerModel computer, int count)
|
||||
{
|
||||
if (model == null)
|
||||
@ -188,15 +137,6 @@ namespace ComputersShopBusinessLogic.BusinessLogics
|
||||
});
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Продажа изделий
|
||||
/// </summary>
|
||||
/// <param name="computer"></param>
|
||||
/// <param name="count"></param>
|
||||
/// <returns></returns>
|
||||
/// <exception cref="ArgumentNullException"></exception>
|
||||
/// <exception cref="ArgumentException"></exception>
|
||||
public bool SellComputers(IComputerModel computer, int count)
|
||||
{
|
||||
if (computer == null)
|
||||
@ -216,14 +156,6 @@ namespace ComputersShopBusinessLogic.BusinessLogics
|
||||
_logger.LogInformation("Selling failed");
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Проверка модели магазина
|
||||
/// </summary>
|
||||
/// <param name="model"></param>
|
||||
/// <param name="withParams"></param>
|
||||
/// <exception cref="ArgumentNullException"></exception>
|
||||
/// <exception cref="InvalidOperationException"></exception>
|
||||
private void CheckModel(ShopBindingModel model, bool withParams = true)
|
||||
{
|
||||
if (model == null)
|
||||
|
@ -13,7 +13,7 @@ namespace ComputersShopContracts.StoragesContracts
|
||||
public interface IComponentStorage
|
||||
{
|
||||
List<ComponentViewModel> GetFullList();
|
||||
List<ComponentViewModel> GetFiltredList(ComponentSearchModel model);
|
||||
List<ComponentViewModel> GetFilteredList(ComponentSearchModel model);
|
||||
ComponentViewModel? GetElement(ComponentSearchModel model);
|
||||
ComponentViewModel? Insert(ComponentBindingModel model);
|
||||
ComponentViewModel? Update(ComponentBindingModel model);
|
||||
|
@ -13,7 +13,7 @@ namespace ComputersShopContracts.StoragesContracts
|
||||
public interface IComputerStorage
|
||||
{
|
||||
List<ComputerViewModel> GetFullList();
|
||||
List<ComputerViewModel> GetFiltredList(ComputerSearchModel model);
|
||||
List<ComputerViewModel> GetFilteredList(ComputerSearchModel model);
|
||||
ComputerViewModel? GetElement(ComputerSearchModel model);
|
||||
ComputerViewModel? Insert(ComputerBindingModel model);
|
||||
ComputerViewModel? Update(ComputerBindingModel model);
|
||||
|
@ -12,40 +12,10 @@ namespace ComputersShopContracts.StoragesContracts
|
||||
public interface IOrderStorage
|
||||
{
|
||||
List<OrderViewModel> GetFullList();
|
||||
|
||||
/// <summary>
|
||||
/// Получение фильтрованного списка
|
||||
/// </summary>
|
||||
/// <param name="model"></param>
|
||||
/// <returns></returns>
|
||||
List<OrderViewModel> GetFilteredList(OrderSearchModel model);
|
||||
|
||||
/// <summary>
|
||||
/// Получение элемента
|
||||
/// </summary>
|
||||
/// <param name="model"></param>
|
||||
/// <returns></returns>
|
||||
OrderViewModel? GetElement(OrderSearchModel model);
|
||||
|
||||
/// <summary>
|
||||
/// Добавление элемента
|
||||
/// </summary>
|
||||
/// <param name="model"></param>
|
||||
/// <returns></returns>
|
||||
OrderViewModel? Insert(OrderBindingModel model);
|
||||
|
||||
/// <summary>
|
||||
/// Редактирование элемента
|
||||
/// </summary>
|
||||
/// <param name="model"></param>
|
||||
/// <returns></returns>
|
||||
OrderViewModel? Update(OrderBindingModel model);
|
||||
|
||||
/// <summary>
|
||||
/// Удаление элемента
|
||||
/// </summary>
|
||||
/// <param name="model"></param>
|
||||
/// <returns></returns>
|
||||
OrderViewModel? Delete(OrderBindingModel model);
|
||||
}
|
||||
}
|
@ -12,50 +12,14 @@ namespace ComputersShopFileImplement
|
||||
internal class DataFileSingleton
|
||||
{
|
||||
private static DataFileSingleton? _instance;
|
||||
|
||||
/// <summary>
|
||||
/// Название файла для хранения информации о компонентах
|
||||
/// </summary>
|
||||
private readonly string ComponentFileName = "Component.xml";
|
||||
|
||||
/// <summary>
|
||||
/// Название файла для хранения информации о заказах
|
||||
/// </summary>
|
||||
private readonly string OrderFileName = "Order.xml";
|
||||
|
||||
/// <summary>
|
||||
/// Название файла для хранения информации о изделиях
|
||||
/// </summary>
|
||||
private readonly string ComputerFileName = "Computer.xml";
|
||||
|
||||
/// <summary>
|
||||
/// Название файла для хранения информации о магазинах
|
||||
/// </summary>
|
||||
private readonly string ShopFileName = "Shop.xml";
|
||||
|
||||
/// <summary>
|
||||
/// Список классов-моделей компонентов
|
||||
/// </summary>
|
||||
public List<Component> Components { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Список классов-моделей заказов
|
||||
/// </summary>
|
||||
public List<Order> Orders { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Список классов-моделей изделий
|
||||
/// </summary>
|
||||
public List<Computer> Computers { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Список классов-моделей магазина
|
||||
/// </summary>
|
||||
public List<Shop> Shops { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
/// </summary>
|
||||
private DataFileSingleton()
|
||||
{
|
||||
Components = LoadData(ComponentFileName, "Component", x => Component.Create(x)!)!;
|
||||
@ -63,11 +27,6 @@ namespace ComputersShopFileImplement
|
||||
Orders = LoadData(OrderFileName, "Order", x => Order.Create(x)!)!;
|
||||
Shops = LoadData(ShopFileName, "Shop", x => Shop.Create(x)!)!;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Получить ссылку на класс
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public static DataFileSingleton GetInstance()
|
||||
{
|
||||
if (_instance == null)
|
||||
@ -76,35 +35,10 @@ namespace ComputersShopFileImplement
|
||||
}
|
||||
return _instance;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Сохранение компонентов
|
||||
/// </summary>
|
||||
public void SaveComponents() => SaveData(Components, ComponentFileName, "Components", x => x.GetXElement);
|
||||
|
||||
/// <summary>
|
||||
/// Сохранение изделий
|
||||
/// </summary>
|
||||
public void SaveComputers() => SaveData(Computers, ComputerFileName, "Computers", x => x.GetXElement);
|
||||
|
||||
/// <summary>
|
||||
/// Сохранение заказов
|
||||
/// </summary>
|
||||
public void SaveOrders() => SaveData(Orders, OrderFileName, "Orders", x => x.GetXElement);
|
||||
|
||||
/// <summary>
|
||||
/// Сохранение магазинов
|
||||
/// </summary>
|
||||
public void SaveShops() => SaveData(Shops, ShopFileName, "Shops", x => x.GetXElement);
|
||||
|
||||
/// <summary>
|
||||
/// Метод для загрузки данных из xml-файла
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <param name="filename"></param>
|
||||
/// <param name="xmlNodeName"></param>
|
||||
/// <param name="selectFunction"></param>
|
||||
/// <returns></returns>
|
||||
private static List<T>? LoadData<T>(string filename, string xmlNodeName, Func<XElement, T> selectFunction)
|
||||
{
|
||||
if (File.Exists(filename))
|
||||
@ -113,15 +47,6 @@ namespace ComputersShopFileImplement
|
||||
}
|
||||
return new List<T>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Метод для сохранения данных в xml-файл
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <param name="data"></param>
|
||||
/// <param name="filename"></param>
|
||||
/// <param name="xmlNodeName"></param>
|
||||
/// <param name="selectFunction"></param>
|
||||
private static void SaveData<T>(List<T> data, string filename, string xmlNodeName, Func<T, XElement> selectFunction)
|
||||
{
|
||||
if (data != null)
|
||||
|
@ -14,67 +14,76 @@ namespace ComputersShopFileImplement.Implements
|
||||
{
|
||||
public class ComponentStorage : IComponentStorage
|
||||
{
|
||||
private readonly DataFileSingleton source;
|
||||
private readonly DataFileSingleton _source;
|
||||
public ComponentStorage()
|
||||
{
|
||||
source = DataFileSingleton.GetInstance();
|
||||
_source = DataFileSingleton.GetInstance();
|
||||
}
|
||||
public List<ComponentViewModel> GetFullList()
|
||||
{
|
||||
return source.Components.Select(x => x.GetViewModel).ToList();
|
||||
return _source.Components
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
public List<ComponentViewModel> GetFiltredList(ComponentSearchModel model)
|
||||
public List<ComponentViewModel> GetFilteredList(ComponentSearchModel model)
|
||||
{
|
||||
if (string.IsNullOrEmpty(model.ComponentName))
|
||||
{
|
||||
return new();
|
||||
}
|
||||
return source.Components
|
||||
|
||||
return _source.Components
|
||||
.Where(x => x.ComponentName.Contains(model.ComponentName))
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
public ComponentViewModel? GetElement(ComponentSearchModel model)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(model.ComponentName) && !model.Id.HasValue)
|
||||
if (string.IsNullOrEmpty(model.ComponentName) && !model.Id.HasValue)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return source.Components
|
||||
.FirstOrDefault(x => (!string.IsNullOrEmpty(model.ComponentName) &&
|
||||
x.ComponentName == model.ComponentName) || (model.Id.HasValue &&
|
||||
x.Id == model.Id))?.GetViewModel;
|
||||
|
||||
return _source.Components
|
||||
.FirstOrDefault(x =>
|
||||
(!string.IsNullOrEmpty(model.ComponentName) &&
|
||||
x.ComponentName == model.ComponentName) ||
|
||||
(model.Id.HasValue && x.Id == model.Id))
|
||||
?.GetViewModel;
|
||||
}
|
||||
public ComponentViewModel? Insert(ComponentBindingModel model)
|
||||
{
|
||||
model.Id = source.Components.Count > 0 ? source.Components.Max(x => x.Id) + 1 : 1;
|
||||
model.Id = _source.Components.Count > 0 ? _source.Components.Max(x => x.Id) + 1 : 1;
|
||||
|
||||
var newComponent = Component.Create(model);
|
||||
if (newComponent == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
source.Components.Add(newComponent);
|
||||
source.SaveComponents();
|
||||
|
||||
_source.Components.Add(newComponent);
|
||||
_source.SaveComponents();
|
||||
return newComponent.GetViewModel;
|
||||
}
|
||||
public ComponentViewModel? Update(ComponentBindingModel model)
|
||||
{
|
||||
var component = source.Components.FirstOrDefault(x => x.Id == model.Id);
|
||||
var component = _source.Components.FirstOrDefault(x => x.Id == model.Id);
|
||||
if (component == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
component.Update(model);
|
||||
source.SaveComponents();
|
||||
_source.SaveComponents();
|
||||
return component.GetViewModel;
|
||||
}
|
||||
public ComponentViewModel? Delete(ComponentBindingModel model)
|
||||
{
|
||||
var element = source.Components.FirstOrDefault(x => x.Id == model.Id);
|
||||
var element = _source.Components.FirstOrDefault(x => x.Id == model.Id);
|
||||
if (element != null)
|
||||
{
|
||||
source.Components.Remove(element);
|
||||
source.SaveComponents();
|
||||
_source.Components.Remove(element);
|
||||
_source.SaveComponents();
|
||||
return element.GetViewModel;
|
||||
}
|
||||
return null;
|
||||
|
@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Numerics;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using ComputersShopContracts.BindingModels;
|
||||
@ -13,67 +14,76 @@ namespace ComputersShopFileImplement.Implements
|
||||
{
|
||||
public class ComputerStorage : IComputerStorage
|
||||
{
|
||||
private readonly DataFileSingleton source;
|
||||
private readonly DataFileSingleton _source;
|
||||
public ComputerStorage()
|
||||
{
|
||||
source = DataFileSingleton.GetInstance();
|
||||
_source = DataFileSingleton.GetInstance();
|
||||
}
|
||||
public List<ComputerViewModel> GetFullList()
|
||||
{
|
||||
return source.Computers.Select(x => x.GetViewModel).ToList();
|
||||
return _source.Computers
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
public List<ComputerViewModel> GetFiltredList(ComputerSearchModel model)
|
||||
public List<ComputerViewModel> GetFilteredList(ComputerSearchModel model)
|
||||
{
|
||||
if (string.IsNullOrEmpty(model.ComputerName))
|
||||
{
|
||||
return new();
|
||||
}
|
||||
return source.Computers
|
||||
|
||||
return _source.Computers
|
||||
.Where(x => x.ComputerName.Contains(model.ComputerName))
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
public ComputerViewModel? GetElement(ComputerSearchModel model)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(model.ComputerName) && !model.Id.HasValue)
|
||||
if (string.IsNullOrEmpty(model.ComputerName) && !model.Id.HasValue)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return source.Computers
|
||||
.FirstOrDefault(x => (!string.IsNullOrEmpty(model.ComputerName) &&
|
||||
x.ComputerName == model.ComputerName) || (model.Id.HasValue &&
|
||||
x.Id == model.Id))?.GetViewModel;
|
||||
|
||||
return _source.Computers
|
||||
.FirstOrDefault(x =>
|
||||
(!string.IsNullOrEmpty(model.ComputerName) &&
|
||||
x.ComputerName == model.ComputerName) ||
|
||||
(model.Id.HasValue && x.Id == model.Id))
|
||||
?.GetViewModel;
|
||||
}
|
||||
public ComputerViewModel? Insert(ComputerBindingModel model)
|
||||
{
|
||||
model.Id = source.Computers.Count > 0 ? source.Components.Max(x => x.Id) + 1 : 1;
|
||||
model.Id = _source.Computers.Count > 0 ? _source.Computers.Max(x => x.Id) + 1 : 1;
|
||||
|
||||
var newComputer = Computer.Create(model);
|
||||
if (newComputer == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
source.Computers.Add(newComputer);
|
||||
source.SaveComputers();
|
||||
|
||||
_source.Computers.Add(newComputer);
|
||||
_source.SaveComputers();
|
||||
return newComputer.GetViewModel;
|
||||
}
|
||||
public ComputerViewModel? Update(ComputerBindingModel model)
|
||||
{
|
||||
var computer = source.Computers.FirstOrDefault(x => x.Id == model.Id);
|
||||
var computer = _source.Computers.FirstOrDefault(x => x.Id == model.Id);
|
||||
if (computer == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
computer.Update(model);
|
||||
source.SaveComputers();
|
||||
_source.SaveComputers();
|
||||
return computer.GetViewModel;
|
||||
}
|
||||
public ComputerViewModel? Delete(ComputerBindingModel model)
|
||||
{
|
||||
var element = source.Computers.FirstOrDefault(x => x.Id == model.Id);
|
||||
var element = _source.Computers.FirstOrDefault(x => x.Id == model.Id);
|
||||
if (element != null)
|
||||
{
|
||||
source.Computers.Remove(element);
|
||||
source.SaveComputers();
|
||||
_source.Computers.Remove(element);
|
||||
_source.SaveComputers();
|
||||
return element.GetViewModel;
|
||||
}
|
||||
return null;
|
||||
|
@ -14,31 +14,16 @@ namespace ComputersShopFileImplement.Implements
|
||||
public class OrderStorage : IOrderStorage
|
||||
{
|
||||
private readonly DataFileSingleton _source;
|
||||
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
/// </summary>
|
||||
public OrderStorage()
|
||||
{
|
||||
_source = DataFileSingleton.GetInstance();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Получение полного списка
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public List<OrderViewModel> GetFullList()
|
||||
{
|
||||
return _source.Orders
|
||||
.Select(x => GetViewModel(x))
|
||||
.ToList();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Получение фильтрованного списка
|
||||
/// </summary>
|
||||
/// <param name="model"></param>
|
||||
/// <returns></returns>
|
||||
public List<OrderViewModel> GetFilteredList(OrderSearchModel model)
|
||||
{
|
||||
if (!model.Id.HasValue)
|
||||
@ -51,12 +36,6 @@ namespace ComputersShopFileImplement.Implements
|
||||
.Select(x => GetViewModel(x))
|
||||
.ToList();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Получение элемента
|
||||
/// </summary>
|
||||
/// <param name="model"></param>
|
||||
/// <returns></returns>
|
||||
public OrderViewModel? GetElement(OrderSearchModel model)
|
||||
{
|
||||
if (!model.Id.HasValue)
|
||||
@ -67,12 +46,6 @@ namespace ComputersShopFileImplement.Implements
|
||||
return GetViewModel(_source.Orders
|
||||
.FirstOrDefault(x => (model.Id.HasValue && x.Id == model.Id)));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Добавление элемента
|
||||
/// </summary>
|
||||
/// <param name="model"></param>
|
||||
/// <returns></returns>
|
||||
public OrderViewModel? Insert(OrderBindingModel model)
|
||||
{
|
||||
model.Id = _source.Orders.Count > 0 ? _source.Orders.Max(x => x.Id) + 1 : 1;
|
||||
@ -87,12 +60,6 @@ namespace ComputersShopFileImplement.Implements
|
||||
_source.SaveOrders();
|
||||
return GetViewModel(newOrder);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Редактирование элемента
|
||||
/// </summary>
|
||||
/// <param name="model"></param>
|
||||
/// <returns></returns>
|
||||
public OrderViewModel? Update(OrderBindingModel model)
|
||||
{
|
||||
var order = _source.Orders.FirstOrDefault(x => x.Id == model.Id);
|
||||
@ -105,12 +72,6 @@ namespace ComputersShopFileImplement.Implements
|
||||
_source.SaveOrders();
|
||||
return GetViewModel(order);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Удаление элемента
|
||||
/// </summary>
|
||||
/// <param name="model"></param>
|
||||
/// <returns></returns>
|
||||
public OrderViewModel? Delete(OrderBindingModel model)
|
||||
{
|
||||
var element = _source.Orders.FirstOrDefault(x => x.Id == model.Id);
|
||||
@ -122,19 +83,13 @@ namespace ComputersShopFileImplement.Implements
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Получение модели заказа
|
||||
/// </summary>
|
||||
/// <param name="order"></param>
|
||||
/// <returns></returns>
|
||||
private OrderViewModel GetViewModel(Order order)
|
||||
{
|
||||
var viewModel = order.GetViewModel;
|
||||
var computer = _source.Computers.FirstOrDefault(x => x.Id == order.ComputerId);
|
||||
if (computer != null)
|
||||
var plane = _source.Computers.FirstOrDefault(x => x.Id == order.ComputerId);
|
||||
if (plane != null)
|
||||
{
|
||||
viewModel.ComputerName = computer.ComputerName;
|
||||
viewModel.ComputerName = plane.ComputerName;
|
||||
}
|
||||
return viewModel;
|
||||
}
|
||||
|
@ -14,35 +14,17 @@ namespace ComputersShopFileImplement.Implements
|
||||
{
|
||||
public class ShopStorage : IShopStorage
|
||||
{
|
||||
/// <summary>
|
||||
/// Хранилище
|
||||
/// </summary>
|
||||
private readonly DataFileSingleton _source;
|
||||
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
/// </summary>
|
||||
public ShopStorage()
|
||||
{
|
||||
_source = DataFileSingleton.GetInstance();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Получение полного списка
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public List<ShopViewModel> GetFullList()
|
||||
{
|
||||
return _source.Shops
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Получение фильтрованного списка
|
||||
/// </summary>
|
||||
/// <param name="model"></param>
|
||||
/// <returns></returns>
|
||||
public List<ShopViewModel> GetFilteredList(ShopSearchModel model)
|
||||
{
|
||||
if (string.IsNullOrEmpty(model.ShopName))
|
||||
@ -55,12 +37,6 @@ namespace ComputersShopFileImplement.Implements
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Получение элемента
|
||||
/// </summary>
|
||||
/// <param name="model"></param>
|
||||
/// <returns></returns>
|
||||
public ShopViewModel? GetElement(ShopSearchModel model)
|
||||
{
|
||||
if (string.IsNullOrEmpty(model.ShopName) && !model.Id.HasValue)
|
||||
@ -75,12 +51,6 @@ namespace ComputersShopFileImplement.Implements
|
||||
(model.Id.HasValue && x.Id == model.Id))
|
||||
?.GetViewModel;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Добавление элемента
|
||||
/// </summary>
|
||||
/// <param name="model"></param>
|
||||
/// <returns></returns>
|
||||
public ShopViewModel? Insert(ShopBindingModel model)
|
||||
{
|
||||
model.Id = _source.Shops.Count > 0 ? _source.Shops.Max(x => x.Id) + 1 : 1;
|
||||
@ -95,12 +65,6 @@ namespace ComputersShopFileImplement.Implements
|
||||
_source.SaveShops();
|
||||
return newShop.GetViewModel;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Редактирование элемента
|
||||
/// </summary>
|
||||
/// <param name="model"></param>
|
||||
/// <returns></returns>
|
||||
public ShopViewModel? Update(ShopBindingModel model)
|
||||
{
|
||||
var shop = _source.Shops.FirstOrDefault(x => x.Id == model.Id);
|
||||
@ -113,12 +77,6 @@ namespace ComputersShopFileImplement.Implements
|
||||
_source.SaveShops();
|
||||
return shop.GetViewModel;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Удаление элемента
|
||||
/// </summary>
|
||||
/// <param name="model"></param>
|
||||
/// <returns></returns>
|
||||
public ShopViewModel? Delete(ShopBindingModel model)
|
||||
{
|
||||
var element = _source.Shops.FirstOrDefault(x => x.Id == model.Id);
|
||||
@ -130,13 +88,6 @@ namespace ComputersShopFileImplement.Implements
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Продажа изделий
|
||||
/// </summary>
|
||||
/// <param name="model"></param>
|
||||
/// <param name="count"></param>
|
||||
/// <returns></returns>
|
||||
public bool SellComputers(IComputerModel model, int count)
|
||||
{
|
||||
var computer = _source.Computers.FirstOrDefault(x => x.Id == model.Id);
|
||||
@ -174,13 +125,6 @@ namespace ComputersShopFileImplement.Implements
|
||||
_source.SaveShops();
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Проверка наличия в нужном количестве
|
||||
/// </summary>
|
||||
/// <param name="model"></param>
|
||||
/// <param name="count"></param>
|
||||
/// <returns></returns>
|
||||
public bool CheckCount(IComputerModel model, int count)
|
||||
{
|
||||
int store = _source.Shops
|
||||
|
@ -16,12 +16,13 @@ namespace ComputersShopFileImplement.Models
|
||||
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)
|
||||
public static Component? Create(ComponentBindingModel? model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return new Component()
|
||||
{
|
||||
Id = model.Id,
|
||||
@ -35,6 +36,7 @@ namespace ComputersShopFileImplement.Models
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return new Component()
|
||||
{
|
||||
Id = Convert.ToInt32(element.Attribute("Id")!.Value),
|
||||
@ -42,12 +44,13 @@ namespace ComputersShopFileImplement.Models
|
||||
Cost = Convert.ToDouble(element.Element("Cost")!.Value)
|
||||
};
|
||||
}
|
||||
public void Update(ComponentBindingModel model)
|
||||
public void Update(ComponentBindingModel? model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
ComponentName = model.ComponentName;
|
||||
Cost = model.Cost;
|
||||
}
|
||||
@ -58,8 +61,8 @@ namespace ComputersShopFileImplement.Models
|
||||
Cost = Cost
|
||||
};
|
||||
public XElement GetXElement => new("Component",
|
||||
new XAttribute("Id", Id),
|
||||
new XElement("ComponentName", ComponentName),
|
||||
new XElement("Cost", Cost.ToString()));
|
||||
new XAttribute("Id", Id),
|
||||
new XElement("ComponentName", ComponentName),
|
||||
new XElement("Cost", Cost.ToString()));
|
||||
}
|
||||
}
|
||||
|
@ -7,6 +7,7 @@ using ComputersShopContracts.BindingModels;
|
||||
using ComputersShopContracts.ViewModels;
|
||||
using ComputersShopDataModels.Models;
|
||||
using System.Xml.Linq;
|
||||
using System.Numerics;
|
||||
|
||||
namespace ComputersShopFileImplement.Models
|
||||
{
|
||||
@ -24,19 +25,18 @@ namespace ComputersShopFileImplement.Models
|
||||
if (_computerComponents == null)
|
||||
{
|
||||
var source = DataFileSingleton.GetInstance();
|
||||
_computerComponents = Components.ToDictionary(x => x.Key, y =>
|
||||
((source.Components.FirstOrDefault(z => z.Id == y.Key) as IComponentModel)!,
|
||||
y.Value));
|
||||
_computerComponents = Components.ToDictionary(x => x.Key, y => ((source.Components.FirstOrDefault(z => z.Id == y.Key) as IComponentModel)!, y.Value));
|
||||
}
|
||||
return _computerComponents;
|
||||
}
|
||||
}
|
||||
public static Computer? Create(ComputerBindingModel model)
|
||||
public static Computer? Create(ComputerBindingModel? model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return new Computer()
|
||||
{
|
||||
Id = model.Id,
|
||||
@ -51,24 +51,23 @@ namespace ComputersShopFileImplement.Models
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return new Computer()
|
||||
{
|
||||
Id = Convert.ToInt32(element.Attribute("Id")!.Value),
|
||||
ComputerName = element.Element("ComputerName")!.Value,
|
||||
Price = Convert.ToDouble(element.Element("Price")!.Value),
|
||||
Components =
|
||||
element.Element("ComputerComponents")!.Elements("ComputerComponent")
|
||||
.ToDictionary(x =>
|
||||
Convert.ToInt32(x.Element("Key")?.Value), x =>
|
||||
Convert.ToInt32(x.Element("Value")?.Value))
|
||||
Components = element.Element("ComputerComponents")!.Elements("ComputerComponent")
|
||||
.ToDictionary(x => Convert.ToInt32(x.Element("Key")?.Value), x => Convert.ToInt32(x.Element("Value")?.Value))
|
||||
};
|
||||
}
|
||||
public void Update(ComputerBindingModel model)
|
||||
public void Update(ComputerBindingModel? model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
ComputerName = model.ComputerName;
|
||||
Price = model.Price;
|
||||
Components = model.ComputerComponents.ToDictionary(x => x.Key, x => x.Value.Item2);
|
||||
@ -86,8 +85,10 @@ namespace ComputersShopFileImplement.Models
|
||||
new XElement("ComputerName", ComputerName),
|
||||
new XElement("Price", Price.ToString()),
|
||||
new XElement("ComputerComponents", Components.Select(x =>
|
||||
new XElement("ComputerComponent", new XElement("Key", x.Key),
|
||||
new XElement("Value", x.Value))).ToArray()));
|
||||
new XElement("ComputerComponent",
|
||||
new XElement("Key", x.Key),
|
||||
new XElement("Value", x.Value)))
|
||||
.ToArray()));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -12,35 +12,11 @@ namespace ComputersShopFileImplement.Models
|
||||
{
|
||||
public class Shop : IShopModel
|
||||
{
|
||||
/// <summary>
|
||||
/// Идентификатор
|
||||
/// </summary>
|
||||
public int Id { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Название магазина
|
||||
/// </summary>
|
||||
public string ShopName { get; private set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// Адрес магазина
|
||||
/// </summary>
|
||||
public string Address { get; private set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// Дата открытия магазина
|
||||
/// </summary>
|
||||
public DateTime DateOpening { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Коллекция изделий магазина в виде
|
||||
/// «идентификатор изделия – количество изделий»
|
||||
/// </summary>
|
||||
public Dictionary<int, int> Computers { get; private set; } = new();
|
||||
|
||||
/// <summary>
|
||||
/// Коллекция изделий в магазине
|
||||
/// </summary>
|
||||
private Dictionary<int, (IComputerModel, int)>? _shopComputers = null;
|
||||
public Dictionary<int, (IComputerModel, int)> ShopComputers
|
||||
{
|
||||
@ -54,17 +30,7 @@ namespace ComputersShopFileImplement.Models
|
||||
return _shopComputers;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Максимальное количество изделий
|
||||
/// </summary>
|
||||
public int MaxComputers { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Создание модели магазина из данных файла
|
||||
/// </summary>
|
||||
/// <param name="element"></param>
|
||||
/// <returns></returns>
|
||||
public static Shop? Create(XElement element)
|
||||
{
|
||||
if (element == null)
|
||||
@ -82,12 +48,6 @@ namespace ComputersShopFileImplement.Models
|
||||
MaxComputers = Convert.ToInt32(element.Element("MaxComputers")!.Value)
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Создание модели магазина
|
||||
/// </summary>
|
||||
/// <param name="model"></param>
|
||||
/// <returns></returns>
|
||||
public static Shop? Create(ShopBindingModel? model)
|
||||
{
|
||||
if (model == null)
|
||||
@ -105,11 +65,6 @@ namespace ComputersShopFileImplement.Models
|
||||
MaxComputers = model.MaxComputers
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Изменение модели магазина
|
||||
/// </summary>
|
||||
/// <param name="model"></param>
|
||||
public void Update(ShopBindingModel? model)
|
||||
{
|
||||
if (model == null)
|
||||
@ -124,10 +79,6 @@ namespace ComputersShopFileImplement.Models
|
||||
MaxComputers = model.MaxComputers;
|
||||
_shopComputers = null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Получение модели магазина
|
||||
/// </summary>
|
||||
public ShopViewModel GetViewModel => new()
|
||||
{
|
||||
Id = Id,
|
||||
@ -137,10 +88,6 @@ namespace ComputersShopFileImplement.Models
|
||||
ShopComputers = ShopComputers,
|
||||
MaxComputers = MaxComputers
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// Запись данных о модели магазина в файл
|
||||
/// </summary>
|
||||
public XElement GetXElement => new("Shop",
|
||||
new XAttribute("Id", Id),
|
||||
new XElement("ShopName", ShopName),
|
||||
|
@ -11,30 +11,10 @@ namespace AbstractShopListImplement
|
||||
public class DataListSingleton
|
||||
{
|
||||
private static DataListSingleton? _instance;
|
||||
|
||||
/// <summary>
|
||||
/// Список классов-моделей компонентов
|
||||
/// </summary>
|
||||
public List<Component> Components { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Список классов-моделей заказов
|
||||
/// </summary>
|
||||
public List<Order> Orders { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Список классов-моделей изделий
|
||||
/// </summary>
|
||||
public List<Computer> Computers { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Список классов-моделей магазинов
|
||||
/// </summary>
|
||||
public List<Shop> Shops { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
/// </summary>
|
||||
private DataListSingleton()
|
||||
{
|
||||
Components = new List<Component>();
|
||||
@ -42,11 +22,6 @@ namespace AbstractShopListImplement
|
||||
Computers = new List<Computer>();
|
||||
Shops = new List<Shop>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Получить ссылку на класс
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public static DataListSingleton GetInstance()
|
||||
{
|
||||
if (_instance == null)
|
||||
|
@ -28,7 +28,7 @@ namespace ComputersShopListImplement.Implements
|
||||
}
|
||||
return result;
|
||||
}
|
||||
public List<ComponentViewModel> GetFiltredList(ComponentSearchModel model)
|
||||
public List<ComponentViewModel> GetFilteredList(ComponentSearchModel model)
|
||||
{
|
||||
var result = new List<ComponentViewModel>();
|
||||
if (string.IsNullOrEmpty(model.ComponentName))
|
||||
|
@ -28,7 +28,7 @@ namespace ComputersShopListImplement.Implements
|
||||
}
|
||||
return result;
|
||||
}
|
||||
public List<ComputerViewModel> GetFiltredList(ComputerSearchModel model)
|
||||
public List<ComputerViewModel> GetFilteredList(ComputerSearchModel model)
|
||||
{
|
||||
var result = new List<ComputerViewModel>();
|
||||
if (string.IsNullOrEmpty(model.ComputerName))
|
||||
|
@ -15,19 +15,10 @@ namespace ComputersShopListImplement.Implements
|
||||
public class OrderStorage : IOrderStorage
|
||||
{
|
||||
private readonly DataListSingleton _source;
|
||||
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
/// </summary>
|
||||
public OrderStorage()
|
||||
{
|
||||
_source = DataListSingleton.GetInstance();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Получение полного списка
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public List<OrderViewModel> GetFullList()
|
||||
{
|
||||
var result = new List<OrderViewModel>();
|
||||
@ -37,12 +28,6 @@ namespace ComputersShopListImplement.Implements
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Получение фильтрованного списка
|
||||
/// </summary>
|
||||
/// <param name="model"></param>
|
||||
/// <returns></returns>
|
||||
public List<OrderViewModel> GetFilteredList(OrderSearchModel model)
|
||||
{
|
||||
var result = new List<OrderViewModel>();
|
||||
@ -60,12 +45,6 @@ namespace ComputersShopListImplement.Implements
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Получение элемента
|
||||
/// </summary>
|
||||
/// <param name="model"></param>
|
||||
/// <returns></returns>
|
||||
public OrderViewModel? GetElement(OrderSearchModel model)
|
||||
{
|
||||
if (!model.Id.HasValue)
|
||||
@ -82,12 +61,6 @@ namespace ComputersShopListImplement.Implements
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Добавление элемента
|
||||
/// </summary>
|
||||
/// <param name="model"></param>
|
||||
/// <returns></returns>
|
||||
public OrderViewModel? Insert(OrderBindingModel model)
|
||||
{
|
||||
model.Id = 1;
|
||||
@ -108,12 +81,6 @@ namespace ComputersShopListImplement.Implements
|
||||
_source.Orders.Add(newOrder);
|
||||
return newOrder.GetViewModel;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Редактирование элемента
|
||||
/// </summary>
|
||||
/// <param name="model"></param>
|
||||
/// <returns></returns>
|
||||
public OrderViewModel? Update(OrderBindingModel model)
|
||||
{
|
||||
foreach (var order in _source.Orders)
|
||||
@ -126,12 +93,6 @@ namespace ComputersShopListImplement.Implements
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Удаление элемента
|
||||
/// </summary>
|
||||
/// <param name="model"></param>
|
||||
/// <returns></returns>
|
||||
public OrderViewModel? Delete(OrderBindingModel model)
|
||||
{
|
||||
for (int i = 0; i < _source.Orders.Count; ++i)
|
||||
|
@ -17,19 +17,10 @@ namespace ComputersShopListImplement.Implements
|
||||
public class ShopStorage : IShopStorage
|
||||
{
|
||||
private readonly DataListSingleton _source;
|
||||
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
/// </summary>
|
||||
public ShopStorage()
|
||||
{
|
||||
_source = DataListSingleton.GetInstance();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Получение полного списка
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public List<ShopViewModel> GetFullList()
|
||||
{
|
||||
var result = new List<ShopViewModel>();
|
||||
@ -39,12 +30,6 @@ namespace ComputersShopListImplement.Implements
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Получение фильтрованного списка
|
||||
/// </summary>
|
||||
/// <param name="model"></param>
|
||||
/// <returns></returns>
|
||||
public List<ShopViewModel> GetFilteredList(ShopSearchModel model)
|
||||
{
|
||||
var result = new List<ShopViewModel>();
|
||||
@ -62,12 +47,6 @@ namespace ComputersShopListImplement.Implements
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Получение элемента
|
||||
/// </summary>
|
||||
/// <param name="model"></param>
|
||||
/// <returns></returns>
|
||||
public ShopViewModel? GetElement(ShopSearchModel model)
|
||||
{
|
||||
if (string.IsNullOrEmpty(model.ShopName) && !model.Id.HasValue)
|
||||
@ -84,12 +63,6 @@ namespace ComputersShopListImplement.Implements
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Добавление элемента
|
||||
/// </summary>
|
||||
/// <param name="model"></param>
|
||||
/// <returns></returns>
|
||||
public ShopViewModel? Insert(ShopBindingModel model)
|
||||
{
|
||||
model.Id = 1;
|
||||
@ -110,12 +83,6 @@ namespace ComputersShopListImplement.Implements
|
||||
_source.Shops.Add(newShop);
|
||||
return newShop.GetViewModel;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Редактирование элемента
|
||||
/// </summary>
|
||||
/// <param name="model"></param>
|
||||
/// <returns></returns>
|
||||
public ShopViewModel? Update(ShopBindingModel model)
|
||||
{
|
||||
foreach (var shop in _source.Shops)
|
||||
@ -128,12 +95,6 @@ namespace ComputersShopListImplement.Implements
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Удаление элемента
|
||||
/// </summary>
|
||||
/// <param name="model"></param>
|
||||
/// <returns></returns>
|
||||
public ShopViewModel? Delete(ShopBindingModel model)
|
||||
{
|
||||
for (int i = 0; i < _source.Shops.Count; ++i)
|
||||
@ -147,26 +108,10 @@ namespace ComputersShopListImplement.Implements
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Продажа изделий
|
||||
/// </summary>
|
||||
/// <param name="computer"></param>
|
||||
/// <param name="count"></param>
|
||||
/// <returns></returns>
|
||||
/// <exception cref="NotImplementedException"></exception>
|
||||
public bool SellComputers(IComputerModel model, int count)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Проверка наличия в нужном количестве
|
||||
/// </summary>
|
||||
/// <param name="model"></param>
|
||||
/// <param name="count"></param>
|
||||
/// <returns></returns>
|
||||
/// <exception cref="NotImplementedException"></exception>
|
||||
public bool CheckCount(IComputerModel model, int count)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
|
@ -13,41 +13,15 @@ namespace ComputersShopListImplement.Models
|
||||
public class Shop : IShopModel
|
||||
{
|
||||
public int Id { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Название магазина
|
||||
/// </summary>
|
||||
public string ShopName { get; private set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// Адрес магазина
|
||||
/// </summary>
|
||||
public string Address { get; private set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// Дата открытия магазина
|
||||
/// </summary>
|
||||
public DateTime DateOpening { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Коллекция изделий в магазине
|
||||
/// </summary>
|
||||
public Dictionary<int, (IComputerModel, int)> ShopComputers
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
} = new Dictionary<int, (IComputerModel, int)>();
|
||||
|
||||
/// <summary>
|
||||
/// Максимальное количество изделий
|
||||
/// </summary>
|
||||
public int MaxComputers { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Создание модели магазина
|
||||
/// </summary>
|
||||
/// <param name="model"></param>
|
||||
/// <returns></returns>
|
||||
public static Shop? Create(ShopBindingModel? model)
|
||||
{
|
||||
if (model == null)
|
||||
@ -65,11 +39,6 @@ namespace ComputersShopListImplement.Models
|
||||
MaxComputers = model.MaxComputers
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Изменение модели магазина
|
||||
/// </summary>
|
||||
/// <param name="model"></param>
|
||||
public void Update(ShopBindingModel? model)
|
||||
{
|
||||
if (model == null)
|
||||
@ -83,10 +52,6 @@ namespace ComputersShopListImplement.Models
|
||||
ShopComputers = model.ShopComputers;
|
||||
MaxComputers = model.MaxComputers;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Получение модели магазина
|
||||
/// </summary>
|
||||
public ShopViewModel GetViewModel => new()
|
||||
{
|
||||
Id = Id,
|
||||
|
15
ComputersShop/ComputersShopView/FormMain.Designer.cs
generated
15
ComputersShop/ComputersShopView/FormMain.Designer.cs
generated
@ -34,13 +34,13 @@
|
||||
this.изделияToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.магазиныToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.поставкиToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.продажаИзделийToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.dataGridView = new System.Windows.Forms.DataGridView();
|
||||
this.buttonCreateOrder = new System.Windows.Forms.Button();
|
||||
this.buttonTakeOrderInWork = new System.Windows.Forms.Button();
|
||||
this.buttonOrderReady = new System.Windows.Forms.Button();
|
||||
this.buttonIssuedOrder = new System.Windows.Forms.Button();
|
||||
this.buttonRef = new System.Windows.Forms.Button();
|
||||
this.продажаИзделийToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.menuStrip1.SuspendLayout();
|
||||
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit();
|
||||
this.SuspendLayout();
|
||||
@ -96,6 +96,13 @@
|
||||
this.поставкиToolStripMenuItem.Text = "Поставки";
|
||||
this.поставкиToolStripMenuItem.Click += new System.EventHandler(this.ПоставкиToolStripMenuItem_Click);
|
||||
//
|
||||
// продажаИзделийToolStripMenuItem
|
||||
//
|
||||
this.продажаИзделийToolStripMenuItem.Name = "продажаИзделийToolStripMenuItem";
|
||||
this.продажаИзделийToolStripMenuItem.Size = new System.Drawing.Size(224, 26);
|
||||
this.продажаИзделийToolStripMenuItem.Text = "Продажа изделий";
|
||||
this.продажаИзделийToolStripMenuItem.Click += new System.EventHandler(this.ПродажаизделийToolStripMenuItem_Click);
|
||||
//
|
||||
// dataGridView
|
||||
//
|
||||
this.dataGridView.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
|
||||
@ -159,12 +166,6 @@
|
||||
this.buttonRef.UseVisualStyleBackColor = true;
|
||||
this.buttonRef.Click += new System.EventHandler(this.ButtonRef_Click);
|
||||
//
|
||||
// продажаИзделийToolStripMenuItem
|
||||
//
|
||||
this.продажаИзделийToolStripMenuItem.Name = "продажаИзделийToolStripMenuItem";
|
||||
this.продажаИзделийToolStripMenuItem.Size = new System.Drawing.Size(224, 26);
|
||||
this.продажаИзделийToolStripMenuItem.Text = "Продажа изделий";
|
||||
//
|
||||
// FormMain
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
|
||||
|
@ -39,16 +39,16 @@
|
||||
// dataGridViewShops
|
||||
//
|
||||
this.dataGridViewShops.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
|
||||
this.dataGridViewShops.Location = new System.Drawing.Point(1, 0);
|
||||
this.dataGridViewShops.Location = new System.Drawing.Point(3, 1);
|
||||
this.dataGridViewShops.Name = "dataGridViewShops";
|
||||
this.dataGridViewShops.RowHeadersWidth = 51;
|
||||
this.dataGridViewShops.RowTemplate.Height = 29;
|
||||
this.dataGridViewShops.Size = new System.Drawing.Size(415, 453);
|
||||
this.dataGridViewShops.Size = new System.Drawing.Size(572, 453);
|
||||
this.dataGridViewShops.TabIndex = 0;
|
||||
//
|
||||
// buttonAdd
|
||||
//
|
||||
this.buttonAdd.Location = new System.Drawing.Point(434, 39);
|
||||
this.buttonAdd.Location = new System.Drawing.Point(605, 41);
|
||||
this.buttonAdd.Name = "buttonAdd";
|
||||
this.buttonAdd.Size = new System.Drawing.Size(94, 29);
|
||||
this.buttonAdd.TabIndex = 1;
|
||||
@ -58,7 +58,7 @@
|
||||
//
|
||||
// buttonUpdate
|
||||
//
|
||||
this.buttonUpdate.Location = new System.Drawing.Point(434, 94);
|
||||
this.buttonUpdate.Location = new System.Drawing.Point(605, 96);
|
||||
this.buttonUpdate.Name = "buttonUpdate";
|
||||
this.buttonUpdate.Size = new System.Drawing.Size(94, 29);
|
||||
this.buttonUpdate.TabIndex = 2;
|
||||
@ -68,7 +68,7 @@
|
||||
//
|
||||
// buttonDelete
|
||||
//
|
||||
this.buttonDelete.Location = new System.Drawing.Point(434, 143);
|
||||
this.buttonDelete.Location = new System.Drawing.Point(605, 145);
|
||||
this.buttonDelete.Name = "buttonDelete";
|
||||
this.buttonDelete.Size = new System.Drawing.Size(94, 29);
|
||||
this.buttonDelete.TabIndex = 3;
|
||||
@ -78,7 +78,7 @@
|
||||
//
|
||||
// buttonRefresh
|
||||
//
|
||||
this.buttonRefresh.Location = new System.Drawing.Point(434, 195);
|
||||
this.buttonRefresh.Location = new System.Drawing.Point(605, 197);
|
||||
this.buttonRefresh.Name = "buttonRefresh";
|
||||
this.buttonRefresh.Size = new System.Drawing.Size(94, 29);
|
||||
this.buttonRefresh.TabIndex = 4;
|
||||
@ -90,7 +90,7 @@
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(554, 450);
|
||||
this.ClientSize = new System.Drawing.Size(733, 450);
|
||||
this.Controls.Add(this.buttonRefresh);
|
||||
this.Controls.Add(this.buttonDelete);
|
||||
this.Controls.Add(this.buttonUpdate);
|
||||
|
@ -1,7 +1,7 @@
|
||||
using ComputersShopBusinessLogic.BusinessLogics;
|
||||
using ComputersShopContracts.BusinessLogicsContracts;
|
||||
using ComputersShopContracts.StoragesContracts;
|
||||
using ComputersShopListImplement.Implements;
|
||||
using ComputersShopFileImplement.Implements;
|
||||
using ComputersShopView;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
Loading…
Reference in New Issue
Block a user