Beispiel #1
0
            public object Get(LocationCount request)
            {
                var resp = new Dto <long>();

                resp.Result = Handler.Count();
                return(resp);
            }
        public IHttpActionResult GetCountOnLocation()
        {
            var locationCount = new LocationCount();
            var species       = new List <Specie>();

            using (
                var conn =
                    new SqlConnection(
                        @"Data Source=localhost\SQLEXPRESS;Initial Catalog=RedList;Integrated Security=SSPI;"))
            {
                conn.Open();
                species = conn.Query <Specie>("select * from Species where category not like 'LC'").ToList();

                foreach (var specie in species)
                {
                    if (!string.IsNullOrWhiteSpace(specie.Hordaland) || !string.IsNullOrWhiteSpace(specie.Hordaland))
                    {
                        locationCount.Hordaland++;
                    }
                    if (!string.IsNullOrWhiteSpace(specie.Akershus) || !string.IsNullOrWhiteSpace(specie.Akershus))
                    {
                        locationCount.Akershus++;
                    }
                    if (!string.IsNullOrWhiteSpace(specie.AustAgder) || !string.IsNullOrWhiteSpace(specie.AustAgder))
                    {
                        locationCount.Aust_Agder++;
                    }
                    if (!string.IsNullOrWhiteSpace(specie.Buskerud) || !string.IsNullOrWhiteSpace(specie.Buskerud))
                    {
                        locationCount.Buskerud++;
                    }
                    if (!string.IsNullOrWhiteSpace(specie.Finnmark) || !string.IsNullOrWhiteSpace(specie.Finnmark))
                    {
                        locationCount.Finnmark++;
                    }
                    if (!string.IsNullOrWhiteSpace(specie.Hedmark) || !string.IsNullOrWhiteSpace(specie.Hedmark))
                    {
                        locationCount.Hedmark++;
                    }
                    if (!string.IsNullOrWhiteSpace(specie.MoreogRomsdal) ||
                        !string.IsNullOrWhiteSpace(specie.MoreogRomsdal))
                    {
                        locationCount.Møre_og_Romsdal++;
                    }
                    if (!string.IsNullOrWhiteSpace(specie.NordTrondelag) ||
                        !string.IsNullOrWhiteSpace(specie.NordTrondelag))
                    {
                        locationCount.Nord_Trøndelag++;
                    }
                    if (!string.IsNullOrWhiteSpace(specie.Nordland) || !string.IsNullOrWhiteSpace(specie.Nordland))
                    {
                        locationCount.Nordland++;
                    }
                    if (!string.IsNullOrWhiteSpace(specie.Oppland) || !string.IsNullOrWhiteSpace(specie.Oppland))
                    {
                        locationCount.Oppland++;
                    }
                    if (!string.IsNullOrWhiteSpace(specie.Oslo) || !string.IsNullOrWhiteSpace(specie.Oslo))
                    {
                        locationCount.Oslo++;
                    }
                    if (!string.IsNullOrWhiteSpace(specie.Ostfold) || !string.IsNullOrWhiteSpace(specie.Ostfold))
                    {
                        locationCount.Østfold++;
                    }
                    if (!string.IsNullOrWhiteSpace(specie.Rogaland) || !string.IsNullOrWhiteSpace(specie.Rogaland))
                    {
                        locationCount.Rogaland++;
                    }
                    if (!string.IsNullOrWhiteSpace(specie.SognogFjordane) ||
                        !string.IsNullOrWhiteSpace(specie.SognogFjordane))
                    {
                        locationCount.Sogn_og_Fjordane++;
                    }
                    if (!string.IsNullOrWhiteSpace(specie.SorTrondelag) ||
                        !string.IsNullOrWhiteSpace(specie.SorTrondelag))
                    {
                        locationCount.Sør_Trøndelag++;
                    }
                    if (!string.IsNullOrWhiteSpace(specie.Telemark) || !string.IsNullOrWhiteSpace(specie.Telemark))
                    {
                        locationCount.Telemark++;
                    }
                    if (!string.IsNullOrWhiteSpace(specie.Troms) || !string.IsNullOrWhiteSpace(specie.Troms))
                    {
                        locationCount.Troms++;
                    }
                    if (!string.IsNullOrWhiteSpace(specie.VestAgder) || !string.IsNullOrWhiteSpace(specie.VestAgder))
                    {
                        locationCount.Vest_Agder++;
                    }
                    if (!string.IsNullOrWhiteSpace(specie.Vestfold) || !string.IsNullOrWhiteSpace(specie.Vestfold))
                    {
                        locationCount.Vestfold++;
                    }
                }
            }
            return(Ok(locationCount));
        }