FileImplement

This commit is contained in:
ShabOl 2024-04-16 00:32:20 +04:00
parent 75911262ea
commit 1e49ce1e21
5 changed files with 184 additions and 10 deletions

View File

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

View File

@ -0,0 +1,104 @@
using AutoWorkshopContracts.BindingModels;
using AutoWorkshopContracts.SearchModels;
using AutoWorkshopContracts.StoragesContracts;
using AutoWorkshopContracts.ViewModels;
using AutoWorkshopListImplement.Models;
namespace AutoWorkshopListImplement.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)
{
if (string.IsNullOrEmpty(Model.ImplementerFIO))
return new();
return _source.Implementers
.Where(x => (!string.IsNullOrEmpty(Model.ImplementerFIO) && x.ImplementerFIO.Contains(Model.ImplementerFIO)))
.Select(x => x.GetViewModel)
.ToList();
}
public ImplementerViewModel? GetElement(ImplementerSearchModel Model)
{
foreach (var Implementer in _source.Implementers)
{
if ((Model.Id.HasValue && Implementer.Id == Model.Id) ||
(!string.IsNullOrEmpty(Model.ImplementerFIO) && Implementer.ImplementerFIO == Model.ImplementerFIO))
{
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 (Implementer.Id == Model.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 Implementer = _source.Implementers[i];
_source.Implementers.RemoveAt(i);
return Implementer.GetViewModel;
}
}
return null;
}
}
}

View File

@ -32,14 +32,16 @@ namespace AutoWorkshopListImplement.Implements
if (Model.DateFrom.HasValue)
{
return _source.Orders
.Where(x => (x.DateCreate >= Model.DateFrom && x.DateCreate <= Model.DateTo) && (!Model.ClientId.HasValue || x.ClientId == Model.ClientId))
.Select(x => JoinClientFIO(JoinRepairName(x.GetViewModel)))
.Where(x => (x.DateCreate >= Model.DateFrom && x.DateCreate <= Model.DateTo) && (!Model.ClientId.HasValue || x.ClientId == Model.ClientId)
&& (!Model.ImplementerId.HasValue || x.ImplementerId == Model.ImplementerId))
.Select(x => JoinImplementerFIO(JoinClientFIO(JoinRepairName(x.GetViewModel))))
.ToList();
}
return _source.Orders
.Where(x => (Model.Id.HasValue && x.Id == Model.Id) || (Model.ClientId.HasValue && x.ClientId == Model.ClientId))
.Select(x => JoinClientFIO(JoinRepairName(x.GetViewModel)))
.Where(x => (Model.Id.HasValue && x.Id == Model.Id) || (Model.ClientId.HasValue && x.ClientId == Model.ClientId)
|| (Model.ImplementerId.HasValue && x.ImplementerId == Model.ImplementerId))
.Select(x => JoinImplementerFIO(JoinClientFIO(JoinRepairName(x.GetViewModel))))
.ToList();
}
@ -50,9 +52,9 @@ namespace AutoWorkshopListImplement.Implements
foreach (var Order in _source.Orders)
{
if (Order.Id == Model.Id)
if ((Model.Id.HasValue && Order.Id == Model.Id) || (Model.ImplementerId.HasValue && Order.ImplementerId == Model.ImplementerId))
{
return JoinRepairName(Order.GetViewModel);
return JoinImplementerFIO(JoinClientFIO(JoinRepairName(Order.GetViewModel)));
}
}
@ -130,5 +132,16 @@ namespace AutoWorkshopListImplement.Implements
}
return Model;
}
public OrderViewModel JoinImplementerFIO(OrderViewModel Model)
{
var SelectedImplementer = _source.Implementers.FirstOrDefault(x => x.Id == Model.ImplementerId);
if (SelectedImplementer != null)
{
Model.ImplementerFIO = SelectedImplementer.ImplementerFIO;
}
return Model;
}
}
}

View File

@ -0,0 +1,54 @@
using AutoWorkshopContracts.BindingModels;
using AutoWorkshopContracts.ViewModels;
using AutoWorkshopDataModels.Models;
namespace AutoWorkshopListImplement.Models
{
public class Implementer : IImplementerModel
{
public int Id { get; private set; }
public string ImplementerFIO { get; private set; } = string.Empty;
public string Password { get; private set; } = string.Empty;
public int WorkExperience { get; private set; }
public int Qualification { get; private set; }
public static Implementer? Create(ImplementerBindingModel Model)
{
if (Model == null)
{
return null;
}
return new()
{
Id = Model.Id,
Password = Model.Password,
Qualification = Model.Qualification,
ImplementerFIO = Model.ImplementerFIO,
WorkExperience = Model.WorkExperience,
};
}
public void Update(ImplementerBindingModel Model)
{
if (Model == null)
return;
Password = Model.Password;
Qualification = Model.Qualification;
ImplementerFIO = Model.ImplementerFIO;
WorkExperience = Model.WorkExperience;
}
public ImplementerViewModel GetViewModel => new()
{
Id = Id,
Password = Password,
Qualification = Qualification,
ImplementerFIO = ImplementerFIO,
};
}
}

View File

@ -13,6 +13,8 @@ namespace AutoWorkshopListImplement.Models
public int ClientId { get; private set; }
public int? ImplementerId { get; private set; }
public int Count { get; private set; }
public double Sum { get; private set; }
@ -33,6 +35,7 @@ namespace AutoWorkshopListImplement.Models
Id = Model.Id,
RepairId = Model.RepairId,
ClientId = Model.ClientId,
ImplementerId = Model.ImplementerId,
Count = Model.Count,
Sum = Model.Sum,
Status = Model.Status,
@ -46,11 +49,7 @@ namespace AutoWorkshopListImplement.Models
if (Model == null)
return;
RepairId = Model.RepairId;
Count = Model.Count;
Sum = Model.Sum;
Status = Model.Status;
DateCreate = Model.DateCreate;
DateImplement = Model.DateImplement;
}
@ -59,6 +58,7 @@ namespace AutoWorkshopListImplement.Models
Id = Id,
RepairId = RepairId,
ClientId = ClientId,
ImplementerId = ImplementerId,
Count = Count,
Sum = Sum,
Status = Status,