dev #12

Merged
mfnefd merged 5 commits from dev into registration 2024-06-20 04:20:37 +04:00
2 changed files with 72 additions and 69 deletions
Showing only changes of commit 106ad56325 - Show all commits

View File

@ -9,5 +9,6 @@ namespace Contracts.SearchModels
public class RoleSearchModel public class RoleSearchModel
{ {
public Guid? Id { get; set; } public Guid? Id { get; set; }
public string? Name { get; set; }
} }
} }

View File

@ -32,20 +32,21 @@ namespace DatabaseImplement.Implements
public RoleBindingModel? GetElement(RoleSearchModel model) public RoleBindingModel? GetElement(RoleSearchModel model)
{ {
if (model.Id is null) if (model.Id is null && string.IsNullOrWhiteSpace(model.Name))
{ {
return null; return null;
} }
var context = new Database(); var context = new Database();
return context.Roles return context.Roles
.FirstOrDefault(r => r.Id == model.Id) .FirstOrDefault(r => (model.Id.HasValue && r.Id == model.Id)
|| (!string.IsNullOrWhiteSpace(model.Name) && r.Name.Contains(model.Name)))
?.GetBindingModel(); ?.GetBindingModel();
} }
public IEnumerable<RoleBindingModel> GetList(RoleSearchModel? model) public IEnumerable<RoleBindingModel> GetList(RoleSearchModel? model)
{ {
var context = new Database(); var context = new Database();
if (model is null) if (model is null && string.IsNullOrWhiteSpace(model.Name))
{ {
return context.Roles.Select(r => r.GetBindingModel()); return context.Roles.Select(r => r.GetBindingModel());
} }
@ -54,7 +55,8 @@ namespace DatabaseImplement.Implements
return []; return [];
} }
return context.Roles return context.Roles
.Where(r => r.Id == model.Id) .Where(r => (model.Id.HasValue && r.Id == model.Id)
|| (!string.IsNullOrWhiteSpace(model.Name) && r.Name.Contains(model.Name)))
.Select(r => r.GetBindingModel()); .Select(r => r.GetBindingModel());
} }