AutoWorkshopFileImplement/Implements
This commit is contained in:
parent
e3a1f15b7c
commit
82ce660a86
82
AutoWorkshopFileImplement/Implements/ComponentStorage.cs
Normal file
82
AutoWorkshopFileImplement/Implements/ComponentStorage.cs
Normal file
@ -0,0 +1,82 @@
|
||||
using AutoWorkshopContracts.BindingModels;
|
||||
using AutoWorkshopContracts.SearchModels;
|
||||
using AutoWorkshopContracts.StoragesContracts;
|
||||
using AutoWorkshopContracts.ViewModels;
|
||||
using AutoWorkshopFileImplement.Models;
|
||||
|
||||
namespace AutoWorkshopFileImplement.Implements
|
||||
{
|
||||
public class ComponentStorage : IComponentStorage
|
||||
{
|
||||
private readonly DataFileSingleton _source;
|
||||
|
||||
public ComponentStorage()
|
||||
{
|
||||
_source = DataFileSingleton.GetInstance();
|
||||
}
|
||||
|
||||
public List<ComponentViewModel> GetFullList()
|
||||
{
|
||||
return _source.Components.Select(x => x.GetViewModel).ToList();
|
||||
}
|
||||
|
||||
public List<ComponentViewModel> GetFilteredList(ComponentSearchModel Model)
|
||||
{
|
||||
if (string.IsNullOrEmpty(Model.ComponentName))
|
||||
return new();
|
||||
|
||||
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)
|
||||
return null;
|
||||
|
||||
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;
|
||||
|
||||
var NewComponent = Component.Create(Model);
|
||||
|
||||
if (NewComponent == null)
|
||||
return null;
|
||||
|
||||
_source.Components.Add(NewComponent);
|
||||
_source.SaveComponents();
|
||||
|
||||
return NewComponent.GetViewModel;
|
||||
}
|
||||
|
||||
public ComponentViewModel? Update(ComponentBindingModel Model)
|
||||
{
|
||||
var Component = _source.Components.FirstOrDefault(x => x.Id == Model.Id);
|
||||
|
||||
if (Component == null)
|
||||
return null;
|
||||
|
||||
Component.Update(Model);
|
||||
_source.SaveComponents();
|
||||
|
||||
return Component.GetViewModel;
|
||||
}
|
||||
|
||||
public ComponentViewModel? Delete(ComponentBindingModel Model)
|
||||
{
|
||||
var Component = _source.Components.FirstOrDefault(x => x.Id == Model.Id);
|
||||
|
||||
if (Component == null)
|
||||
return null;
|
||||
|
||||
_source.Components.Remove(Component);
|
||||
_source.SaveComponents();
|
||||
|
||||
return Component.GetViewModel;
|
||||
}
|
||||
}
|
||||
}
|
96
AutoWorkshopFileImplement/Implements/OrderStorage.cs
Normal file
96
AutoWorkshopFileImplement/Implements/OrderStorage.cs
Normal file
@ -0,0 +1,96 @@
|
||||
using AutoWorkshopContracts.BindingModels;
|
||||
using AutoWorkshopContracts.SearchModels;
|
||||
using AutoWorkshopContracts.StoragesContracts;
|
||||
using AutoWorkshopContracts.ViewModels;
|
||||
using AutoWorkshopFileImplement.Models;
|
||||
using System.Reflection;
|
||||
|
||||
namespace AutoWorkshopFileImplement.Implements
|
||||
{
|
||||
public class OrderStorage : IOrderStorage
|
||||
{
|
||||
private readonly DataFileSingleton _source;
|
||||
|
||||
public OrderStorage()
|
||||
{
|
||||
_source = DataFileSingleton.GetInstance();
|
||||
}
|
||||
|
||||
public List<OrderViewModel> GetFullList()
|
||||
{
|
||||
return _source.Orders.Select(x => AddRepairName(x.GetViewModel)).ToList();
|
||||
}
|
||||
|
||||
public List<OrderViewModel> GetFilteredList(OrderSearchModel Model)
|
||||
{
|
||||
if (!Model.Id.HasValue)
|
||||
return new();
|
||||
|
||||
return _source.Orders.Where(x => x.Id == Model.Id).Select(x => AddRepairName(x.GetViewModel)).ToList();
|
||||
}
|
||||
|
||||
public OrderViewModel? Delete(OrderBindingModel Model)
|
||||
{
|
||||
var Element = _source.Orders.FirstOrDefault(x => x.Id == Model.Id);
|
||||
|
||||
if (Element != null)
|
||||
{
|
||||
_source.Orders.Remove(Element);
|
||||
_source.SaveOrders();
|
||||
|
||||
return AddRepairName(Element.GetViewModel);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public OrderViewModel? GetElement(OrderSearchModel Model)
|
||||
{
|
||||
if (!Model.Id.HasValue)
|
||||
return null;
|
||||
|
||||
var Order = _source.Orders.FirstOrDefault(x => (Model.Id.HasValue && x.Id == Model.Id));
|
||||
|
||||
if (Order == null)
|
||||
return null;
|
||||
|
||||
return AddRepairName(Order.GetViewModel);
|
||||
}
|
||||
|
||||
public OrderViewModel? Insert(OrderBindingModel Model)
|
||||
{
|
||||
Model.Id = _source.Orders.Count > 0 ? _source.Orders.Max(x => x.Id) + 1 : 1;
|
||||
|
||||
var NewOrder = Order.Create(Model);
|
||||
|
||||
if (NewOrder == null)
|
||||
return null;
|
||||
|
||||
_source.Orders.Add(NewOrder);
|
||||
_source.SaveOrders();
|
||||
|
||||
return AddRepairName(NewOrder.GetViewModel);
|
||||
}
|
||||
|
||||
public OrderViewModel? Update(OrderBindingModel Model)
|
||||
{
|
||||
var Order = _source.Orders.FirstOrDefault(x => x.Id == Model.Id);
|
||||
|
||||
if (Order == null)
|
||||
return null;
|
||||
|
||||
Order.Update(Model);
|
||||
_source.SaveOrders();
|
||||
|
||||
return AddRepairName(Order.GetViewModel);
|
||||
}
|
||||
|
||||
private OrderViewModel AddRepairName(OrderViewModel Model)
|
||||
{
|
||||
var SelectedRepair = _source.Repairs.FirstOrDefault(x => x.Id == Model.RepairId);
|
||||
|
||||
Model.RepairName = SelectedRepair?.RepairName ?? string.Empty;
|
||||
return Model;
|
||||
}
|
||||
}
|
||||
}
|
80
AutoWorkshopFileImplement/Implements/RepairStorage.cs
Normal file
80
AutoWorkshopFileImplement/Implements/RepairStorage.cs
Normal file
@ -0,0 +1,80 @@
|
||||
using AutoWorkshopContracts.BindingModels;
|
||||
using AutoWorkshopContracts.SearchModels;
|
||||
using AutoWorkshopContracts.StoragesContracts;
|
||||
using AutoWorkshopContracts.ViewModels;
|
||||
using AutoWorkshopFileImplement.Models;
|
||||
|
||||
namespace AutoWorkshopFileImplement.Implements
|
||||
{
|
||||
public class RepairStorage : IRepairStorage
|
||||
{
|
||||
private readonly DataFileSingleton _source;
|
||||
|
||||
public RepairStorage()
|
||||
{
|
||||
_source = DataFileSingleton.GetInstance();
|
||||
}
|
||||
|
||||
public List<RepairViewModel> GetFullList()
|
||||
{
|
||||
return _source.Repairs.Select(x => x.GetViewModel).ToList();
|
||||
}
|
||||
|
||||
public List<RepairViewModel> GetFilteredList(RepairSearchModel Model)
|
||||
{
|
||||
if (string.IsNullOrEmpty(Model.RepairName))
|
||||
return new();
|
||||
|
||||
return _source.Repairs.Where(x => x.RepairName.Contains(Model.RepairName)).Select(x => x.GetViewModel).ToList();
|
||||
}
|
||||
|
||||
public RepairViewModel? GetElement(RepairSearchModel Model)
|
||||
{
|
||||
if (string.IsNullOrEmpty(Model.RepairName) && !Model.Id.HasValue)
|
||||
return null;
|
||||
|
||||
return _source.Repairs.FirstOrDefault(x => (!string.IsNullOrEmpty(Model.RepairName) && x.RepairName == Model.RepairName) || (Model.Id.HasValue && x.Id == Model.Id))?.GetViewModel;
|
||||
}
|
||||
|
||||
public RepairViewModel? Insert(RepairBindingModel Model)
|
||||
{
|
||||
Model.Id = _source.Repairs.Count > 0 ? _source.Repairs.Max(x => x.Id) + 1 : 1;
|
||||
|
||||
var NewRepair = Repair.Create(Model);
|
||||
|
||||
if (NewRepair == null)
|
||||
return null;
|
||||
|
||||
_source.Repairs.Add(NewRepair);
|
||||
_source.SaveRepairs();
|
||||
|
||||
return NewRepair.GetViewModel;
|
||||
}
|
||||
|
||||
public RepairViewModel? Update(RepairBindingModel Model)
|
||||
{
|
||||
var Repair = _source.Repairs.FirstOrDefault(x => x.Id == Model.Id);
|
||||
|
||||
if (Repair == null)
|
||||
return null;
|
||||
|
||||
Repair.Update(Model);
|
||||
_source.SaveRepairs();
|
||||
|
||||
return Repair.GetViewModel;
|
||||
}
|
||||
|
||||
public RepairViewModel? Delete(RepairBindingModel Model)
|
||||
{
|
||||
var Repair = _source.Repairs.FirstOrDefault(x => x.Id == Model.Id);
|
||||
|
||||
if (Repair == null)
|
||||
return null;
|
||||
|
||||
_source.Repairs.Remove(Repair);
|
||||
_source.SaveRepairs();
|
||||
|
||||
return Repair.GetViewModel;
|
||||
}
|
||||
}
|
||||
}
|
@ -24,7 +24,8 @@ namespace AutoWorkshopFileImplement.Models
|
||||
if (_RepairComponents == null)
|
||||
{
|
||||
var source = DataFileSingleton.GetInstance();
|
||||
_RepairComponents = Components.ToDictionary(x => x.Key, y => ((source.Components.FirstOrDefault(z => z.Id == y.Key) as IComponentModel)!, y.Value));
|
||||
_RepairComponents = Components.ToDictionary(x =>
|
||||
x.Key, y => ((source.Components.FirstOrDefault(z => z.Id == y.Key) as IComponentModel)!, y.Value));
|
||||
}
|
||||
return _RepairComponents;
|
||||
}
|
||||
@ -53,7 +54,8 @@ namespace AutoWorkshopFileImplement.Models
|
||||
Id = Convert.ToInt32(Element.Attribute("Id")!.Value),
|
||||
RepairName = Element.Element("RepairName")!.Value,
|
||||
Price = Convert.ToDouble(Element.Element("Price")!.Value),
|
||||
Components = Element.Element("RepairComponents")!.Elements("RepairComponent").ToDictionary(x => Convert.ToInt32(x.Element("Key")?.Value), x => Convert.ToInt32(x.Element("Value")?.Value))
|
||||
Components = Element.Element("RepairComponents")!.Elements("RepairComponent").ToDictionary(x =>
|
||||
Convert.ToInt32(x.Element("Key")?.Value), x => Convert.ToInt32(x.Element("Value")?.Value))
|
||||
};
|
||||
}
|
||||
|
||||
@ -81,7 +83,8 @@ namespace AutoWorkshopFileImplement.Models
|
||||
new XAttribute("Id", Id),
|
||||
new XElement("RepairName", RepairName),
|
||||
new XElement("Price", Price.ToString()),
|
||||
new XElement("RepairComponents", Components.Select(x => new XElement("RepairComponent", new XElement("Key", x.Key), new XElement("Value", x.Value))).ToArray())
|
||||
new XElement("RepairComponents", Components.Select(x =>
|
||||
new XElement("RepairComponent", new XElement("Key", x.Key), new XElement("Value", x.Value))).ToArray())
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
using AutoWorkshopBusinessLogic.BusinessLogics;
|
||||
using AutoWorkshopContracts.BusinessLogicContracts;
|
||||
using AutoWorkshopContracts.StoragesContracts;
|
||||
using AutoWorkshopListImplement.Implements;
|
||||
using AutoWorkshopFileImplement.Implements;
|
||||
using AutoWorkshopView.Forms;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
Loading…
Reference in New Issue
Block a user