Merge branch 'Lab6_Base' into Lab6_Hard

This commit is contained in:
Данияр Аглиуллов 2023-03-13 17:32:29 +04:00
commit 37d4acecf6
4 changed files with 130 additions and 107 deletions

View File

@ -2,11 +2,6 @@
using ConfectioneryContracts.SearchModels;
using ConfectioneryContracts.StoragesContract;
using ConfectioneryContracts.ViewModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConfectioneryListImplement
{
@ -20,25 +15,30 @@ namespace ConfectioneryListImplement
public ClientViewModel? Delete(ClientBindingModel model)
{
var res = _source.Clients.FirstOrDefault(x => x.Id == model.Id);
if (res != null)
for (int i = 0; i < _source.Clients.Count; ++i)
{
_source.Clients.Remove(res);
if (_source.Clients[i].Id == model.Id)
{
var element = _source.Clients[i];
_source.Clients.RemoveAt(i);
return element.GetViewModel;
}
return res?.GetViewModel;
}
return null;
}
public ClientViewModel? GetElement(ClientSearchModel model)
{
if (model.Id.HasValue)
return _source.Clients.FirstOrDefault(x => x.Id == model.Id)?.GetViewModel;
if (model.Email != null && model.Password != null)
return _source.Clients
.FirstOrDefault(x => x.Email.Equals(model.Email)
&& x.Password.Equals(model.Password))
?.GetViewModel;
if (model.Email != null)
return _source.Clients.FirstOrDefault(x => x.Email.Equals(model.Email))?.GetViewModel;
foreach (var client in _source.Clients)
{
if (model.Id.HasValue && model.Id == client.Id)
return client.GetViewModel;
if (model.Email != null && model.Password != null &&
client.Email.Equals(model.Email) && client.Password.Equals(model.Password))
return client.GetViewModel;
if (model.Email != null && client.Email.Equals(model.Email))
return client.GetViewModel;
}
return null;
}
@ -48,24 +48,20 @@ namespace ConfectioneryListImplement
{
return new();
}
if (model.Id.HasValue)
{
// У нас нет каких либо специфических условий для выборки списка клиентов,
// поэтому получаем лишь один элемент по модели
var res = GetElement(model);
return res != null ? new() { res } : new();
}
if (model.Email != null)
{
return _source.Clients
.Where(x => x.Email.Contains(model.Email))
.Select(x => x.GetViewModel)
.ToList();
}
return new();
}
public List<ClientViewModel> GetFullList()
{
return _source.Clients.Select(x => x.GetViewModel).ToList();
var result = new List<ClientViewModel>();
foreach (var client in _source.Clients)
{
result.Add(client.GetViewModel);
}
return result;
}
public ClientViewModel? Insert(ClientBindingModel model)
@ -81,9 +77,15 @@ namespace ConfectioneryListImplement
public ClientViewModel? Update(ClientBindingModel model)
{
var res = _source.Clients.FirstOrDefault(x => x.Id == model.Id);
res?.Update(model);
return res?.GetViewModel;
foreach (var client in _source.Clients)
{
if (client.Id == model.Id)
{
client.Update(model);
return client.GetViewModel;
}
}
return null;
}
}
}

View File

@ -2,6 +2,7 @@
using ConfectioneryContracts.SearchModels;
using ConfectioneryContracts.StoragesContract;
using ConfectioneryContracts.ViewModels;
using System.Collections.Generic;
namespace ConfectioneryListImplement
{
@ -15,25 +16,30 @@ namespace ConfectioneryListImplement
public ImplementerViewModel? Delete(ImplementerBindingModel model)
{
var res = _source.Implementers.FirstOrDefault(x => x.Id == model.Id);
if (res != null)
for (int i = 0; i < _source.Implementers.Count; ++i)
{
_source.Implementers.Remove(res);
if (_source.Implementers[i].Id == model.Id)
{
var element = _source.Implementers[i];
_source.Implementers.RemoveAt(i);
return element.GetViewModel;
}
return res?.GetViewModel;
}
return null;
}
public ImplementerViewModel? GetElement(ImplementerSearchModel model)
{
if (model.Id.HasValue)
return _source.Implementers.FirstOrDefault(x => x.Id == model.Id)?.GetViewModel;
if (model.ImplementerFIO != null && model.Password != null)
return _source.Implementers
.FirstOrDefault(x => x.ImplementerFIO.Equals(model.ImplementerFIO)
&& x.Password.Equals(model.Password))
?.GetViewModel;
if (model.ImplementerFIO != null)
return _source.Implementers.FirstOrDefault(x => x.ImplementerFIO.Equals(model.ImplementerFIO))?.GetViewModel;
foreach (var x in _source.Implementers)
{
if (model.Id.HasValue && x.Id == model.Id)
return x.GetViewModel;
if (model.ImplementerFIO != null && model.Password != null &&
x.ImplementerFIO.Equals(model.ImplementerFIO) && x.Password.Equals(model.Password))
return x.GetViewModel;
if (model.ImplementerFIO != null && x.ImplementerFIO.Equals(model.ImplementerFIO))
return x.GetViewModel;
}
return null;
}
@ -48,19 +54,30 @@ namespace ConfectioneryListImplement
var res = GetElement(model);
return res != null ? new() { res } : new();
}
if (model.ImplementerFIO != null) // На случай если фио не будет уникальным (по заданию оно уникально)
// На случай если при расширении проекта фио не будет уникальным
// (по заданию оно уникально)
List<ImplementerViewModel> result = new();
if (model.ImplementerFIO != null)
{
return _source.Implementers
.Where(x => x.ImplementerFIO.Equals(model.ImplementerFIO))
.Select(x => x.GetViewModel)
.ToList();
foreach (var implementer in _source.Implementers)
{
if (implementer.ImplementerFIO.Equals(model.ImplementerFIO))
{
result.Add(implementer.GetViewModel);
}
return new();
}
}
return result;
}
public List<ImplementerViewModel> GetFullList()
{
return _source.Implementers.Select(x => x.GetViewModel).ToList();
var result = new List<ImplementerViewModel>();
foreach (var implementer in _source.Implementers)
{
result.Add(implementer.GetViewModel);
}
return result;
}
public ImplementerViewModel? Insert(ImplementerBindingModel model)
@ -76,9 +93,15 @@ namespace ConfectioneryListImplement
public ImplementerViewModel? Update(ImplementerBindingModel model)
{
var res = _source.Implementers.FirstOrDefault(x => x.Id == model.Id);
res?.Update(model);
return res?.GetViewModel;
foreach (var implementer in _source.Implementers)
{
if (implementer.Id == model.Id)
{
implementer.Update(model);
return implementer.GetViewModel;
}
}
return null;
}
}
}

View File

@ -62,7 +62,6 @@ namespace ConfectioneryListImplement.Models
public OrderViewModel GetViewModel => new()
{
PastryId = PastryId,
ClientFIO = DataListSingleton.GetInstance().Clients.FirstOrDefault(x => x.Id == ClientId)?.ClientFIO ?? string.Empty,
ClientId = ClientId,
ImplementerId = ImplementerId,
ImplementerFIO = DataListSingleton.GetInstance().Implementers.FirstOrDefault(x => x.Id == ImplementerId)?.ImplementerFIO ?? string.Empty,

View File

@ -3,6 +3,7 @@ using ConfectioneryContracts.SearchModels;
using ConfectioneryContracts.StoragesContract;
using ConfectioneryContracts.ViewModels;
using ConfectioneryListImplement.Models;
using System.Security.Cryptography.X509Certificates;
namespace ConfectioneryListImplement
{
@ -30,17 +31,6 @@ namespace ConfectioneryListImplement
public OrderViewModel? GetElement(OrderSearchModel model)
{
if (model.ImplementerId.HasValue && model.Statusses != null)
{
return _source.Orders
.FirstOrDefault(x => x.ImplementerId == model.ImplementerId &&
model.Statusses.Contains(x.Status))
?.GetViewModel;
}
if (model.ImplementerId.HasValue)
{
return _source.Orders.FirstOrDefault(x => x.ImplementerId == model.ImplementerId)?.GetViewModel;
}
if (!model.Id.HasValue)
{
return null;
@ -51,6 +41,15 @@ namespace ConfectioneryListImplement
{
return GetViewModel(order);
}
else if (model.ImplementerId.HasValue && model.Statusses != null &&
order.ImplementerId == model.ImplementerId && model.Statusses.Contains(order.Status))
{
return GetViewModel(order);
}
else if (model.ImplementerId.HasValue && model.ImplementerId == order.ImplementerId)
{
return GetViewModel(order);
}
}
return null;
}
@ -58,40 +57,32 @@ namespace ConfectioneryListImplement
public List<OrderViewModel> GetFilteredList(OrderSearchModel model)
{
var result = new List<OrderViewModel>();
if (!model.Id.HasValue && model.DateFrom.HasValue && model.DateTo.HasValue) // если не ищем по айдишнику, значит ищем по диапазону дат
{
return _source.Orders
.Where(x => model.DateFrom <= x.DateCreate.Date && x.DateCreate <= model.DateTo)
.Select(x => x.GetViewModel)
.ToList();
}
if (!model.Id.HasValue && model.ClientId.HasValue)
{
return _source.Orders
.Where(x => x.ClientId == model.ClientId)
.Select(x => x.GetViewModel)
.ToList();
}
if (!model.Id.HasValue && model.Statusses != null)
{
return _source.Orders
.Where(x => model.Statusses.Contains(x.Status))
.Select(x => x.GetViewModel)
.ToList();
}
if (model.ImplementerId.HasValue)
{
var res = _source.Orders.FirstOrDefault(x => x.ImplementerId == model.ImplementerId);
return res != null ? new() { res.GetViewModel } : new();
}
foreach (var order in _source.Orders)
{
if (order.Id == model.Id)
{
return new() { GetViewModel(order) };
}
// если не ищем по айдишнику, значит ищем по диапазону дат
else if (model.DateFrom.HasValue && model.DateTo.HasValue &&
model.DateFrom <= order.DateCreate.Date && order.DateCreate.Date <= model.DateTo)
{
result.Add(GetViewModel(order));
}
return new();
else if (model.ClientId.HasValue && order.ClientId == model.ClientId)
{
result.Add(GetViewModel(order));
}
else if (model.ImplementerId.HasValue && order.ImplementerId == model.ImplementerId)
{
result.Add(GetViewModel(order));
}
else if (model.Statusses != null && model.Statusses.Contains(order.Status))
{
result.Add(GetViewModel(order));
}
}
return result;
}
public List<OrderViewModel> GetFullList()
@ -147,6 +138,14 @@ namespace ConfectioneryListImplement
break;
}
}
foreach (var client in _source.Clients)
{
if (client.Id == res.ClientId)
{
res.ClientFIO = client.ClientFIO;
break;
}
}
return res;
}
}