I want to order the result with multiple comparisons like (by paid users, updated date, created date).
var order = _vrepository.Details()
.Where(od => od.Order.Id != null
&& od.PlanName.ToLower().Contains("DP".ToLower())
&& od.Order.Status == true)
.OrderByDescending(od => od.ValidityTill)
.Select(ord => ord.Order.Id.Value);
The above one I am getting the paid users.
var updatedList = _repository.GetUsers()
.Where(c => c.UpdatedDate != null
&& fresh <= c.UpdatedDate)
.Select(c => c.Id);
This second query I am getting updated users.
var UsersListByCreatedDate = _repository.GetUsers()
.Where(c => fresh <= c.CreatedDate)
.Select(c => c.Id);
The third one is for get the users by created date. Then I am selecting the Id (an Integer)
lstId = order.ToList();
lstUpdatedUsersId = updatedList ToList();
lstCreatedDatewiseUsers = UsersListByCreatedDate.ToList();
To show the ordered list I did the following code:
Func<IQueryable<User>, IOrderedQueryable<User>> orderingFunc = query =>
{
if (order.Count() > 0)
return query.OrderByDescending(rslt => lstId .Contains(rslt.Id))
.ThenByDescending(rslt => lstUpdatedUsersId .Contains(rslt.Id))
.ThenByDescending(rslt => lstCreatedDatewiseUsers.Contains(rslt.Id));
else
return query.OrderByDescending(rslt => lstUpdatedUsersId .Contains(rslt.Id))
.ThenByDescending(rslt => rslt.UpdatedDate);
};
But I am getting result as One Paid user, some Created user and the date is before 3 years like wise. I want to get the exact order is as follows
- Ordered User
- Updated User
- Created User
Please help me to solve this issue. Hope I will get correct result.