public async Task <ApiResult> GetHazardRulesAsync(HazardRuleFilter hazardRuleFilter) { var hazardRulesPagedResult = await hazardRuleRepository.GetHazardRulesAsync(hazardRuleFilter); var hazardRulesDtoPagedResult = new PagedResult <HazardRuleDto>(); Mapper.Map(hazardRulesPagedResult, hazardRulesDtoPagedResult); return(new ApiResult(MessageType.Success, hazardRulesDtoPagedResult)); }
private Expression <Func <HazardRule, bool> > GetHazardRuleExpression(HazardRuleFilter filter) { Expression <Func <HazardRule, bool> > expression = null; if (filter.Id > 0) { expression = x => x.Id == filter.Id; } return(expression); }
public async Task <PagedResult <HazardRule> > GetHazardRulesAsync(HazardRuleFilter filter) { filter = filter ?? new HazardRuleFilter(); var result = unitOfWork.Query(GetHazardRuleExpression(filter), filter.PropertiesToInclude); List <HazardRule> list = await result.OrderBy(filter.OrderBy) .Skip((filter.Page - 1) * filter.Skip).Take(filter.Take) .ToListAsync(); var pagedResult = new PagedResult <HazardRule> { Data = list, PageInfo = await GetPageInfo(x => x.Id, filter, GetHazardRuleExpression(filter)) }; return(pagedResult); }
public async Task <IHttpActionResult> GetHazardRules(HazardRuleFilter filter) { var hazardRules = await hazardRuleManager.GetHazardRulesAsync(filter); return(Ok(hazardRules)); }