прикрутил хранилище в списке
This commit is contained in:
parent
9e0d4625b9
commit
61a621a3e7
@ -4,17 +4,19 @@ namespace SushiBarListImplement
|
||||
{
|
||||
public class DataListSingleton
|
||||
{
|
||||
private static DataListSingleton _instance;
|
||||
private static DataListSingleton? _instance;
|
||||
public List<Component> Components { get; set; }
|
||||
public List<Order> Orders { get; set; }
|
||||
public List<Sushi> Sushis { get; set; }
|
||||
public List<Client> Clients { get; set; }
|
||||
public List<Implementer> Implementers { get; set; }
|
||||
private DataListSingleton()
|
||||
{
|
||||
Components = new List<Component>();
|
||||
Orders = new List<Order>();
|
||||
Sushis = new List<Sushi>();
|
||||
Clients = new List<Client>();
|
||||
Implementers = new List<Implementer>();
|
||||
}
|
||||
|
||||
public static DataListSingleton GetInstance()
|
||||
|
@ -0,0 +1,97 @@
|
||||
using IceCreamShopContracts.StoragesContracts;
|
||||
using SushiBarContracts.BindingModels;
|
||||
using SushiBarContracts.SearchModels;
|
||||
using SushiBarContracts.ViewModels;
|
||||
using SushiBarListImplement.Models;
|
||||
|
||||
namespace SushiBarListImplement.Implements
|
||||
{
|
||||
public class ImplementerStorage : IImplementerStorage
|
||||
{
|
||||
private readonly DataListSingleton _source;
|
||||
public ImplementerStorage()
|
||||
{
|
||||
_source = DataListSingleton.GetInstance();
|
||||
}
|
||||
public List<ImplementerViewModel> GetFullList()
|
||||
{
|
||||
var result = new List<ImplementerViewModel>();
|
||||
foreach (var implementer in _source.Implementers)
|
||||
{
|
||||
result.Add(implementer.GetViewModel);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
public List<ImplementerViewModel> GetFilteredList(ImplementerSearchModel model)
|
||||
{
|
||||
var result = new List<ImplementerViewModel>();
|
||||
if (string.IsNullOrEmpty(model.ImplementerFIO) && string.IsNullOrEmpty(model.Password))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
foreach (var implementer in _source.Implementers)
|
||||
{
|
||||
if (implementer.ImplementerFIO.Contains(model.ImplementerFIO))
|
||||
{
|
||||
result.Add(implementer.GetViewModel);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
public ImplementerViewModel? GetElement(ImplementerSearchModel model)
|
||||
{
|
||||
foreach (var implementer in _source.Implementers)
|
||||
{
|
||||
if ((string.IsNullOrEmpty(model.ImplementerFIO) || implementer.ImplementerFIO == model.ImplementerFIO) &&
|
||||
(!model.Id.HasValue || implementer.Id == model.Id) && (string.IsNullOrEmpty(model.Password) || implementer.Password == model.Password))
|
||||
{
|
||||
return implementer.GetViewModel;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
public ImplementerViewModel? Insert(ImplementerBindingModel model)
|
||||
{
|
||||
model.Id = 1;
|
||||
foreach (var implementer in _source.Implementers)
|
||||
{
|
||||
if (model.Id <= implementer.Id)
|
||||
{
|
||||
model.Id = implementer.Id + 1;
|
||||
}
|
||||
}
|
||||
var newImplementer = Implementer.Create(model);
|
||||
if (newImplementer == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
_source.Implementers.Add(newImplementer);
|
||||
return newImplementer.GetViewModel;
|
||||
}
|
||||
public ImplementerViewModel? Update(ImplementerBindingModel model)
|
||||
{
|
||||
foreach (var implementer in _source.Implementers)
|
||||
{
|
||||
if (model.Id == implementer.Id)
|
||||
{
|
||||
implementer.Update(model);
|
||||
return implementer.GetViewModel;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
public ImplementerViewModel? Delete(ImplementerBindingModel model)
|
||||
{
|
||||
for (int i = 0; i < _source.Implementers.Count; ++i)
|
||||
{
|
||||
if (_source.Implementers[i].Id == model.Id)
|
||||
{
|
||||
var element = _source.Implementers[i];
|
||||
_source.Implementers.RemoveAt(i);
|
||||
return element.GetViewModel;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
49
SushiBar/SushiBarListImplement/Models/Implementer.cs
Normal file
49
SushiBar/SushiBarListImplement/Models/Implementer.cs
Normal file
@ -0,0 +1,49 @@
|
||||
using SushiBarContracts.BindingModels;
|
||||
using SushiBarContracts.ViewModels;
|
||||
using SushiBarDataModels.Models;
|
||||
|
||||
namespace SushiBarListImplement.Models
|
||||
{
|
||||
public class Implementer : IImplementerModel
|
||||
{
|
||||
public int Id { get; private set; }
|
||||
public string ImplementerFIO { get; private set; } = string.Empty;
|
||||
public string Password { get; set; } = string.Empty;
|
||||
public int WorkExperience { get; set; } = 0;
|
||||
public int Qualification { get; set; } = 0;
|
||||
public static Implementer? Create(ImplementerBindingModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return new Implementer()
|
||||
{
|
||||
Id = model.Id,
|
||||
ImplementerFIO = model.ImplementerFIO,
|
||||
Password = model.Password,
|
||||
WorkExperience = model.WorkExperience,
|
||||
Qualification = model.Qualification
|
||||
};
|
||||
}
|
||||
public void Update(ImplementerBindingModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
ImplementerFIO = model.ImplementerFIO;
|
||||
Password = model.Password;
|
||||
WorkExperience = model.WorkExperience;
|
||||
Qualification = model.Qualification;
|
||||
}
|
||||
public ImplementerViewModel GetViewModel => new()
|
||||
{
|
||||
Id = Id,
|
||||
ImplementerFIO = ImplementerFIO,
|
||||
Password = Password,
|
||||
WorkExperience = WorkExperience,
|
||||
Qualification = Qualification
|
||||
};
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user