public object GetNatureAreaSummary([FromBody] AreaFilterRequest areaFilterRequest)
        {
            if (string.IsNullOrWhiteSpace(areaFilterRequest.Geometry) && cachedNatureAreaSummary != null)
            {
                return(cachedNatureAreaSummary);
            }

            var geometry = "";

            if (areaFilterRequest != null)
            {
                geometry = areaFilterRequest.Geometry;
            }

            var natureAreaTypes        = SqlServer.GetNatureAreaSummary(geometry);
            var natureAreaTypeHash     = new CodeIds();
            var decriptionVariableHash = new CodeIds();

            foreach (var natureAreaTypeItem in natureAreaTypes)
            {
                if (natureAreaTypeItem.Item3)
                {
                    if (natureAreaTypeHash.ContainsKey(natureAreaTypeItem.Item1))
                    {
                        natureAreaTypeHash[natureAreaTypeItem.Item1].Add(natureAreaTypeItem.Item2);
                    }
                    else
                    {
                        natureAreaTypeHash[natureAreaTypeItem.Item1] = new HashSet <int> {
                            natureAreaTypeItem.Item2
                        }
                    };
                }
                else
                {
                    if (decriptionVariableHash.ContainsKey(natureAreaTypeItem.Item1))
                    {
                        decriptionVariableHash[natureAreaTypeItem.Item1].Add(natureAreaTypeItem.Item2);
                    }
                    else
                    {
                        decriptionVariableHash[natureAreaTypeItem.Item1] = new HashSet <int> {
                            natureAreaTypeItem.Item2
                        }
                    };
                }
            }

            CodeSummaryItem natureAreaTypeSummary      = GetNatureAreaTypeSummary(natureAreaTypeHash);
            CodeSummaryItem descriptionVariableSummary = GetDescriptionVariableSummary(decriptionVariableHash);

            var r = new NatureAreaSummary
            {
                NatureAreaTypes      = natureAreaTypeSummary,
                DescriptionVariables = descriptionVariableSummary
            };

            var jo = JObject.FromObject(r);

            RemoveFields(jo, "HandledIds", true);
            if (jo.First != null)
            {
                RemoveFields(jo.First.First, "Name", false);
                RemoveFields(jo.First.First, "Url", false);
                RemoveFields(jo.First.First, "Count", false);
            }
            if (jo.Last != null)
            {
                RemoveFields(jo.Last.First, "Name", false);
                RemoveFields(jo.Last.First, "Url", false);
                RemoveFields(jo.Last.First, "Count", false);
            }

            if (string.IsNullOrWhiteSpace(areaFilterRequest.Geometry))
            {
                cachedNatureAreaSummary = jo;
            }

            return(jo);
        }
        public object GetNatureAreaSummary(AreaFilterRequest areaFilterRequest)
        {
            var geometry = "";

            if (areaFilterRequest != null)
            {
                geometry = areaFilterRequest.Geometry;
            }

            var natureAreaTypes        = SqlServer.GetNatureAreaSummary(geometry);
            var natureAreaTypeHash     = new CodeIds();
            var decriptionVariableHash = new CodeIds();

            foreach (var natureAreaTypeItem in natureAreaTypes)
            {
                if (natureAreaTypeItem.Item3)
                {
                    if (natureAreaTypeHash.ContainsKey(natureAreaTypeItem.Item1))
                    {
                        natureAreaTypeHash[natureAreaTypeItem.Item1].Add(natureAreaTypeItem.Item2);
                    }
                    else
                    {
                        natureAreaTypeHash[natureAreaTypeItem.Item1] = new HashSet <int> {
                            natureAreaTypeItem.Item2
                        }
                    };
                }
                else
                {
                    if (decriptionVariableHash.ContainsKey(natureAreaTypeItem.Item1))
                    {
                        decriptionVariableHash[natureAreaTypeItem.Item1].Add(natureAreaTypeItem.Item2);
                    }
                    else
                    {
                        decriptionVariableHash[natureAreaTypeItem.Item1] = new HashSet <int> {
                            natureAreaTypeItem.Item2
                        }
                    };
                }
            }

            var natureAreaTypeSummary      = GetCodeSummaryHierarchy(natureAreaTypeHash, Naturkodetrær.Naturtyper);
            var descriptionVariableSummary =
                GetCodeSummaryHierarchy(decriptionVariableHash, Naturkodetrær.Naturvariasjon);

            var r = new NatureAreaSummary
            {
                NatureAreaTypes      = natureAreaTypeSummary,
                DescriptionVariables = descriptionVariableSummary
            };

            var jo = JObject.FromObject(r);

            RemoveFields(jo, "HandledIds", true);
            if (jo.First != null)
            {
                RemoveFields(jo.First.First, "Name", false);
                RemoveFields(jo.First.First, "Url", false);
                RemoveFields(jo.First.First, "Count", false);
            }
            if (jo.Last != null)
            {
                RemoveFields(jo.Last.First, "Name", false);
                RemoveFields(jo.Last.First, "Url", false);
                RemoveFields(jo.Last.First, "Count", false);
            }

            return(jo);
        }