public ContentResult GetParents(AggregationRelationParameters parameters)
        {
            // XXX Fixme, change from getting children to get parents
            SecurityService.CreateAccessContext();

            if (String.IsNullOrEmpty(parameters.Query))
            {
                parameters.Query = "*:*";
            }

            CFAggregationAssociationsViewModel response = new CFAggregationAssociationsViewModel
            {
                Page         = parameters.Page,
                TotalItems   = 1,
                ItemsPerPage = 1,
                TotalPages   = 1
            };


            int total;

            //string mappedGuid =
            CFAggregation aggregation = AggregationService.GetAggregation(parameters.id);
            string        mappedGuid  = aggregation.MappedGuid;

            AggregationService.Detach(aggregation);
            response.Data = AggregationService.Parents(
                mappedGuid,
                out total,
                parameters.Query,
                response.Page,
                parameters.ItemsPerPage).Select(x => new CFAggregationIndexViewModel(x));

            response.TotalItems   = total;
            response.ItemsPerPage = parameters.ItemsPerPage;
            response.TotalPages   = (int)Math.Ceiling((double)response.TotalItems / response.ItemsPerPage);

            string responseString = JsonConvert.SerializeObject(response,
                                                                Formatting.None
                                                                );

            return(Content(responseString, "application/json"));
        }
        public ContentResult Index([System.Web.Http.FromUri] AggregationRelationParameters parameters)
        {
            SecurityService.CreateAccessContext();

            if (String.IsNullOrEmpty(parameters.Query))
            {
                parameters.Query = "*:*";
            }

            if (!string.IsNullOrEmpty(parameters.Type))
            {
                parameters.Query = string.Format("{1} AND modeltype_s: {0}", parameters.Type, parameters.Query);
            }

            CFAggregationAssociationsViewModel response = new CFAggregationAssociationsViewModel
            {
                Page         = parameters.Page,
                TotalItems   = 1,
                ItemsPerPage = 1,
                TotalPages   = 1
            };


            int total;

            response.Data = AggregationService.Index(
                out total,
                parameters.Query,
                response.Page,
                parameters.ItemsPerPage, parameters.EntityType).Select(x => new CFAggregationIndexViewModel(x));

            response.TotalItems   = total;
            response.ItemsPerPage = parameters.ItemsPerPage;
            response.TotalPages   = (int)Math.Ceiling((double)response.TotalItems / response.ItemsPerPage);

            string responseString = JsonConvert.SerializeObject(response,
                                                                Formatting.None
                                                                );

            return(Content(responseString, "application/json"));
        }
        public ContentResult GetRelated([System.Web.Http.FromUri] AggregationRelationParameters parameters)
        {
            SecurityService.CreateAccessContext();

            if (String.IsNullOrEmpty(parameters.Query))
            {
                parameters.Query = "*:*";
            }

            CFAggregationAssociationsViewModel response = new CFAggregationAssociationsViewModel
            {
                Page         = parameters.Page,
                TotalItems   = 1,
                ItemsPerPage = 1,
                TotalPages   = 1
            };


            // XXX Fix me
            int total;

            //string mappedGuid =
            CFAggregation test = AggregationService.GetAggregation(parameters.id);

            response.Data = AggregationService.Related(
                test.MappedGuid,
                out total,
                parameters.Query,
                response.Page,
                parameters.ItemsPerPage).Select(x => new CFAggregationIndexViewModel(x));

            response.TotalItems   = total;
            response.ItemsPerPage = parameters.ItemsPerPage;
            response.TotalPages   = (int)Math.Ceiling((double)response.TotalItems / response.ItemsPerPage);

            string responseString = JsonConvert.SerializeObject(response,
                                                                Formatting.None
                                                                );

            return(Content(responseString, "application/json"));
        }