Merge branch 'lab5_base' into lab5_hard

This commit is contained in:
prodigygirl 2023-04-09 10:28:12 +04:00
commit 918e60384b
3 changed files with 49 additions and 23 deletions

View File

@ -32,16 +32,25 @@ namespace FurnitureAssemFileImplement.Implements
public ClientViewModel? GetElement(ClientSearchModel model) public ClientViewModel? GetElement(ClientSearchModel model)
{ {
if (string.IsNullOrEmpty(model.Email) && !model.Id.HasValue) if (string.IsNullOrEmpty(model.Email) && !model.Id.HasValue && string.IsNullOrEmpty(model.Password))
{ {
return null; return null;
} }
return source.Clients if (model.Id.HasValue)
.FirstOrDefault(x => {
(!string.IsNullOrEmpty(model.Email) && x.Email == return source.Clients.FirstOrDefault(x => x.Id == model.Id)?.GetViewModel;
model.Email) || }
(model.Id.HasValue && x.Id == model.Id)) if (model.Email != null && model.Password != null)
?.GetViewModel; {
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;
}
return null;
} }
public List<ClientViewModel> GetFilteredList(ClientSearchModel model) public List<ClientViewModel> GetFilteredList(ClientSearchModel model)
@ -51,7 +60,7 @@ namespace FurnitureAssemFileImplement.Implements
return new(); return new();
} }
return source.Clients return source.Clients
.Where(x => x.Email.Equals(model.Email) && x.Password.Equals(model.Password)) .Where(x => x.Email.Equals(model.Email))
.Select(x => x.GetViewModel) .Select(x => x.GetViewModel)
.ToList(); .ToList();
} }

View File

@ -28,27 +28,37 @@ namespace FurnitureAssemblyDatabaseImplement.Implements
public ClientViewModel? GetElement(ClientSearchModel model) public ClientViewModel? GetElement(ClientSearchModel model)
{ {
if (string.IsNullOrEmpty(model.Email) && !model.Id.HasValue) if (string.IsNullOrEmpty(model.Email) && !model.Id.HasValue && string.IsNullOrEmpty(model.Password))
{ {
return null; return null;
} }
using var context = new FurnitureAssemblyDatabase(); using var context = new FurnitureAssemblyDatabase();
return context.Clients if (model.Id.HasValue)
.FirstOrDefault(x => {
(!string.IsNullOrEmpty(model.Email) && x.Email == model.Email) || return context.Clients.FirstOrDefault(x => x.Id == model.Id)?.GetViewModel;
(model.Id.HasValue && x.Id == model.Id)) }
?.GetViewModel; if (model.Email != null && model.Password != null)
{
return context.Clients
.FirstOrDefault(x => x.Email.Equals(model.Email) && x.Password.Equals(model.Password))
?.GetViewModel;
}
if (model.Email != null)
{
return context.Clients.FirstOrDefault(x => x.Email.Equals(model.Email))?.GetViewModel;
}
return null;
} }
public List<ClientViewModel> GetFilteredList(ClientSearchModel model) public List<ClientViewModel> GetFilteredList(ClientSearchModel model)
{ {
if (string.IsNullOrEmpty(model.Email) || string.IsNullOrEmpty(model.Password)) if (string.IsNullOrEmpty(model.Email))
{ {
return new(); return new();
} }
using var context = new FurnitureAssemblyDatabase(); using var context = new FurnitureAssemblyDatabase();
return context.Clients return context.Clients
.Where(x => x.Email.Equals(model.Email) && x.Password.Equals(model.Password)) .Where(x => x.Email.Equals(model.Email))
.Select(x => x.GetViewModel) .Select(x => x.GetViewModel)
.ToList(); .ToList();
} }

View File

@ -32,15 +32,22 @@ namespace FurnitureAssemblyListImplement.Implements
public ClientViewModel? GetElement(ClientSearchModel model) public ClientViewModel? GetElement(ClientSearchModel model)
{ {
if (string.IsNullOrEmpty(model.Email) && !model.Id.HasValue)
{
return null;
}
foreach (var client in _source.Clients) foreach (var client in _source.Clients)
{ {
if ((!string.IsNullOrEmpty(model.Email) && client.Email == model.Email) if (model.Id.HasValue && client.Id == model.Id)
|| (model.Id.HasValue && client.Id == model.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 client.GetViewModel;
} }
@ -57,7 +64,7 @@ namespace FurnitureAssemblyListImplement.Implements
} }
foreach (var client in _source.Clients) foreach (var client in _source.Clients)
{ {
if (client.Email.Equals(model.Email) && client.Password.Equals(model.Password)) if (client.Email.Equals(model.Email))
{ {
result.Add(client.GetViewModel); result.Add(client.GetViewModel);
} }