Example #1
0
        public JsonResult CreatePolygon(string[] lats, string[] lngs)
        {
            var status = 0;

            if (lats.Length > 0 && lngs.Length > 0 && lats.Length == lngs.Length)
            {
                var polygon = new Polygon {
                    Name = "Polygon created:" + DateTime.Now.ToShortTimeString()
                };
                dataManager.GEO.PolygonSave(polygon);
                for (int i = 0; i < lats.Length; i++)
                {
                    var latlng = new LatLng
                    {
                        Latitude  = lats[i],
                        Longitude = lngs[i]
                    };
                    dataManager.GEO.LatLngSave(latlng);
                    var plRelation = new PolygonLatLngRelation
                    {
                        PolygonId = polygon.Id,
                        LatLngId  = latlng.Id
                    };
                    dataManager.GEO.PolygonLatLngRelationSave(plRelation);
                }
                return(Json(polygon, JsonRequestBehavior.DenyGet));
            }
            return(Json(status, JsonRequestBehavior.DenyGet));
        }
Example #2
0
        public JsonResult EditPolygon(int Id, string[] lats, string[] lngs)
        {
            string status = "";

            try
            {
                if (lats.Length > 0 && lngs.Length > 0 && lats.Length == lngs.Length)
                {
                    var polygon = dataManager.GEO.PolygonGet(Id);
                    RemoveLatLngsByPolygonId(polygon.Id);
                    for (int i = 0; i < lats.Length; i++)
                    {
                        var latlng = new LatLng
                        {
                            Latitude  = lats[i],
                            Longitude = lngs[i]
                        };
                        dataManager.GEO.LatLngSave(latlng);
                        var plRelation = new PolygonLatLngRelation
                        {
                            PolygonId = polygon.Id,
                            LatLngId  = latlng.Id
                        };
                        dataManager.GEO.PolygonLatLngRelationSave(plRelation);
                        status = "1";
                    }
                }
            }
            catch (Exception e)
            {
                status = e.TargetSite.Name + ": " + e.Message;
            }
            return(Json(status, JsonRequestBehavior.DenyGet));
        }
Example #3
0
 public void PolygonLatLngRelationSave(PolygonLatLngRelation obj)
 {
     if (obj.Id == 0)
     {
         context.Entry(obj).State = System.Data.Entity.EntityState.Added;
     }
     else
     {
         context.Entry(obj).State = System.Data.Entity.EntityState.Modified;
     }
     context.SaveChanges();
 }