List implement

This commit is contained in:
ShabOl 2024-04-11 01:07:25 +04:00
parent 3e7ccbdc62
commit 2ac06320e6
5 changed files with 182 additions and 4 deletions

View File

@ -11,12 +11,15 @@ namespace AutoWorkshopListImplement
public List<Order> Orders { get; set; }
public List<Repair> Repairs { get; set; }
public List<Client> Clients { get; set; }
private DataListSingleton()
{
Components = new List<Component>();
Orders = new List<Order>();
Repairs = new List<Repair>();
Clients = new List<Client>();
}
public static DataListSingleton GetInstance()

View File

@ -0,0 +1,111 @@
using AutoWorkshopContracts.BindingModels;
using AutoWorkshopContracts.SearchModels;
using AutoWorkshopContracts.StoragesContracts;
using AutoWorkshopContracts.ViewModels;
using AutoWorkshopListImplement.Models;
namespace AutoWorkshopListImplement.Implements
{
public class ClientStorage : IClientStorage
{
private readonly DataListSingleton _source;
public ClientStorage()
{
_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;
_source.Clients.Add(NewClient);
return NewClient.GetViewModel;
}
public ClientViewModel? Update(ClientBindingModel Model)
{
foreach (var Client in _source.Clients)
{
if (Client.Id == Model.Id)
{
Client.Update(Model);
return Client.GetViewModel;
}
}
return null;
}
public ClientViewModel? Delete(ClientBindingModel Model)
{
for (int i = 0; i < _source.Clients.Count; ++i)
{
if (_source.Clients[i].Id == Model.Id)
{
var Element = _source.Clients[i];
_source.Clients.RemoveAt(i);
return Element.GetViewModel;
}
}
return null;
}
}
}

View File

@ -3,7 +3,6 @@ using AutoWorkshopContracts.SearchModels;
using AutoWorkshopContracts.StoragesContracts;
using AutoWorkshopContracts.ViewModels;
using AutoWorkshopListImplement.Models;
using System.Reflection;
namespace AutoWorkshopListImplement.Implements
{
@ -37,7 +36,8 @@ namespace AutoWorkshopListImplement.Implements
foreach (var Order in _source.Orders)
{
if (Order.DateCreate >= Model.DateFrom && Order.DateCreate <= Model.DateTo)
if ((Order.DateCreate >= Model.DateFrom && Order.DateCreate <= Model.DateTo) &&
(!Model.ClientId.HasValue || Model.ClientId == Model.ClientId))
{
Result.Add(JoinRepairName(Order.GetViewModel));
break;
@ -123,5 +123,16 @@ namespace AutoWorkshopListImplement.Implements
}
return Model;
}
public OrderViewModel JoinClientFIO(OrderViewModel Model)
{
var SelectedClient = _source.Clients.FirstOrDefault(x => x.Id == Model.ClientId);
if (SelectedClient != null)
{
Model.ClientFIO = SelectedClient.ClientFIO;
}
return Model;
}
}
}

View File

@ -0,0 +1,49 @@
using AutoWorkshopContracts.BindingModels;
using AutoWorkshopContracts.ViewModels;
using AutoWorkshopDataModels.Models;
namespace AutoWorkshopListImplement.Models
{
public class Client : IClientModel
{
public int Id { get; private set; }
public string ClientFIO { get; private set; } = string.Empty;
public string Email { get; set; } = string.Empty;
public string Password { get; set; } = string.Empty;
public static Client? Create(ClientBindingModel Model)
{
if (Model == null)
return null;
return new Client()
{
Id = Model.Id,
ClientFIO = Model.ClientFIO,
Email = Model.Email,
Password = Model.Password
};
}
public void Update(ClientBindingModel Model)
{
if (Model == null)
return;
ClientFIO = Model.ClientFIO;
Email = Model.Email;
Password = Model.Password;
}
public ClientViewModel GetViewModel => new()
{
Id = Id,
ClientFIO = ClientFIO,
Email = Email,
Password = Password
};
}
}

View File

@ -10,7 +10,9 @@ namespace AutoWorkshopListImplement.Models
public int Id { get; private set; }
public int RepairId { get; private set; }
public int ClientId { get; private set; }
public int Count { get; private set; }
public double Sum { get; private set; }
@ -30,6 +32,7 @@ namespace AutoWorkshopListImplement.Models
{
Id = Model.Id,
RepairId = Model.RepairId,
ClientId = Model.ClientId,
Count = Model.Count,
Sum = Model.Sum,
Status = Model.Status,
@ -55,6 +58,7 @@ namespace AutoWorkshopListImplement.Models
{
Id = Id,
RepairId = RepairId,
ClientId = ClientId,
Count = Count,
Sum = Sum,
Status = Status,