I have a params which contains a start date and end date and then use it to query, but I wanted to handle that even if there is no start and enddate, it will will query data. How do we handle that in C#?
So that if there is no startDate and endDate, then it will just proceed on the query.
The filteredData variable is the query. The issue right now is that when there is no startDate and endDate it will not query the data, so the solution if to handle date range if it has no value. Any idea guys? Thanks.
#code snippet
public async Task<IPagedList<TransactionListDto>> GetList(DateTime? startDate , DateTime? endDatestring status, int id, string sortKey, string sortOrder, string searchString, int page, int pageSize, string transactionType, string repmFilter, string transactionSubType, string masterBrokerCompany, string masterBrokerName)
{
var sortKeys = JsonConvert.DeserializeObject<List<string>>(sortKey);
var sortOrders = JsonConvert.DeserializeObject<List<string>>(sortOrder);
List<string> statusValues = new List<string>();
List<string> transactionTypeValues = new List<string>();
if (!string.IsNullOrEmpty(status))
{
statusValues = status.Split(',').ToList();
}
if (!string.IsNullOrEmpty(transactionType))
{
transactionTypeValues = transactionType.Split(',').ToList();
}
.......
var filteredData = mappedData.Where(x => (masterBrokerCompanyValues.Count == 0 || masterBrokerCompanyValues.Contains(x.MasterBrokerCompany)) && x.TargetCompletionDate >= startDate && endDate <= x.TargetCompletionDate);
var paginatedData = await AppUtil.MultipleSort<TransactionListDto>(
filteredData.AsQueryable(), sortKeys, sortOrders).ToPagedListAsync(page, pageSize);
Filterclass and change the signature toGetList(Filter filter). That's wayy to many parameters imo.