コード例 #1
0
        public ActionResult SaveOverlays(string name, Guid?parentId, string points, string color, string xy, Guid?childrenId)
        {
            Guid       mainId           = childrenId ?? parentId ?? Guid.Empty;
            MapOverlay parentMapOverlay = service.Get(mainId);

            if (parentMapOverlay == null)
            {
                throw new NopException("父级遮盖物不存在");
            }

            MapOverlay entity = new MapOverlay()
            {
                Name = name, ParentId = parentMapOverlay.Id, Level = parentMapOverlay.Level + 1, Color = color
            };

            if (!string.IsNullOrEmpty(xy))
            {
                entity.Longitude = xy.Split(',')[0];
                entity.Latitude  = xy.Split(',')[1];
            }
            service.Add(entity);

            if (points != null)
            {
                var coordinates   = points.Split(new[] { '|' }, StringSplitOptions.RemoveEmptyEntries);
                var pointsEntitys = new List <MapOverlayPoints>();
                foreach (var coordinate in coordinates)
                {
                    var tmp   = coordinate.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
                    var point = new MapOverlayPoints()
                    {
                        Longitude = tmp[0], Latitude = tmp[1], MapOverlayId = entity.Id
                    };
                    pointsEntitys.Add(point);
                }
                service.BatchAdd(pointsEntitys);
            }

            return(Content("1"));
        }
コード例 #2
0
        public ActionResult UpdateOverlays(string name, string points, string color, string xy, Guid id, bool isUpdatePoints)
        {
            MapOverlay mapOverlay = service.Get(id);

            if (mapOverlay == null)
            {
                throw new NopException("遮盖物不存在");
            }
            mapOverlay.Name  = name;
            mapOverlay.Color = color;
            if (!string.IsNullOrEmpty(xy))
            {
                mapOverlay.Longitude = xy.Split(',')[0];
                mapOverlay.Latitude  = xy.Split(',')[1];
            }
            service.Modify(mapOverlay);

            if (isUpdatePoints)
            {
                if (points != null)
                {
                    var coordinates   = points.Split(new[] { '|' }, StringSplitOptions.RemoveEmptyEntries);
                    var pointsEntitys = new List <MapOverlayPoints>();
                    foreach (var coordinate in coordinates)
                    {
                        var tmp   = coordinate.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
                        var point = new MapOverlayPoints()
                        {
                            Longitude = tmp[0], Latitude = tmp[1], MapOverlayId = mapOverlay.Id
                        };
                        pointsEntitys.Add(point);
                    }
                    service.DeleteMapOverlayPoints(id);
                    service.BatchAdd(pointsEntitys);
                }
            }


            return(Content("1"));
        }