public PageResultDTO <PolicyDTOWithActions> GetAllPolicies(int pageSize, int pageIndex) { var fs = new ListFetchStrategy <Policy>(Enums.FetchInUnitOfWorkOption.NoTracking); fs.OrderBy(x => x.Id); fs.WithPaging(pageSize, pageIndex); policyRep.FindBy(fs); var res = new PageResultDTO <PolicyDTOWithActions>(); res.InjectFrom(fs.PageCriteria.PageResult); res.Result = fs.PageCriteria.PageResult.Result.Select(r => policyWithActionMapper.MapToModel(r)).ToList(); return(res); }
public ResponseEntityVM FindBy(Expression <Func <PolicyModel, bool> > predicate) { try { var coverateTypeCodes = ((List <CodeVM>)_codeService.GetCoverageTypeCodes().Result).ToList(); var riskTypeCodes = ((List <CodeVM>)_codeService.GetRiskTypeCodes().Result).ToList(); var policyList = _repository.FindBy(predicate).Where(x => x.DeleteDate.Equals(null)).ToList().Select(x => new PolicyVM() { PolicyID = x.PolicyID, CoveragePercentage = x.CoveragePercentage, CoverageTypeID = x.CoverageTypeID, CoverageType = coverateTypeCodes.Where(y => y.CodeID.Equals(x.CoverageTypeID)).FirstOrDefault().Code, Description = x.Description, Name = x.Name, Price = x.Price, RiskTypeID = x.RiskTypeID, RiskType = riskTypeCodes.Where(y => y.CodeID.Equals(x.RiskTypeID)).FirstOrDefault().Code, CoverageTerm = x.CoverageTerm } ).ToList(); return(new ResponseEntityVM() { StatusCode = System.Net.HttpStatusCode.OK, Result = policyList }); } catch (Exception ex) { return(new ResponseEntityVM() { StatusCode = System.Net.HttpStatusCode.InternalServerError, Message = $"There was an error getting the Policies: {ex.Message}" }); } }