Ejemplo n.º 1
0
        public async Task <IActionResult> GetZemfondInfo(
            string objectid)
        {
            string DefaultConnection = Microsoft
                                       .Extensions
                                       .Configuration
                                       .ConfigurationExtensions
                                       .GetConnectionString(Startup.Configuration, "DefaultConnection");
            zemfondpol zemfondpol = new zemfondpol();

            using (var connection = new NpgsqlConnection(DefaultConnection))
            {
                connection.Open();
                var zemfondpols = connection.Query <zemfondpol>($"SELECT gid, objectid, type_k, ur_avgyear, " +
                                                                $"dominant_t, korm_avgye, area, s_recomend, subtype_k, kato_te_1, shape_leng, shape_area, geom " +
                                                                $"FROM public.zemfondpol " +
                                                                $"WHERE objectid = {objectid};");
                zemfondpol = zemfondpols.FirstOrDefault();
            }
            zemfondpol.stype           = _context.SType.FirstOrDefault(s => s.Code == zemfondpol.type_k)?.Description;
            zemfondpol.dominanttype    = _context.DominantType.FirstOrDefault(d => d.Code == zemfondpol.dominant_t)?.Description;
            zemfondpol.supplyrecommend = _context.SupplyRecommend.FirstOrDefault(s => s.Code == zemfondpol.s_recomend)?.Description;
            return(Json(new
            {
                zemfondpol
            }));
        }
Ejemplo n.º 2
0
        public ActionResult GetCATOZemfondInfo(
            string catote)
        {
            string DefaultConnection = Microsoft
                                       .Extensions
                                       .Configuration
                                       .ConfigurationExtensions
                                       .GetConnectionString(Startup.Configuration, "DefaultConnection");
            string ab = catote?.Substring(0, 2),
                   cd = catote?.Substring(2, 2),
                   ef = catote?.Substring(4, 2),
                   te = ab;

            if (cd != "00")
            {
                te += cd;
            }
            if (ef != "00")
            {
                te += ef;
            }

            List <zemfondpol> zemfondpols = new List <zemfondpol>();
            zemfondpol        zemfondpol  = new zemfondpol();

            using (var connection = new NpgsqlConnection(DefaultConnection))
            {
                connection.Open();
                string query         = $"SELECT ur_avgyear, korm_avgye, area FROM public.zemfondpol WHERE kato_te_1 LIKE '{te}%';";
                var    zemfondpolsDB = connection.Query <zemfondpol>(query);
                zemfondpols           = zemfondpolsDB.ToList();
                zemfondpol.area       = zemfondpols.Where(z => z.ur_avgyear > 0).Sum(z => z.area);
                zemfondpol.ur_avgyear = zemfondpols.Sum(z => z.area * z.ur_avgyear) / zemfondpol.area;
                zemfondpol.korm_avgye = zemfondpols.Sum(z => z.korm_avgye);
            }

            List <zemfondpol> zemfondpols_stypes = new List <zemfondpol>();

            using (var connection = new NpgsqlConnection(DefaultConnection))
            {
                connection.Open();
                string query         = $"SELECT type_k, SUM(area) as shape_area FROM public.zemfondpol WHERE kato_te_1 LIKE '{te}%' GROUP BY type_k;";
                var    zemfondpolsDB = connection.Query <zemfondpol>(query);
                zemfondpols_stypes = zemfondpolsDB.ToList();
            }

            List <zemfondpol> zemfondpols_supplyrecommends = new List <zemfondpol>();

            using (var connection = new NpgsqlConnection(DefaultConnection))
            {
                connection.Open();
                string query         = $"SELECT s_recomend, SUM(area) as shape_area FROM public.zemfondpol WHERE kato_te_1 LIKE '{te}%' GROUP BY s_recomend;";
                var    zemfondpolsDB = connection.Query <zemfondpol>(query);
                zemfondpols_supplyrecommends = zemfondpolsDB.ToList();
            }

            return(Json(new
            {
                zemfondpol,
                zemfondpols_stypes,
                zemfondpols_supplyrecommends
            }));
        }