Example #1
0
        public async Task <IActionResult> AddPolyGon([FromBody] PolygonApiModel input)
        {
            try
            {
                if (input is null)
                {
                    return(BadRequest());
                }
                if (!ModelState.IsValid)
                {
                    return(BadRequest());
                }
                var shape = await _polygonMapSupervisor.GetShapeByIdAsync(input.ShapeID);

                if (shape is null)
                {
                    return(NotFound());
                }
                var polygon = await _polygonMapSupervisor.AddPolygonAsync(input);

                await _polygonMapSupervisor.UpdateShapeAsync(shape);

                return(Ok(polygon));
            }
            catch (Exception ex)
            {
                return(StatusCode(500, ex.Message));
            }
        }
Example #2
0
        public async Task <ActionResult <PolygonApiModel> > CalPointsWithNewCenterAsync(int id, string RegonName, float newCenterlat, float newCenterLng)
        {
            try
            {
                var Shape = await _polygonMapSupervisor.GetShapeByIdAsync(id);

                if (Shape == null)
                {
                    return(NotFound());
                }

                Shape.Points = DisplacementPoint(Shape, newCenterlat - Shape.FixedLatitude,
                                                 newCenterLng - Shape.FixedLongitude);
                var newPolygonApiModel = new PolygonApiModel()
                {
                    ShapeID       = Shape.ShapeID,
                    Name          = RegonName,
                    RealLatitude  = newCenterlat,
                    RealLongitude = newCenterLng,
                    Points        = JsonConvert.SerializeObject(Shape.Points, Formatting.Indented)
                };
                var polygon = await _polygonMapSupervisor.AddPolygonAsync(newPolygonApiModel);

                return(Ok(polygon));
            }
            catch (Exception ex)
            {
                return(StatusCode(500, ex));
            }
        }
Example #3
0
        public async Task <ActionResult <PolygonApiModel> > CalPointsWithNewCenterAsync(int id, string RegonName, float newCenterlat, float newCenterLng)
        {
            try
            {
                var Shape = await _polygonMapSupervisor.GetShapeByIdAsync(id);

                if (Shape == null)
                {
                    return(NotFound());
                }
                var newPolygonApiModel = CalDisplacementPoints(Shape, RegonName, newCenterlat, newCenterLng);
                var polygon            = await _polygonMapSupervisor.AddPolygonAsync(newPolygonApiModel);

                return(Ok(polygon));
            }
            catch (Exception ex)
            {
                return(StatusCode(500, ex));
            }
        }