ПИбд-23 Старостин Иван Лабораторная работа №5 #7
50
ShipyardListImplement/Client.cs
Normal file
50
ShipyardListImplement/Client.cs
Normal file
@ -0,0 +1,50 @@
|
||||
using ShipyardContracts.BindingModels;
|
||||
using ShipyardContracts.ViewModels;
|
||||
using ShipyardDataModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ShipyardListImplement.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
|
||||
};
|
||||
}
|
||||
}
|
100
ShipyardListImplement/ClientStorage.cs
Normal file
100
ShipyardListImplement/ClientStorage.cs
Normal file
@ -0,0 +1,100 @@
|
||||
using ShipyardContracts.BindingModels;
|
||||
using ShipyardContracts.SearchModels;
|
||||
using ShipyardContracts.StorageContracts;
|
||||
using ShipyardContracts.ViewModels;
|
||||
using ShipyardListImplement.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ShipyardListImplement
|
||||
{
|
||||
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)
|
||||
{
|
||||
if (string.IsNullOrEmpty(model.ClientFIO) &&
|
||||
string.IsNullOrEmpty(model.Email) &&
|
||||
string.IsNullOrEmpty(model.Password))
|
||||
{
|
||||
return new();
|
||||
}
|
||||
return _source.Clients
|
||||
.Where(x =>
|
||||
(string.IsNullOrEmpty(model.ClientFIO) || x.ClientFIO.Contains(model.ClientFIO)) &&
|
||||
(string.IsNullOrEmpty(model.Email) || x.Email.Contains(model.Email)) &&
|
||||
(string.IsNullOrEmpty(model.Password) || x.Password.Contains(model.Password)))
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
public ClientViewModel? GetElement(ClientSearchModel model)
|
||||
{
|
||||
return _source.Clients
|
||||
.FirstOrDefault(x =>
|
||||
(string.IsNullOrEmpty(model.ClientFIO) || x.ClientFIO == model.ClientFIO) &&
|
||||
(string.IsNullOrEmpty(model.Email) || x.Email == model.Email) &&
|
||||
(string.IsNullOrEmpty(model.Password) || x.Password == model.Password) &&
|
||||
(!model.Id.HasValue || x.Id == model.Id))
|
||||
?.GetViewModel;
|
||||
}
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
@ -8,12 +8,14 @@ namespace ShipyardListImplement
|
||||
public List<Component> Components { get; set; }
|
||||
public List<Order> Orders { get; set; }
|
||||
public List<Ship> Ships { get; set; }
|
||||
private DataListSingleton()
|
||||
public List<Client> Clients { get; set; }
|
||||
private DataListSingleton()
|
||||
{
|
||||
Components = new List<Component>();
|
||||
Orders = new List<Order>();
|
||||
Ships = new List<Ship>();
|
||||
}
|
||||
Clients = new List<Client>();
|
||||
}
|
||||
public static DataListSingleton GetInstance()
|
||||
{
|
||||
if (_instance == null)
|
||||
|
@ -14,8 +14,9 @@ namespace ShipyardListImplement
|
||||
public OrderStatus Status { get; private set; }
|
||||
public DateTime DateCreate { get; private set; }
|
||||
public DateTime? DateImplement { get; private set; }
|
||||
public int ClientId { get; private set; }
|
||||
|
||||
public static Order? Create(OrderBindingModel? model)
|
||||
public static Order? Create(OrderBindingModel? model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
@ -30,7 +31,8 @@ namespace ShipyardListImplement
|
||||
Status = model.Status,
|
||||
DateCreate = model.DateCreate,
|
||||
DateImplement = model.DateImplement,
|
||||
};
|
||||
ClientId = model.ClientId,
|
||||
};
|
||||
}
|
||||
public void Update(OrderBindingModel? model)
|
||||
{
|
||||
@ -50,6 +52,7 @@ namespace ShipyardListImplement
|
||||
Status = Status,
|
||||
DateCreate = DateCreate,
|
||||
DateImplement = DateImplement,
|
||||
};
|
||||
ClientId = ClientId,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@ -29,7 +29,8 @@ namespace ShipyardListImplement
|
||||
{
|
||||
if ((!model.Id.HasValue || order.Id == model.Id) &&
|
||||
(!model.DateFrom.HasValue || order.DateCreate >= model.DateFrom)
|
||||
&& (!model.DateTo.HasValue || order.DateCreate <= model.DateTo))
|
||||
&& (!model.DateTo.HasValue || order.DateCreate <= model.DateTo)
|
||||
&& (!model.ClientId.HasValue || order.ClientId == model.ClientId))
|
||||
{
|
||||
result.Add(AccessShipStorage(order.GetViewModel));
|
||||
}
|
||||
@ -96,7 +97,12 @@ namespace ShipyardListImplement
|
||||
}
|
||||
public OrderViewModel AccessShipStorage(OrderViewModel model)
|
||||
{
|
||||
foreach (var Ship in _source.Ships)
|
||||
var client = _source.Clients.FirstOrDefault(x => x.Id == model.ClientId);
|
||||
if (client != null)
|
||||
{
|
||||
model.ClientFIO = client.ClientFIO;
|
||||
}
|
||||
foreach (var Ship in _source.Ships)
|
||||
{
|
||||
if (Ship.Id == model.Id)
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user