I apologize in advance for my English.
I have a user search method. It's parameters - login
and strict
. The last one determines, which method should have been used for search - Equals
(strict is true) or Contains
(strict is false). How should I implement it? I could do two different methods, but I think it would be code repeating.
public async Task<List<UserFindInfoDTO>> FindUserByLoginAsync(string login, bool strict)
{
var users = await context.Users
.Where(u => u.Nickname.Equals(login)) // change on "Contains" if strict is false
.Select(u => new UserFindInfoDTO
{
Status = u.Status,
Id = u.Id,
MiniAvatar = u.Image,
Nickname = u.Nickname
})
.ToListAsync();
...
return users;
}