Exemple #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));
            }
        }
Exemple #2
0
        public async Task <IActionResult> 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));
            }
        }
        public async Task <PolygonApiModel> AddPolygonAsync(PolygonApiModel newPolygonApiModel)
        {
            var polygon = _mapper.Map <Polygon>(newPolygonApiModel);

            polygon = await _polygonRepository.AddAsync(polygon);

            newPolygonApiModel.PolygonID = polygon.PolygonID;
            return(newPolygonApiModel);
        }
Exemple #4
0
        private PolygonApiModel CalDisplacementPoints(ShapeApiModel shape, string RegonName, float newCenterlat, float newCenterLng)
        {
            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)
            };

            return(newPolygonApiModel);
        }
Exemple #5
0
        private void CreatePDFFile(PolygonApiModel polygon, string folderPath)
        {
            PdfContentByte cb     = null;
            Document       doc    = null;
            var            points = JsonConvert.DeserializeObject <List <Point> >(polygon.Points);

            points = ConvertCordinations(points);
            if (!Directory.Exists(folderPath))
            {
                Directory.CreateDirectory(folderPath);
            }

            try
            {
                doc = new Document();
                var writer = PdfWriter.GetInstance(doc, new FileStream(folderPath + "/" + polygon.Name + "-" + polygon.PolygonID + ".pdf", FileMode.Create));
                doc.Open();

                cb = writer.DirectContent;
                int index = 0;
                foreach (var point in points)
                {
                    if (doc.PageSize.Height > point.Latitude && doc.PageSize.Width > point.Longitude)
                    {
                        if (index == 0)
                        {
                            cb.MoveTo(point.Longitude, doc.PageSize.Height - point.Latitude);
                        }
                        else
                        {
                            cb.LineTo(point.Longitude, doc.PageSize.Height - point.Latitude);
                        }
                        index++;
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                cb.ClosePath();
                cb.Stroke();
                doc.Close();
            }
        }
Exemple #6
0
        public async Task <IActionResult> UpdatePolygonByIdAsync(int id, [FromBody] PolygonApiModel input)
        {
            try
            {
                if (input == null)
                {
                    return(BadRequest());
                }
                if (await _polygonMapSupervisor.GetPolygonByIdAsync(id) is null)
                {
                    return(NotFound());
                }
                if (await _polygonMapSupervisor.UpdatePolygonAsync(input))
                {
                    return(Ok(input));
                }

                return(StatusCode(500));
            }
            catch (Exception ex)
            {
                return(StatusCode(500, ex));
            }
        }
Exemple #7
0
        public async Task <ActionResult <PolygonApiModel> > UpdatePolygonByIdAsync(int id, [FromBody] PolygonApiModel input)
        {
            try
            {
                if (input == null)
                {
                    return(BadRequest());
                }
                if (await _polygonMapSupervisor.GetPolygonByIdAsync(id) == null)
                {
                    return(NotFound());
                }
                var shape = await _polygonMapSupervisor.GetShapeByIdAsync(input.ShapeID);

                if (shape == null)
                {
                    return(NotFound());
                }
                var newPolygonApiModel = CalDisplacementPoints(shape, input.Name, input.RealLatitude, input.RealLongitude);
                newPolygonApiModel.PolygonID = id;
                if (await _polygonMapSupervisor.UpdatePolygonAsync(newPolygonApiModel))
                {
                    return(Ok(newPolygonApiModel));
                }

                return(StatusCode(500));
            }
            catch (Exception ex)
            {
                return(StatusCode(500, ex));
            }
        }
        public async Task <bool> UpdatePolygonAsync(PolygonApiModel polygonApiModel)
        {
            var polygon = _mapper.Map <Polygon>(polygonApiModel);

            return(await _polygonRepository.UpdateAsync(polygon));
        }