public IActionResult CreatePointOfInterest(int cityId, [FromBody] PointOfInterestCreationDTO pointofInterest)
        {
            if (pointofInterest == null)
            {
                return(BadRequest());
            }
            if (!ModelState.IsValid)
            {
                return(NotFound());
            }
            var city = CitiesDataStore.current.Cities.FirstOrDefault(c => c.Id == cityId);

            if (city == null)
            {
                return(NotFound());
            }
            var MaxPoindOfInterestId = CitiesDataStore.current.Cities.SelectMany(c => c.pointofInterest).Max(p => p.Id);

            var finalPointOfDTO = new PointOfInterestDTO()
            {
                Id          = ++MaxPoindOfInterestId,
                Name        = pointofInterest.Name,
                Description = pointofInterest.Description
            };

            city.pointofInterest.Add(finalPointOfDTO);
            return(CreatedAtRoute("getPoindOfInterest", new { cityId = cityId, id = finalPointOfDTO.Id }));
            //return Ok();
        }
Exemplo n.º 2
0
        public IActionResult CreatePOI(int cityId, [FromBody] PointOfInterestCreationDTO poi)
        {
            if (poi == null)
            {
                return(BadRequest());
            }

            if (!_cityRepository.CityExists(cityId))
            {
                return(NotFound());
            }

            if (poi.Description == poi.Name)
            {
                ModelState.AddModelError("Description", "Name and Description should be different");
            }

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var city = CitiesDataStore.Current.cities.FirstOrDefault(x => x.Id == cityId);

            PointOfInterestDTO poiObj = new PointOfInterestDTO()
            {
                Id          = city.NumberOfPointOfInterst + 1, //temporary
                Name        = poi.Name,
                Description = poi.Description
            };

            city.POI.Add(poiObj);

            return(CreatedAtRoute("GetPoiRoute", new { cityId = cityId, pId = poiObj.Id }, poiObj));
        }
Exemplo n.º 3
0
        partial void Merge(PointOfInterest entity, PointOfInterestDTO dto, object state)
        {
            entity.PointOfInterestId = dto.PointOfInterestId;
            entity.Name  = dto.Name;
            entity.Floor = dto.Floor;
            var coordinates = dto.Coordinates;

            if (coordinates != null && coordinates.Length == 2)
            {
                entity.Coordinates = this.vector2DConverter.Convert(coordinates, dto);
            }
        }
        public RouteToPointOfInterestDTO StartUserTour(int userID, int tourID, double currentLatitude, double currentLongitude)
        {
            VerifyNoTourIsStarted(userID);
            _userTourRepo.StartUserTour(userID, tourID);
            UserTour activeTour = _userTourRepo.GetActiveTour(userID);
            POI      nextPOI    = _userPOIRepo.GetNextPOI(activeTour.Id);
            IEnumerable <CoordinateDTO> route = _geoLocationService.GetRoute(currentLatitude, currentLongitude,
                                                                             nextPOI.Coordinates.Latitude.Value,
                                                                             nextPOI.Coordinates.Longitude.Value);

            return(new RouteToPointOfInterestDTO {
                NextPOI = PointOfInterestDTO.Create().Compile()(nextPOI), RouteToNextPOI = route
            });
        }
        public IActionResult GetPointOfInterest(int cityId, int pointOfInterestId)
        {
            CityDTO city = CitiesDataStore.Current.Cities
                           .FirstOrDefault(x => x.Id == cityId);

            PointOfInterestDTO pointOfInterest = city.PointsOfInterest
                                                 .FirstOrDefault(x => x.Id == pointOfInterestId);

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

            return(Ok(pointOfInterest));
        }
Exemplo n.º 6
0
        public IActionResult CreatePointOfInterest(int cityId,
                                                   [FromBody] PointsOfInterestForCreationDTO pointsOfInterest)
        {
            //ERROR CHECKING...
            // null poi
            if (pointsOfInterest == null)
            {
                return(BadRequest("Point of Interest not defined."));
            }

            // Adding a customer error and customized validation checking
            if (pointsOfInterest.Description == pointsOfInterest.Name)
            {
                ModelState.AddModelError("Description", "The provided description cannot be the same as the name.");
            }

            // ModelState is a dictionary containing various data
            // If model validation fails, isvalid will be false.
            if (!ModelState.IsValid)
            {
                // will pass along any error messages in modelstate to the response
                return(BadRequest(ModelState));
            }

            // city not found
            var city = CitiesDataStore.Current.Cities.FirstOrDefault(c => c.Id == cityId);

            if (city == null)
            {
                return(NotFound("City not found."));
            }

            // need to get next poi id...
            var maxPoiId = CitiesDataStore.Current.Cities.SelectMany(c =>
                                                                     c.PointsOfInterest).Max(p => p.Id);

            var finalPoi = new PointOfInterestDTO()
            {
                Id          = ++maxPoiId,
                Name        = pointsOfInterest.Name,
                Description = pointsOfInterest.Description
            };

            city.PointsOfInterest.Add(finalPoi);
            // this is the method to return a '201 created' response with the object in the response body
            return(CreatedAtRoute("GetPointOfInterest",
                                  new { cityId, id = finalPoi.Id }, finalPoi));
        }
        public IActionResult CreatePointOfInterest(int cityId, [FromBody] PointOfInterestForCreationDto pointOfInterest)
        {
            if (pointOfInterest == null)
            {
                return(BadRequest());
            }

            if (pointOfInterest.Description == pointOfInterest.Name)
            {
                ModelState.AddModelError("Description", "The provided description should be different from the name.");
            }

            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            var city = CitiesDataStore.Current.Cities.FirstOrDefault(c => c.Id == cityId);

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

            var maxPointOfInterestId = CitiesDataStore.Current.Cities.SelectMany(
                c => c.PointsOfInterest).Max(p => p.Id);

            var finalPointOfInterest = new PointOfInterestDTO()
            {
                Id          = ++maxPointOfInterestId,
                Name        = pointOfInterest.Name,
                Description = pointOfInterest.Description
            };

            city.PointsOfInterest.Add(finalPointOfInterest);

            return(CreatedAtRoute("GetPointOfInterest", new
            {
                cityId = cityId,
                id = finalPointOfInterest.Id,
                finalPointOfInterest
            }
                                  ));
        }
        public IActionResult CreatePointOfInterest(int cityID,
                                                   [FromBody] PointOfInterestCreationDTO pointOfInterest)
        {
            if (pointOfInterest == null)
            {
                return(BadRequest());
            }

            if (pointOfInterest.Description == pointOfInterest.Name)
            {
                ModelState.AddModelError("Description", "The provided description cannot be the same as the name");
            }
            //TODO: Check FluentValidation

            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            var city = CitiesDataStore.Current.Cities.Where(c => c.ID == cityID).FirstOrDefault();

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

            var maxPointOfInterestID = CitiesDataStore.Current.Cities.SelectMany(c => c.PointsOfInterest).Max(p => p.ID);

            var finalPointOfInterest = new PointOfInterestDTO()
            {
                ID          = maxPointOfInterestID + 1,
                Name        = pointOfInterest.Name,
                Description = pointOfInterest.Description
            };

            city.PointsOfInterest.Add(finalPointOfInterest);

            return(CreatedAtRoute("GetPointOfInterest", new
            {
                cityID,
                poiID = finalPointOfInterest.ID
            }, finalPointOfInterest));
        }
Exemplo n.º 9
0
        public IActionResult CreatePointOfInterest(int cityId,
                                                   [FromBody] PointOfInterestForCreationDTO poiData)
        {
            if (poiData.Description == poiData.Name)
            {
                ModelState.AddModelError(
                    "Description",
                    "The provided description should not match the name."
                    );
            }


            // handled by ApiController attribute (magic)
            // if (poiData == null)
            // {
            //   return BadRequest();
            // }
            // handled by ApiController attribute (magic)
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            var city = CityDataStore.Current.Cities
                       .FirstOrDefault(c => c.Id == cityId);

            if (city == null)
            {
                return(NotFound());
            }
            var maxPoiId = CityDataStore.Current.Cities
                           .SelectMany(c => c.PointsOfInterest).Max(p => p.Id);

            var nextPoi = new PointOfInterestDTO()
            {
                Id          = ++maxPoiId,
                Name        = poiData.Name,
                Description = poiData.Description
            };

            city.PointsOfInterest.Add(nextPoi);
            return(CreatedAtRoute("GetPointOfInterest",
                                  new { cityId, id = nextPoi.Id }, nextPoi));
        }
Exemplo n.º 10
0
        public IActionResult CreatePointOfInterest(int cityId, [FromBody] PointOfInterestDTO pointOfInterest)
        {
            var city = CityDataStore.Current.Cities.FirstOrDefault(c => c.Id == cityId);

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

            var lastID             = CityDataStore.Current.Cities.SelectMany(c => c.PointOfInterests).Max(c => c.Id);
            var newPointOfInterest = new PointOfInterestDTO
            {
                Id          = ++lastID,
                Name        = pointOfInterest.Name,
                Description = pointOfInterest.Description
            };

            city.PointOfInterests.Add(newPointOfInterest);

            return(CreatedAtRoute("GetPointOfInterest",
                                  new { cityId = cityId, id = newPointOfInterest.Id },
                                  newPointOfInterest));
        }
Exemplo n.º 11
0
        public PointOfInterestDTO GetNextPOI(int userID)
        {
            var nextPOI = GetNextPOIInternal(userID);

            return(PointOfInterestDTO.Create().Compile()(nextPOI));
        }
Exemplo n.º 12
0
 public IEnumerable <PointOfInterestDTO> GetPOIsByTour(int tourID)
 {
     return(_poiRepo.GetPOIsByTour(tourID).Select(PointOfInterestDTO.Create()));
 }
Exemplo n.º 13
0
 public IEnumerable <PointOfInterestDTO> GetPOIs()
 {
     return(_poiRepo.GetPOIs().Select(PointOfInterestDTO.Create()));
 }