PIbd-22. Safiulova K.N. LabWork_05_base #9

Closed
safiulova.k wants to merge 16 commits from LabWork_05 into LabWork_04
7 changed files with 212 additions and 3 deletions
Showing only changes of commit e1bbc9ba93 - Show all commits

View File

@ -0,0 +1,52 @@
using AircraftPlantContracts.BindingModels;
using AircraftPlantContracts.ViewModels;
using AircraftPlantDataModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AircraftPlantListImplement
{
public class Client : IClientModel
{
public int Id { get; private set; }
public string ClientFIO { get; 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

@ -0,0 +1,112 @@
using AircraftPlantContracts.BindingModels;
using AircraftPlantContracts.SearchModels;
using AircraftPlantContracts.StoragesContracts;
using AircraftPlantContracts.ViewModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AircraftPlantListImplement
{
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.Email))
{
return result;
}
foreach (var client in _source.Clients)
{
if (client.Email.Contains(model.Email))
{
result.Add(client.GetViewModel);
}
}
return result;
}
public ClientViewModel? GetElement(ClientSearchModel model)
{
if (string.IsNullOrEmpty(model.ClientFIO) && string.IsNullOrEmpty(model.Email) && string.IsNullOrEmpty(model.Password) && !model.Id.HasValue)
{
return null;
}
foreach (var client in _source.Clients)
{
if (model.Id.HasValue && model.Id == client.Id)
return client.GetViewModel;
if (!string.IsNullOrEmpty(model.Email) && !string.IsNullOrEmpty(model.Password) &&
client.Email.Equals(model.Email) && client.Password.Equals(model.Password))
return client.GetViewModel;
if (!string.IsNullOrEmpty(model.Email) && client.Email.Equals(model.Email))
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

@ -32,6 +32,11 @@ namespace AircraftPlantListImplement
/// </summary>
public List<Plane> Planes { get; set; }
/// <summary>
/// Список классов-моделей клиентов
/// </summary>
public List<Client> Clients { get; set; }
/// <summary>
/// Конструктор
/// </summary>
@ -40,6 +45,7 @@ namespace AircraftPlantListImplement
Components = new List<Component>();
Orders = new List<Order>();
Planes = new List<Plane>();
Clients = new List<Client>();
}
/// <summary>
/// Получить ссылку на класс

View File

@ -5,6 +5,7 @@ using AircraftPlantDataModels.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
@ -25,6 +26,11 @@ namespace AircraftPlantListImplement.Models
/// </summary>
public int PlaneId { get; private set; }
/// <summary>
/// Идентификатор клиента
/// </summary>
public int ClientId { get; private set; }
/// <summary>
/// Количество изделий
/// </summary>
@ -66,6 +72,7 @@ namespace AircraftPlantListImplement.Models
{
Id = model.Id,
PlaneId = model.PlaneId,
ClientId = model.ClientId,
Count = model.Count,
Sum = model.Sum,
Status = model.Status,
@ -94,6 +101,7 @@ namespace AircraftPlantListImplement.Models
{
Id = Id,
PlaneId = PlaneId,
ClientId = model.ClientId,
Count = Count,
Sum = Sum,
Status = Status,

View File

@ -49,7 +49,7 @@ namespace AircraftPlantListImplement.Implements
public List<OrderViewModel> GetFilteredList(OrderSearchModel model)
{
var result = new List<OrderViewModel>();
if (!model.Id.HasValue || !model.DateFrom.HasValue || !model.DateTo.HasValue)
if (!model.Id.HasValue || !model.DateFrom.HasValue || !model.DateTo.HasValue || !model.ClientId.HasValue)
{
return result;
}
@ -66,6 +66,13 @@ namespace AircraftPlantListImplement.Implements
return result;
}
if (model.ClientId.HasValue && !model.Id.HasValue)
{
foreach (var order in _source.Orders)
{
result.Add(GetViewModel(order));
}
}
foreach (var order in _source.Orders)
{
@ -173,6 +180,16 @@ namespace AircraftPlantListImplement.Implements
break;
}
}
foreach (var client in _source.Clients)
{
if (client.Id == order.ClientId)
{
viewModel.ClientFIO = client.ClientFIO;
break;
}
}
return viewModel;
}
}

View File

@ -15,7 +15,7 @@ namespace AircraftPlantFileImplement.Models
{
public int Id { get; private set; }
public int PlaneId { get; private set; }
public int ClientId { get; private set; }
public int Count { get; private set; }
public double Sum { get; private set; }
public OrderStatus Status { get; private set; }
@ -31,6 +31,7 @@ namespace AircraftPlantFileImplement.Models
{
Id = model.Id,
PlaneId = model.PlaneId,
ClientId = model.ClientId,
Count = model.Count,
Sum = model.Sum,
Status = model.Status,
@ -48,6 +49,7 @@ namespace AircraftPlantFileImplement.Models
{
Id = Convert.ToInt32(element.Attribute("Id")!.Value),
PlaneId = Convert.ToInt32(element.Element("PlaneId")!.Value),
ClientId = Convert.ToInt32(element.Element("ClientId")!.Value),
Sum = Convert.ToDouble(element.Element("Sum")!.Value),
Count = Convert.ToInt32(element.Element("Count")!.Value),
Status = (OrderStatus)Enum.Parse(typeof(OrderStatus), element.Element("Status")!.Value),
@ -69,6 +71,7 @@ namespace AircraftPlantFileImplement.Models
{
Id = Id,
PlaneId = PlaneId,
ClientId = ClientId,
Count = Count,
Sum = Sum,
Status = Status,
@ -78,6 +81,7 @@ namespace AircraftPlantFileImplement.Models
public XElement GetXElement => new("Order",
new XAttribute("Id", Id),
new XElement("PlaneId", PlaneId),
new XElement("ClientId", ClientId),
new XElement("Count", Count.ToString()),
new XElement("Sum", Sum.ToString()),
new XElement("Status", Status.ToString()),

View File

@ -37,6 +37,14 @@ namespace AircraftPlantFileImplement.Implements
.ToList();
}
if (model.ClientId.HasValue && !model.Id.HasValue)
{
return _source.Orders
.Where(x => x.ClientId == model.ClientId)
.Select(x => x.GetViewModel)
.ToList();
}
return _source.Orders.Where(x => x.Id.Equals(model.Id)).Select(x => GetViewModel(x)).ToList();
}
public OrderViewModel? GetElement(OrderSearchModel model)
@ -86,7 +94,9 @@ namespace AircraftPlantFileImplement.Implements
{
var viewModel = order.GetViewModel;
var plane = _source.Planes.FirstOrDefault(x => x.Id == order.PlaneId);
viewModel.PlaneName = plane?.PlaneName;
viewModel.PlaneName = plane?.PlaneName ?? string.Empty;
var client = _source.Clients.FirstOrDefault(x => x.Id == order.ClientId);
viewModel.ClientFIO = client?.ClientFIO ?? string.Empty;
return viewModel;
}
}