public FilterdClaimsDTO GetAllClaims(ClaimsFilter claimsFilter) { FilterdClaimsDTO filterdClaimsdto = new FilterdClaimsDTO(); filterdClaimsdto.FilterdClaims = new List <Claim>(); filterdClaimsdto.NumberOfClaimsReturned = filterdClaimsdto.FilterdClaims.Count(); // If user did not supply a filter if (claimsFilter.Police_No == null && claimsFilter.Claimed_Amount_From == null && claimsFilter.Claimed_Amount_To == null && claimsFilter.Incured_Date_From == null && claimsFilter.Claimed_Amount_To == null) { var claims = _context.Claims .OrderByDescending(c => c.Claimed_Amount) .Skip((claimsFilter.PageNumber - 1) * claimsFilter.PageSize) .Take(claimsFilter.PageSize) .ToList(); filterdClaimsdto.FilterdClaims.AddRange(claims); filterdClaimsdto.NumberOfClaimsReturned = filterdClaimsdto.FilterdClaims.Count(); } else if (claimsFilter.Police_No != null) { // If user did supply only a policy No var claims = _context.Claims .Where(c => c.Police_No == claimsFilter.Police_No) .OrderByDescending(c => c.Claimed_Amount) .Skip((claimsFilter.PageNumber - 1) * claimsFilter.PageSize) .Take(claimsFilter.PageSize) .ToList(); filterdClaimsdto.FilterdClaims.AddRange(claims); filterdClaimsdto.NumberOfClaimsReturned = filterdClaimsdto.FilterdClaims.Count(); // If user did supply a policy No and ClaimedAmount From and To if (claimsFilter.Claimed_Amount_From != null && claimsFilter.Claimed_Amount_To != null) { filterdClaimsdto.FilterdClaims.Clear(); var claimsAmountFilter = _context.Claims .Where(c => (c.Police_No == claimsFilter.Police_No && c.Claimed_Amount >= claimsFilter.Claimed_Amount_From) && c.Claimed_Amount <= claimsFilter.Claimed_Amount_To) .OrderByDescending(c => c.Claimed_Amount) .Skip((claimsFilter.PageNumber - 1) * claimsFilter.PageSize) .Take(claimsFilter.PageSize) .ToList(); filterdClaimsdto.FilterdClaims.AddRange(claimsAmountFilter); filterdClaimsdto.NumberOfClaimsReturned = filterdClaimsdto.FilterdClaims.Count(); } // If user did supply a policy No and IncuredDate From and To if (claimsFilter.Incured_Date_From != null && claimsFilter.Incured_Date_To != null) { filterdClaimsdto.FilterdClaims.Clear(); var claimsIncuredFilter = _context.Claims .Where(c => (c.Police_No == claimsFilter.Police_No && c.Incured_Date >= claimsFilter.Incured_Date_From) && c.Incured_Date <= claimsFilter.Incured_Date_To) .OrderByDescending(c => c.Claimed_Amount) .Skip((claimsFilter.PageNumber - 1) * claimsFilter.PageSize) .Take(claimsFilter.PageSize) .ToList(); filterdClaimsdto.FilterdClaims.AddRange(claimsIncuredFilter); filterdClaimsdto.NumberOfClaimsReturned = filterdClaimsdto.FilterdClaims.Count(); } } // If user did supply only Claimed_Amount_From and To else if (claimsFilter.Claimed_Amount_From != null && claimsFilter.Claimed_Amount_To != null) { filterdClaimsdto.FilterdClaims.Clear(); var claimsAmountFilter = _context.Claims .Where(c => (c.Claimed_Amount >= claimsFilter.Claimed_Amount_From) && c.Claimed_Amount <= claimsFilter.Claimed_Amount_To) .OrderByDescending(c => c.Claimed_Amount) .Skip((claimsFilter.PageNumber - 1) * claimsFilter.PageSize) .Take(claimsFilter.PageSize) .ToList(); filterdClaimsdto.FilterdClaims.AddRange(claimsAmountFilter); filterdClaimsdto.NumberOfClaimsReturned = filterdClaimsdto.FilterdClaims.Count(); } // If user did supply only Incured_Date From and To else if (claimsFilter.Incured_Date_From != null && claimsFilter.Incured_Date_To != null) { filterdClaimsdto.FilterdClaims.Clear(); var claimsIncuredFilter = _context.Claims .Where(c => (c.Incured_Date >= claimsFilter.Incured_Date_From) && c.Incured_Date <= claimsFilter.Incured_Date_To) .OrderByDescending(c => c.Claimed_Amount) .Skip((claimsFilter.PageNumber - 1) * claimsFilter.PageSize) .Take(claimsFilter.PageSize) .ToList(); filterdClaimsdto.FilterdClaims.AddRange(claimsIncuredFilter); filterdClaimsdto.NumberOfClaimsReturned = filterdClaimsdto.FilterdClaims.Count(); } return(filterdClaimsdto); }
public IActionResult GetAllClaims(ClaimsFilter claimsFilter) { var claims = _unitOfWork.Claim.GetAllClaims(claimsFilter); return(Ok(claims)); }