Beispiel #1
0
        public async Task <Result <ListResult <RoutePoint> > > GetPoints(PagingRequestModel model, string routes)
        {
            try
            {
                var pager = new QueryPager();

                ApplyPaging(model, pager);

                var results = await _pointRepository.Search(pager);

                var listResult = new ListResult <RoutePoint>()
                {
                    Count   = results.Count,
                    HasNext = results.HasNext,
                    Results = results.Results.Select(r => new RoutePoint()
                    {
                        Id    = r.RouteInfo.ID,
                        Point = GeoPointConverter.GetPoint(r.Point)
                    }).ToList()
                };

                return(new Result <ListResult <RoutePoint> >(listResult));
            }
            catch (Exception ex)
            {
                ErrorResult error = GenerateError(ex);
                return(new Result <ListResult <RoutePoint> >(error));
            }
        }
        public void ConvertPoint()
        {
            string pointString = "POINT(431.33393335342407 3.82005181729661)";
            var    point       = GeoPointConverter.GetPoint(pointString);

            Assert.Equal(point.Lat.Value, 431.33M, 2);
            Assert.Equal(point.Lng.Value, 3.82M, 2);
        }
Beispiel #3
0
        public async Task <Result <RouteDetailsViewModel> > GetRouteById(IdModel model)
        {
            try
            {
                var query = new SearchQuery <RouteInfoEntity>();

                RouteInfoEntity result = await _routeRepository.GetSingleWithDependencies(model.Id);

                if (result == null)
                {
                    ErrorResult error = GenerateError("Route not found", "Id", "Invalid identifier", ErrorStatus.ObjectNotFound);
                    return(new Result <RouteDetailsViewModel>(error));
                }

                var viewModel = new RouteDetailsViewModel()
                {
                    Difficulty = result.Difficulty,
                    Id         = result.ID,
                    Name       = result.Name,
                    UserId     = result.UserId,
                    User       = new UserListItemModel()
                    {
                        Email       = result.User.Email,
                        Id          = result.User.ID,
                        Name        = result.User.Name,
                        RoutesCount = result.User.Routes.Count
                    },
                    Geometry = new RouteGeometry()
                    {
                        Id     = result.Geometry.ID,
                        Points = GeoPointConverter.GetPoints(result.Geometry.Line),
                    },
                    MainPoint = GeoPointConverter.GetPoint(result.Point.Point)
                };

                return(new Result <RouteDetailsViewModel>(viewModel));
            }
            catch (Exception ex)
            {
                ErrorResult error = GenerateError(ex);
                return(new Result <RouteDetailsViewModel>(error));
            }
        }