示例#1
0
        public RestApiResult ImportPolygons(JObject json)
        {
            if (json == null)
            {
                return(new RestApiResult {
                    StatusCode = HttpStatusCode.BadRequest
                });
            }

            var polygonListOld = ClarityDB.Instance.Polygons.Where(x => x.Name != "" || 1 == 1);

            foreach (Polygon polygon in polygonListOld)
            {
                ClarityDB.Instance.Polygons.Remove(polygon);
            }

            var polygons = json.Value <JArray>("polygons");

            List <Polygon> polygonList = new List <Polygon>();

            foreach (var polygon in polygons)
            {
                Polygon newPolygon = new Polygon();
                newPolygon.ApplyJson(polygon);
                ClarityDB.Instance.Polygons.Add(newPolygon);
                polygonList.Add(newPolygon);
            }

            ClarityDB.Instance.SaveChanges();
            return(new RestApiResult {
                StatusCode = HttpStatusCode.OK, Json = BuildJsonArray(polygonList)
            });
        }