public List<Donation> GetAllDonationsAfterSearchWithParameter(out int totalCount, string orderBy = default(string), int startRowIndex = default(int), int maximumRows = default(int), string DonorNumber = default(string), DateTime DonationDateFrom = default(DateTime), DateTime DonationDateTo = default(DateTime), decimal DonationAmountFrom = default(decimal), decimal DonationAmountTo = default(decimal), string FirstName = default(string), string LastName = default(string), string EmailAddress = default(string), string OrderStatus = default(string))
{
if (string.IsNullOrEmpty(orderBy))
orderBy = "DonationId";
string[] orderStatusArray = { "" };
if (!string.IsNullOrEmpty(OrderStatus))
{
if (OrderStatus.Contains(','))
{
orderStatusArray = OrderStatus.Split(',');
OrderStatus = default(string);
}
}
if (DonationDateFrom == default(DateTime))
{
// DonationDateFrom = new DateTime(1900, 1, 1);
DonationDateFrom = SqlDateTime.MinValue.Value;
}
if (DonationDateTo == default(DateTime))
DonationDateTo = SqlDateTime.MaxValue.Value;
List<Donation> temp = (from donation in _DatabaseContext.Donations
.DynamicOrderBy(orderBy)
where (string.IsNullOrEmpty(OrderStatus) ? true : donation.OrderStatus.Trim() == OrderStatus.Trim())
&& (string.IsNullOrEmpty(DonorNumber) ? true : donation.DonorNumber == DonorNumber)
&&
(
(DonationDateFrom == SqlDateTime.MinValue.Value ? true : donation.DonationDate >= DonationDateFrom)
&& (DonationDateTo == SqlDateTime.MaxValue.Value ? true : donation.DonationDate <= DonationDateTo)
)
&&
(
(DonationAmountFrom == default(decimal) ? true : donation.DonationAmount >= DonationAmountFrom)
&& (DonationAmountTo == default(decimal) ? true : donation.DonationAmount <= DonationAmountTo)
)
&& (string.IsNullOrEmpty(FirstName) ? true : donation.FirstName.Contains(FirstName))
&& (string.IsNullOrEmpty(LastName) ? true : donation.LastName.Contains(LastName))
&& (string.IsNullOrEmpty(EmailAddress) ? true : donation.EmailAddress.Contains(EmailAddress.Trim()))
select donation
).ToList();
if (orderStatusArray.Length > 1)
{
temp = temp.FindAll(x => x.OrderStatus == orderStatusArray[0] || x.OrderStatus == orderStatusArray[1]);
}
totalCount = temp.Count;
List<Donation> list = temp.Skip(startRowIndex).Take(maximumRows).ToList();
temp = null;
return list;
}