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,17 +32,26 @@ namespace FurnitureAssemFileImplement.Implements
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;
}
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 =>
(!string.IsNullOrEmpty(model.Email) && x.Email ==
model.Email) ||
(model.Id.HasValue && x.Id == model.Id))
.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)
{
@ -51,7 +60,7 @@ namespace FurnitureAssemFileImplement.Implements
return new();
}
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)
.ToList();
}

View File

@ -28,27 +28,37 @@ namespace FurnitureAssemblyDatabaseImplement.Implements
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;
}
using var context = new FurnitureAssemblyDatabase();
if (model.Id.HasValue)
{
return context.Clients.FirstOrDefault(x => x.Id == model.Id)?.GetViewModel;
}
if (model.Email != null && model.Password != null)
{
return context.Clients
.FirstOrDefault(x =>
(!string.IsNullOrEmpty(model.Email) && x.Email == model.Email) ||
(model.Id.HasValue && x.Id == model.Id))
.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)
{
if (string.IsNullOrEmpty(model.Email) || string.IsNullOrEmpty(model.Password))
if (string.IsNullOrEmpty(model.Email))
{
return new();
}
using var context = new FurnitureAssemblyDatabase();
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)
.ToList();
}

View File

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