list
This commit is contained in:
parent
1486672e6f
commit
d2d638fb69
@ -0,0 +1,27 @@
|
|||||||
|
using JewelryStoreContracts.DI;
|
||||||
|
using JewelryStoreContracts.StoragesContracts;
|
||||||
|
using JewelryStoreListImplement.Implements;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace JewelryStoreListImplement
|
||||||
|
{
|
||||||
|
public class ImplementationExtension : IImplementationExtension
|
||||||
|
{
|
||||||
|
public int Priority => 0;
|
||||||
|
|
||||||
|
public void RegisterServices()
|
||||||
|
{
|
||||||
|
DependencyManager.Instance.RegisterType<IClientStorage, ClientStorage>();
|
||||||
|
DependencyManager.Instance.RegisterType<IComponentStorage, ComponentStorage>();
|
||||||
|
DependencyManager.Instance.RegisterType<IImplementerStorage, ImplementerStorage>();
|
||||||
|
DependencyManager.Instance.RegisterType<IMessageInfoStorage, MessageInfoStorage>();
|
||||||
|
DependencyManager.Instance.RegisterType<IOrderStorage, OrderStorage>();
|
||||||
|
DependencyManager.Instance.RegisterType<IJewelStorage, JewelStorage>();
|
||||||
|
DependencyManager.Instance.RegisterType<IBackUpInfo, BackUpInfo>();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,22 @@
|
|||||||
|
using JewelryStoreContracts.StoragesContracts;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace JewelryStoreListImplement.Implements
|
||||||
|
{
|
||||||
|
public class BackUpInfo : IBackUpInfo
|
||||||
|
{
|
||||||
|
public List<T>? GetList<T>() where T : class, new()
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Type? GetTypeByModelInterface(string modelInterfaceName)
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,5 +1,8 @@
|
|||||||
using JewelryStoreContracts.BindingModels;
|
using JewelryStoreContracts.BindingModels;
|
||||||
|
using JewelryStoreContracts.SearchModels;
|
||||||
|
using JewelryStoreContracts.StoragesContracts;
|
||||||
using JewelryStoreContracts.ViewModels;
|
using JewelryStoreContracts.ViewModels;
|
||||||
|
using JewelryStoreListImplement.Models;
|
||||||
using JewerlyStoreDataModels.Models;
|
using JewerlyStoreDataModels.Models;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
@ -9,42 +12,94 @@ using System.Threading.Tasks;
|
|||||||
|
|
||||||
namespace JewelryStoreListImplement.Implements
|
namespace JewelryStoreListImplement.Implements
|
||||||
{
|
{
|
||||||
public class Client : IClientModel
|
public class ClientStorage : IClientStorage //ватафак тут было
|
||||||
{
|
{
|
||||||
public int Id { get; set; }
|
private readonly DataListSingleton _source;
|
||||||
public string ClientFIO { get; set; } = string.Empty;
|
public ClientStorage()
|
||||||
public string Email { get; set; } = string.Empty;
|
|
||||||
public string Password { get; set; } = string.Empty;
|
|
||||||
|
|
||||||
public static Client? Create(ClientBindingModel? model)
|
|
||||||
{
|
{
|
||||||
if (model == null)
|
_source = DataListSingleton.GetInstance();
|
||||||
|
}
|
||||||
|
public List<ClientViewModel> GetFullList()
|
||||||
|
{
|
||||||
|
var result = new List<ClientViewModel>();
|
||||||
|
foreach (var client in _source.Clients)
|
||||||
|
{
|
||||||
|
result.Add(client.GetViewModel);
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
public List<ClientViewModel> GetFilteredList(ClientSearchModel
|
||||||
|
model)
|
||||||
|
{
|
||||||
|
var result = new List<ClientViewModel>();
|
||||||
|
if (string.IsNullOrEmpty(model.ClientFIO) && string.IsNullOrEmpty(model.Email) && string.IsNullOrEmpty(model.Password))
|
||||||
|
{
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
foreach (var client in _source.Clients)
|
||||||
|
{
|
||||||
|
if (client.ClientFIO.Contains(model.ClientFIO))
|
||||||
|
{
|
||||||
|
result.Add(client.GetViewModel);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
public ClientViewModel? GetElement(ClientSearchModel model)
|
||||||
|
{
|
||||||
|
foreach (var client in _source.Clients)
|
||||||
|
{
|
||||||
|
if ((string.IsNullOrEmpty(model.ClientFIO) || client.ClientFIO == model.ClientFIO) &&
|
||||||
|
(!model.Id.HasValue || client.Id == model.Id) && (string.IsNullOrEmpty(model.Email) || client.Email == model.Email) &&
|
||||||
|
(string.IsNullOrEmpty(model.Password) || client.Password == model.Password))
|
||||||
|
{
|
||||||
|
return client.GetViewModel;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
public ClientViewModel? Insert(ClientBindingModel model)
|
||||||
|
{
|
||||||
|
model.Id = 1;
|
||||||
|
foreach (var client in _source.Clients)
|
||||||
|
{
|
||||||
|
if (model.Id <= client.Id)
|
||||||
|
{
|
||||||
|
model.Id = client.Id + 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
var newClient = Client.Create(model);
|
||||||
|
if (newClient == null)
|
||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return new Client()
|
_source.Clients.Add(newClient);
|
||||||
|
return newClient.GetViewModel;
|
||||||
|
}
|
||||||
|
public ClientViewModel? Update(ClientBindingModel model)
|
||||||
|
{
|
||||||
|
foreach (var client in _source.Clients)
|
||||||
{
|
{
|
||||||
Id = model.Id,
|
if (client.Id == model.Id)
|
||||||
ClientFIO = model.ClientFIO,
|
{
|
||||||
Email = model.Email,
|
client.Update(model);
|
||||||
Password = model.Password
|
return client.GetViewModel;
|
||||||
};
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
public ClientViewModel? Delete(ClientBindingModel model)
|
||||||
public void Update(ClientBindingModel? model)
|
|
||||||
{
|
{
|
||||||
if (model == null) { return; }
|
for (int i = 0; i < _source.Clients.Count; ++i)
|
||||||
ClientFIO = model.ClientFIO;
|
{
|
||||||
Email = model.Email;
|
if (_source.Clients[i].Id == model.Id)
|
||||||
Password = model.Password;
|
{
|
||||||
|
var element = _source.Clients[i];
|
||||||
|
_source.Clients.RemoveAt(i);
|
||||||
|
return element.GetViewModel;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ClientViewModel GetViewModel => new()
|
|
||||||
{
|
|
||||||
Id = Id,
|
|
||||||
ClientFIO = ClientFIO,
|
|
||||||
Email = Email,
|
|
||||||
Password = Password
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
using JewelryStoreContracts.BindingModels;
|
using JewelryStoreContracts.BindingModels;
|
||||||
using JewelryStoreContracts.SearchModels;
|
using JewelryStoreContracts.SearchModels;
|
||||||
|
using JewelryStoreContracts.StoragesContracts;
|
||||||
using JewelryStoreContracts.ViewModels;
|
using JewelryStoreContracts.ViewModels;
|
||||||
using JewelryStoreListImplement.Models;
|
using JewelryStoreListImplement.Models;
|
||||||
using System;
|
using System;
|
||||||
@ -10,7 +11,7 @@ using System.Threading.Tasks;
|
|||||||
|
|
||||||
namespace JewelryStoreListImplement.Implements
|
namespace JewelryStoreListImplement.Implements
|
||||||
{
|
{
|
||||||
public class ImplementerStorage
|
public class ImplementerStorage : IImplementerStorage // и тут потеря потерь
|
||||||
{
|
{
|
||||||
private readonly DataListSingleton _source;
|
private readonly DataListSingleton _source;
|
||||||
public ImplementerStorage()
|
public ImplementerStorage()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user