public async Task <decimal> GetSumAsync(VariableDataQuery queryObj) { queryObj.IsPaging = false; decimal sum = 0; var result = new QueryResult <VariableData>(); var query = context.VariableData .AsQueryable(); query = query.ApplyFiltering(queryObj); sum = await query.SumAsync(vd => vd.Value); return(sum); }
public async Task <QueryResult <VariableData> > GetData(VariableDataQuery queryObj) { var result = new QueryResult <VariableData>(); var query = context.VariableData .AsQueryable(); query = query.ApplyFiltering(queryObj); result.TotalItems = await query.CountAsync(); query = query.ApplyPaging(queryObj); result.Items = await query.ToListAsync(); return(result); }
protected VariableDataQuery GetVariableDataQuery(SubVariableData dataItem) { var variableDataQuery = new VariableDataQuery { ScenarioId = dataItem.ScenarioId, VariableId = dataItem.VariableId, KeyParameterId = dataItem.KeyParameterId, KeyParameterLevelId = dataItem.KeyParameterLevelId, ProcessSetId = dataItem.ProcessSetId, AttributeId = dataItem.AttributeId, CommodityId = dataItem.CommodityId, CommoditySetId = dataItem.CommoditySetId, UserConstraintId = dataItem.UserConstraintId, Year = dataItem.Year, IsPaging = false }; if (IsRegionIncluded) { variableDataQuery.RegionId = dataItem.RegionId; } return(variableDataQuery); }
public static IQueryable <VariableData> ApplyFiltering(this IQueryable <VariableData> query, VariableDataQuery queryObj) { if (queryObj.VariableId.HasValue) { query = query.Where(v => v.VariableId == queryObj.VariableId.Value); } if (queryObj.RegionId.HasValue) { query = query.Where(v => v.RegionId == queryObj.RegionId.Value); } if (queryObj.ScenarioId.HasValue) { query = query.Where(v => v.ScenarioId == queryObj.ScenarioId.Value); } if (queryObj.KeyParameterId.HasValue) { query = query.Where(v => v.KeyParameterId == queryObj.KeyParameterId.Value); } if (queryObj.KeyParameterLevelId.HasValue) { query = query.Where(v => v.KeyParameterLevelId == queryObj.KeyParameterLevelId.Value); } if (!string.IsNullOrEmpty(queryObj.Year)) { query = query.Where(v => v.Year == queryObj.Year); } #region Attributes if (queryObj.ProcessSetId.HasValue) { query = query.Where(v => v.ProcessSetId == queryObj.ProcessSetId.Value); } if (queryObj.UserConstraintId.HasValue) { query = query.Where(v => v.UserConstraintId == queryObj.UserConstraintId.Value); } if (queryObj.AttributeId.HasValue) { query = query.Where(v => v.AttributeId == queryObj.AttributeId.Value); } if (queryObj.CommodityId.HasValue) { query = query.Where(v => v.CommodityId == queryObj.CommodityId.Value); } if (queryObj.CommoditySetId.HasValue) { query = query.Where(v => v.CommoditySetId == queryObj.CommoditySetId.Value); } #endregion Attributes return(query); }