Ejemplo n.º 1
0
        public APISuccessResponse AddIrregularShape([FromBody] IrregularShapeArea irregularShape)
        {
            try
            {
                if (irregularShape.Coordinates.Count < 3)
                {
                    HttpContext.Response.StatusCode = BadRequest().StatusCode;

                    return(new APISuccessResponse("The shape should have at least three coordinates"));
                }

                bool isSuccess = _GPSService.AddIrrigularShape(irregularShape);

                if (isSuccess)
                {
                    HttpContext.Response.StatusCode = Ok().StatusCode;

                    return(new APISuccessResponse());
                }
                else
                {
                    return(new APISuccessResponse("Error in adding rectangle to database"));
                }
            }
            catch (Exception ex)
            {
                _logger.LogWarning("An error occurs, Exception: {Exception Message}", ex.Message);
                HttpContext.Response.StatusCode = 500;

                return(new APISuccessResponse("Internal Server Error"));
            }
        }
Ejemplo n.º 2
0
        public static Shape ToShape(IrregularShapeArea irregularShape)
        {
            var shape = new Shape()
            {
                TypeId = irregularShape.TypeId,
                Name   = irregularShape.Name
            };

            return(shape);
        }
Ejemplo n.º 3
0
        public static IEnumerable <IrregularShape> ToIrregularShape(IrregularShapeArea irregularShapeArea)
        {
            var irregularShape = irregularShapeArea.Coordinates.Select(coordinate =>
                                                                       new IrregularShape()
            {
                Longitude = coordinate.Longitude,
                Latitude  = coordinate.Latitude
            });

            return(irregularShape);
        }
Ejemplo n.º 4
0
        public bool AddIrrigularShape(IrregularShapeArea irregularShapeArea)
        {
            var irregularShape = ObjectMapper.ToIrregularShape(irregularShapeArea);
            var shape          = ObjectMapper.ToShape(irregularShapeArea);

            var shapeResult = _repository.InsertShape(shape);

            foreach (var ishape in irregularShape)
            {
                ishape.ShapeId = shapeResult.Id;
            }

            var irregularShapeResult = _repository.InsertIrregularShape(irregularShape);

            if (shapeResult == null || irregularShapeResult == null)
            {
                return(false);
            }

            return(true);
        }