Исправление по получению элемента (Клиента)

This commit is contained in:
prodigygirl 2023-04-09 10:15:25 +04:00
parent 6cef60fc0d
commit 2d5dccd197

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();
return context.Clients
.FirstOrDefault(x =>
(!string.IsNullOrEmpty(model.Email) && x.Email == model.Email) ||
(model.Id.HasValue && x.Id == model.Id))
?.GetViewModel;
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 => 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();
}