Удалены методы LINQ в ListImplement
This commit is contained in:
parent
93d8e0596a
commit
209f1fa73b
@ -5,6 +5,7 @@ using ConfectioneryContracts.ViewModels;
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Security.Cryptography.X509Certificates;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
@ -19,26 +20,31 @@ namespace ConfectioneryListImplement
|
|||||||
}
|
}
|
||||||
|
|
||||||
public ClientViewModel? Delete(ClientBindingModel model)
|
public ClientViewModel? Delete(ClientBindingModel model)
|
||||||
{
|
{
|
||||||
var res = _source.Clients.FirstOrDefault(x => x.Id == model.Id);
|
for (int i = 0; i < _source.Clients.Count; ++i)
|
||||||
if (res != null)
|
{
|
||||||
{
|
if (_source.Clients[i].Id == model.Id)
|
||||||
_source.Clients.Remove(res);
|
{
|
||||||
}
|
var element = _source.Clients[i];
|
||||||
return res?.GetViewModel;
|
_source.Clients.RemoveAt(i);
|
||||||
}
|
return element.GetViewModel;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
public ClientViewModel? GetElement(ClientSearchModel model)
|
public ClientViewModel? GetElement(ClientSearchModel model)
|
||||||
{
|
{
|
||||||
if (model.Id.HasValue)
|
foreach (var client in _source.Clients)
|
||||||
return _source.Clients.FirstOrDefault(x => x.Id == model.Id)?.GetViewModel;
|
{
|
||||||
if (model.Email != null && model.Password != null)
|
if (model.Id.HasValue && model.Id == client.Id)
|
||||||
return _source.Clients
|
return client.GetViewModel;
|
||||||
.FirstOrDefault(x => x.Email.Equals(model.Email)
|
if (model.Email != null && model.Password != null &&
|
||||||
&& x.Password.Equals(model.Password))
|
client.Email.Equals(model.Email) && client.Password.Equals(model.Password))
|
||||||
?.GetViewModel;
|
return client.GetViewModel;
|
||||||
if (model.Email != null)
|
if (model.Email != null && client.Email.Equals(model.Email))
|
||||||
return _source.Clients.FirstOrDefault(x => x.Email.Equals(model.Email))?.GetViewModel;
|
return client.GetViewModel;
|
||||||
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -48,25 +54,21 @@ namespace ConfectioneryListImplement
|
|||||||
{
|
{
|
||||||
return new();
|
return new();
|
||||||
}
|
}
|
||||||
if (model.Id.HasValue)
|
// У нас нет каких либо специфических условий для выборки списка клиентов,
|
||||||
{
|
// поэтому получаем лишь один элемент по модели
|
||||||
var res = GetElement(model);
|
var res = GetElement(model);
|
||||||
return res != null ? new() { res } : new();
|
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()
|
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)
|
public ClientViewModel? Insert(ClientBindingModel model)
|
||||||
{
|
{
|
||||||
@ -80,10 +82,16 @@ namespace ConfectioneryListImplement
|
|||||||
}
|
}
|
||||||
|
|
||||||
public ClientViewModel? Update(ClientBindingModel model)
|
public ClientViewModel? Update(ClientBindingModel model)
|
||||||
{
|
{
|
||||||
var res = _source.Clients.FirstOrDefault(x => x.Id == model.Id);
|
foreach (var client in _source.Clients)
|
||||||
res?.Update(model);
|
{
|
||||||
return res?.GetViewModel;
|
if (client.Id == model.Id)
|
||||||
}
|
{
|
||||||
}
|
client.Update(model);
|
||||||
|
return client.GetViewModel;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,6 +3,7 @@ using ConfectioneryContracts.SearchModels;
|
|||||||
using ConfectioneryContracts.StoragesContract;
|
using ConfectioneryContracts.StoragesContract;
|
||||||
using ConfectioneryContracts.ViewModels;
|
using ConfectioneryContracts.ViewModels;
|
||||||
using ConfectioneryListImplement.Models;
|
using ConfectioneryListImplement.Models;
|
||||||
|
using System.Security.Cryptography.X509Certificates;
|
||||||
|
|
||||||
namespace ConfectioneryListImplement
|
namespace ConfectioneryListImplement
|
||||||
{
|
{
|
||||||
@ -47,28 +48,24 @@ namespace ConfectioneryListImplement
|
|||||||
public List<OrderViewModel> GetFilteredList(OrderSearchModel model)
|
public List<OrderViewModel> GetFilteredList(OrderSearchModel model)
|
||||||
{
|
{
|
||||||
var result = new List<OrderViewModel>();
|
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();
|
|
||||||
}
|
|
||||||
foreach (var order in _source.Orders)
|
foreach (var order in _source.Orders)
|
||||||
{
|
{
|
||||||
if (order.Id == model.Id)
|
if (order.Id == model.Id)
|
||||||
{
|
{
|
||||||
return new() { GetViewModel(order) };
|
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));
|
||||||
|
}
|
||||||
|
else if (model.ClientId.HasValue && order.ClientId == model.ClientId)
|
||||||
|
{
|
||||||
|
result.Add(GetViewModel(order));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return new();
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<OrderViewModel> GetFullList()
|
public List<OrderViewModel> GetFullList()
|
||||||
|
Loading…
Reference in New Issue
Block a user