Skip to content

Instantly share code, notes, and snippets.

@rofr
Created September 11, 2020 21:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rofr/c0dfe07da575453492bdeaf78ad894ec to your computer and use it in GitHub Desktop.
Save rofr/c0dfe07da575453492bdeaf78ad894ec to your computer and use it in GitHub Desktop.
How is your day going?
private Expression<Func<ActivityHistory, bool>> GetSearchActivityExpression(ActivityHistorySearchParameters searchParameters, ActivityHistorySearchIdLists idLists)
{
return x => ((!searchParameters.DateFrom.HasValue || (DbFunctions.TruncateTime(x.CreatedDate) >= DbFunctions.TruncateTime(searchParameters.DateFrom.Value)))
&& (!searchParameters.DateTo.HasValue || (DbFunctions.TruncateTime(x.CreatedDate) <= DbFunctions.TruncateTime(searchParameters.DateTo.Value)))) &&
((searchParameters.ActionByCustomerId.HasValue && x.ActionByCustomerId.HasValue && searchParameters.ActionByCustomerId.Value == x.ActionByCustomerId.Value) || !searchParameters.ActionByCustomerId.HasValue) && // SystemAdmin are the only one without a CustomerId, they can see everything
((searchParameters.ActionByDepartmentId.HasValue && x.ActionByDepartmentId.HasValue && searchParameters.ActionByDepartmentId.Value == x.ActionByDepartmentId.Value) || !searchParameters.ActionByDepartmentId.HasValue) &&
(!searchParameters.ActionType.HasValue || x.ActionType == searchParameters.ActionType) &&
(!searchParameters.ActionSubType.HasValue || x.ActionSubType == searchParameters.ActionSubType) &&
(searchParameters.ActionByName == null || searchParameters.ActionByName == "" ||
x.ActionByType == ActivityHistoryObjectType.User && idLists.UserByList.Contains(x.ActionById) ||
x.ActionByType == ActivityHistoryObjectType.Carrier && idLists.CarrierByList.Contains(x.ActionById)) &&
(searchParameters.ActionOnName == null || searchParameters.ActionOnName == "" ||
(x.ActionOnId.HasValue && x.ActionOnType.HasValue &&
((idLists.UserOnList.Contains(x.ActionOnId.Value) && x.ActionOnType.Value == ActivityHistoryObjectType.User) ||
(idLists.CarrierOnList.Contains(x.ActionOnId.Value) && x.ActionOnType.Value == ActivityHistoryObjectType.Carrier) ||
(idLists.DepartmentOnList.Contains(x.ActionOnId.Value) && x.ActionOnType.Value == ActivityHistoryObjectType.Department) ||
(idLists.DeviceOnList.Contains(x.ActionOnId.Value) && x.ActionOnType.Value == ActivityHistoryObjectType.Device)))) &&
(x.ActionById != 0 && x.ActionOnId != 0);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment