ListImplement
This commit is contained in:
parent
8ad6e9478e
commit
8447239146
@ -11,12 +11,15 @@ namespace AutoWorkshopListImplement
|
||||
public List<Order> Orders { get; set; }
|
||||
|
||||
public List<Repair> Repairs { get; set; }
|
||||
|
||||
public List<Shop> Shops { get; set; }
|
||||
|
||||
private DataListSingleton()
|
||||
{
|
||||
Components = new List<Component>();
|
||||
Orders = new List<Order>();
|
||||
Repairs = new List<Repair>();
|
||||
Shops = new List<Shop>();
|
||||
}
|
||||
|
||||
public static DataListSingleton GetInstance()
|
||||
|
112
AutoWorkshopImplement/Implements/ShopStorage.cs
Normal file
112
AutoWorkshopImplement/Implements/ShopStorage.cs
Normal file
@ -0,0 +1,112 @@
|
||||
using AutoWorkshopContracts.BindingModels;
|
||||
using AutoWorkshopContracts.SearchModels;
|
||||
using AutoWorkshopContracts.StoragesContracts;
|
||||
using AutoWorkshopContracts.ViewModels;
|
||||
using AutoWorkshopListImplement.Models;
|
||||
|
||||
namespace AutoWorkshopListImplement.Implements
|
||||
{
|
||||
public class ShopStorage : IShopStorage
|
||||
{
|
||||
private readonly DataListSingleton _source;
|
||||
|
||||
public ShopStorage()
|
||||
{
|
||||
_source = DataListSingleton.GetInstance();
|
||||
}
|
||||
|
||||
public List<ShopViewModel> GetFullList()
|
||||
{
|
||||
var Result = new List<ShopViewModel>();
|
||||
|
||||
foreach (var Shop in _source.Shops)
|
||||
{
|
||||
Result.Add(Shop.GetViewModel);
|
||||
}
|
||||
|
||||
return Result;
|
||||
}
|
||||
|
||||
public List<ShopViewModel> GetFilteredList(ShopSearchModel Model)
|
||||
{
|
||||
var Result = new List<ShopViewModel>();
|
||||
|
||||
if (string.IsNullOrEmpty(Model.ShopName))
|
||||
return Result;
|
||||
|
||||
foreach (var Shop in _source.Shops)
|
||||
{
|
||||
if (Shop.ShopName.Contains(Model.ShopName))
|
||||
Result.Add(Shop.GetViewModel);
|
||||
}
|
||||
|
||||
return Result;
|
||||
}
|
||||
|
||||
public ShopViewModel? GetElement(ShopSearchModel Model)
|
||||
{
|
||||
if (string.IsNullOrEmpty(Model.ShopName) && !Model.Id.HasValue)
|
||||
return null;
|
||||
|
||||
foreach (var Shop in _source.Shops)
|
||||
{
|
||||
if ((!string.IsNullOrEmpty(Model.ShopName) && Shop.ShopName == Model.ShopName) ||
|
||||
(Model.Id.HasValue && Shop.Id == Model.Id))
|
||||
{
|
||||
return Shop.GetViewModel;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public ShopViewModel? Insert(ShopBindingModel Model)
|
||||
{
|
||||
Model.Id = 1;
|
||||
|
||||
foreach (var Shop in _source.Shops)
|
||||
{
|
||||
if (Model.Id <= Shop.Id)
|
||||
Model.Id = Shop.Id + 1;
|
||||
}
|
||||
|
||||
var NewShop = Shop.Create(Model);
|
||||
|
||||
if (NewShop is null)
|
||||
return null;
|
||||
|
||||
_source.Shops.Add(NewShop);
|
||||
return NewShop.GetViewModel;
|
||||
}
|
||||
|
||||
public ShopViewModel? Update(ShopBindingModel Model)
|
||||
{
|
||||
foreach (var Shop in _source.Shops)
|
||||
{
|
||||
if (Shop.Id == Model.Id)
|
||||
{
|
||||
Shop.Update(Model);
|
||||
return Shop.GetViewModel;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public ShopViewModel? Delete(ShopBindingModel Model)
|
||||
{
|
||||
for (int i = 0; i < _source.Shops.Count; ++i)
|
||||
{
|
||||
if (_source.Shops[i].Id == Model.Id)
|
||||
{
|
||||
var Shop = _source.Shops[i];
|
||||
_source.Shops.RemoveAt(i);
|
||||
|
||||
return Shop.GetViewModel;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
52
AutoWorkshopImplement/Models/Shop.cs
Normal file
52
AutoWorkshopImplement/Models/Shop.cs
Normal file
@ -0,0 +1,52 @@
|
||||
using AutoWorkshopContracts.BindingModels;
|
||||
using AutoWorkshopContracts.ViewModels;
|
||||
using AutoWorkshopDataModels.Models;
|
||||
|
||||
namespace AutoWorkshopListImplement.Models
|
||||
{
|
||||
public class Shop : IShopModel
|
||||
{
|
||||
public int Id { get; private set; }
|
||||
|
||||
public string ShopName { get; private set; } = string.Empty;
|
||||
|
||||
public string Address { get; private set; } = string.Empty;
|
||||
|
||||
public DateTime OpeningDate { get; private set; }
|
||||
|
||||
public Dictionary<int, (IRepairModel, int)> ShopRepairs { get; private set; } = new();
|
||||
|
||||
public static Shop? Create(ShopBindingModel? Model)
|
||||
{
|
||||
if (Model is null)
|
||||
return null;
|
||||
|
||||
return new Shop()
|
||||
{
|
||||
Id = Model.Id,
|
||||
ShopName = Model.ShopName,
|
||||
Address = Model.Address,
|
||||
OpeningDate = Model.OpeningDate
|
||||
};
|
||||
}
|
||||
|
||||
public void Update(ShopBindingModel? Model)
|
||||
{
|
||||
if (Model is null)
|
||||
return;
|
||||
|
||||
ShopName = Model.ShopName;
|
||||
Address = Model.Address;
|
||||
OpeningDate = Model.OpeningDate;
|
||||
}
|
||||
|
||||
public ShopViewModel GetViewModel => new()
|
||||
{
|
||||
Id = Id,
|
||||
ShopName = ShopName,
|
||||
Address = Address,
|
||||
OpeningDate = OpeningDate,
|
||||
ShopRepairs = ShopRepairs
|
||||
};
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user