Важное исправление

This commit is contained in:
prodigygirl 2023-04-09 10:14:05 +04:00
parent c823a62a24
commit 9c4bb0ad59

View File

@ -10,26 +10,40 @@ namespace HospitalDatabaseImplement.Implements
{
public ApothecaryViewModel? GetElement(ApothecarySearchModel model)
{
if (string.IsNullOrEmpty(model.Login) && !model.Id.HasValue)
if (string.IsNullOrEmpty(model.Login) && !model.Id.HasValue && string.IsNullOrEmpty(model.Password))
{
return null;
}
using var context = new HospitalDatabase();
return context.Apothecaries.FirstOrDefault(x =>
(!string.IsNullOrEmpty(model.Login) && x.Login == model.Login) ||
(model.Id.HasValue && x.Id == model.Id))
?.GetViewModel;
if (model.Id.HasValue)
{
return context.Apothecaries.FirstOrDefault(x => model.Id.HasValue && x.Id == model.Id)
?.GetViewModel;
}
if (model.Login != null && model.Password != null)
{
return context.Apothecaries
.FirstOrDefault(x => x.Login.Equals(model.Login) && x.Password.Equals(model.Password))
?.GetViewModel;
}
if (model.Login != null)
return context.Apothecaries.FirstOrDefault(x => x.Login == model.Login)?.GetViewModel;
return null;
}
public List<ApothecaryViewModel> GetFilteredList(ApothecarySearchModel model)
{
if (string.IsNullOrEmpty(model.Login) || string.IsNullOrEmpty(model.Password))
if (string.IsNullOrEmpty(model.Login))
{
return new();
}
using var context = new HospitalDatabase();
return context.Apothecaries
.Where(x => x.Login.Equals(model.Login) && x.Password.Equals(model.Password))
.Where(x => x.Login.Equals(model.Login))
.Select(x => x.GetViewModel)
.ToList();
}