Exemplo n.º 1
0
        public override List <PropertyQueryWithResults> GetPropertyResults(List <PropertyQueryInfo> queries, List <OrganisationalUnitInfo> organisationalUnits) //List<PropertyQuery> queries, List<OrganisationalUnit> organisationalUnits)
        {
            var rawJson = string.Empty;

            //Set the Kolada url
            var apiRequest = "oudata/kpi/";

            apiRequest += string.Join(",", queries.Select(q => q.QueryId).ToList());
            apiRequest += "/ou/" + string.Join(",", organisationalUnits.Select(o => o.OrganisationalUnitId).ToList());

            //Load the data from Kolada
            rawJson = RawJson(BaseUrl + apiRequest);

            //serialize the json data
            var kpiAnswers = JsonConvert.DeserializeObject <KpiAnswers>(rawJson).Values;

            //create correct models
            List <PropertyQueryWithResults> results = new List <PropertyQueryWithResults>();

            foreach (PropertyQueryInfo query in queries)
            {
                PropertyQueryWithResults queryWithResults = new PropertyQueryWithResults(query);
                foreach (OrganisationalUnitInfo ou in organisationalUnits)
                {
                    queryWithResults.Results.Add(new PropertyQueryResult(ou.OrganisationalUnitId, kpiAnswers.Where(a => a.Kpi == query.QueryId && a.Ou == ou.OrganisationalUnitId)
                                                                         .Select(a => new PropertyQueryResultForPeriod(a.Period,
                                                                                                                       a.Values.Select(v => new PropertyQueryResultValue(v.Gender, v.Status, v.Value)).ToList()))
                                                                         .ToList(), query.Period));
                }
                results.Add(queryWithResults);
            }

            return(results);
        }
 public PropertyQueryWithResultsViewModel(PropertyQueryWithResults model)
 {
     Query   = new PropertyQueryInfoViewModel(model.Query);
     Results = model.Results;
 }