add role search by name
This commit is contained in:
parent
b1d13a591d
commit
106ad56325
@ -9,5 +9,6 @@ namespace Contracts.SearchModels
|
||||
public class RoleSearchModel
|
||||
{
|
||||
public Guid? Id { get; set; }
|
||||
public string? Name { get; set; }
|
||||
}
|
||||
}
|
@ -32,20 +32,21 @@ namespace DatabaseImplement.Implements
|
||||
|
||||
public RoleBindingModel? GetElement(RoleSearchModel model)
|
||||
{
|
||||
if (model.Id is null)
|
||||
if (model.Id is null && string.IsNullOrWhiteSpace(model.Name))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
var context = new Database();
|
||||
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();
|
||||
}
|
||||
|
||||
public IEnumerable<RoleBindingModel> GetList(RoleSearchModel? model)
|
||||
{
|
||||
var context = new Database();
|
||||
if (model is null)
|
||||
if (model is null && string.IsNullOrWhiteSpace(model.Name))
|
||||
{
|
||||
return context.Roles.Select(r => r.GetBindingModel());
|
||||
}
|
||||
@ -54,7 +55,8 @@ namespace DatabaseImplement.Implements
|
||||
return [];
|
||||
}
|
||||
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());
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user