示例#1
0
        public IActionResult Post([FromBody] Customer customer)
        {
            if (customer == null)
            {
                return(BadRequest("Post the spatial type doesn't support yet!"));
            }

            _db.Customers.Add(customer);
            _db.SaveChanges();
            return(Created(customer));
        }
示例#2
0
        private static void BuildDatabase(SpatialDataContext db)
        {
            if (db.Customers.Any())
            {
                return;
            }

            string[] names = { "Mercury", "Venus", "Earth", "Mars", "Jupiter", "Saturn", "Uranus", "Neptune" };

            var customers = Enumerable.Range(1, 7).Select(e => new Customer
            {
                Id         = e,
                Name       = names[e - 1],
                DbLocation = String.Format("POINT({0} {1} {2} {3})", e, e, e, e)
            });

            foreach (var customer in customers)
            {
                db.Customers.Add(customer);
            }

            db.SaveChanges();
        }
示例#3
0
        private static void BuildDatabase()
        {
            SpatialDataContext db = new SpatialDataContext();

            if (db.Customers.Any())
            {
                return;
            }

            string[] names = { "Mercury", "Venus", "Earth", "Mars", "Jupiter", "Saturn", "Uranus", "Neptune" };

            string[] lineStrings =
            {
                "LINESTRING(1 1, 3 3)",
                "LINESTRING(1 1, 3 3, 2 4, 2 0)",
                "LINESTRING(1 1, 3 3, 2 4, 2 0, 1 1)",
                "LINESTRING(1 1, 2 4, 3 9)",
                "LINESTRING(1 1 NULL 0, 2 4 NULL 12.3, 3 9 NULL 24.5)",
                "LINESTRING(2 1, 2 3)",
                "LINESTRING(3 2, 4 6)"
            };
            var customers = Enumerable.Range(1, 7).Select(e => new Customer
            {
                Id           = e,
                Name         = names[e - 1],
                DbLocation   = DbGeography.FromText(String.Format("POINT({0} {1} {2} {3})", e, e, e, e)),
                DbLineString = DbGeography.FromText(lineStrings[e - 1])
            });

            foreach (var customer in customers)
            {
                db.Customers.Add(customer);
            }

            db.SaveChanges();
        }