I have issue with implementation Get method into my manager class. How do i need to filter and where i need to write filter method.
In short - i have data class Gym, repository class and method Find in it. I wrote methods in data classes - IsAppreciateToRequest(RequestName) to do smth like this in manager class
public IEnumerable<GymDto> GetGyms(GetGymRequest request)
{
return _gymRepository
.Find(gym => gym.IsAppreciateToRequest(request))
.AsEnumerable()
.Select(GymDto.FromEntityToDto);
}
I think this is shitcode, but also idk how to get rid of this and how to write it proper way(before this i had Get method like 30-50 lines longer in every manager class)
IsAppreciateToRequest method:
public bool IsAppreciateToRequest(GetGymRequest other)
{
return (string.IsNullOrEmpty(other.Name) || Name == other.Name)
&& (string.IsNullOrEmpty(other.Location) || Location == other.Location)
&& (other.SectionRequest == null || Sections.All(section => section.IsAppreciateToRequest(other.SectionRequest)));
}