Merge branch 'Lab5_Base' into Lab5_Hard
This commit is contained in:
commit
f7b889276c
@ -5,6 +5,7 @@ using ConfectioneryContracts.ViewModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Security.Cryptography.X509Certificates;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
@ -19,26 +20,31 @@ namespace ConfectioneryListImplement
|
||||
}
|
||||
|
||||
public ClientViewModel? Delete(ClientBindingModel model)
|
||||
{
|
||||
var res = _source.Clients.FirstOrDefault(x => x.Id == model.Id);
|
||||
if (res != null)
|
||||
{
|
||||
_source.Clients.Remove(res);
|
||||
}
|
||||
return res?.GetViewModel;
|
||||
}
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
public ClientViewModel? GetElement(ClientSearchModel model)
|
||||
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,25 +54,21 @@ 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();
|
||||
// У нас нет каких либо специфических условий для выборки списка клиентов,
|
||||
// поэтому получаем лишь один элемент по модели
|
||||
var res = GetElement(model);
|
||||
return res != null ? new() { res } : 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)
|
||||
{
|
||||
@ -80,10 +82,16 @@ 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -3,6 +3,7 @@ using ConfectioneryContracts.SearchModels;
|
||||
using ConfectioneryContracts.StoragesContract;
|
||||
using ConfectioneryContracts.ViewModels;
|
||||
using ConfectioneryListImplement.Models;
|
||||
using System.Security.Cryptography.X509Certificates;
|
||||
|
||||
namespace ConfectioneryListImplement
|
||||
{
|
||||
@ -47,28 +48,24 @@ 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();
|
||||
}
|
||||
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));
|
||||
}
|
||||
else if (model.ClientId.HasValue && order.ClientId == model.ClientId)
|
||||
{
|
||||
result.Add(GetViewModel(order));
|
||||
}
|
||||
}
|
||||
return new();
|
||||
return result;
|
||||
}
|
||||
|
||||
public List<OrderViewModel> GetFullList()
|
||||
|
Loading…
Reference in New Issue
Block a user