public IActionResult CreatePointOfInterest(int cityId, [FromBody] PointOfInterestForCreateDto pointOfInterest)
        {
            if (pointOfInterest == null)
            {
                return(BadRequest());
            }

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

            var city = CitiDataStore.Current.Cities.FirstOrDefault(x => x.Id == cityId);

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

            var maxPointPfInterestId = CitiDataStore.Current.Cities.SelectMany(c => c.PointsOfInterests).Max(p => p.Id);
            var finalPointOfInterest = new PointsOfInterestDto()
            {
                Id          = maxPointPfInterestId,
                Name        = pointOfInterest.Name,
                Description = pointOfInterest.Description
            };

            city.PointsOfInterests.Add(finalPointOfInterest);

            return(CreatedAtRoute("GetPointOfInterest",
                                  new { cityId = cityId, id = finalPointOfInterest.Id }, finalPointOfInterest));
        }
예제 #2
0
        public IActionResult CreatePointOfInterest(int cityId, [FromBody] PointOfInterestForCreationDto pointOfInterest)
        {
            if (pointOfInterest == null)
            {
                return(BadRequest());
            }
            if (pointOfInterest.Name == pointOfInterest.Description)
            {
                ModelState.AddModelError("Description", "Please provide different description than name.");
            }
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            var city = CitiesDataStore.Current.Cities.FirstOrDefault(x => x.Id == cityId);

            if (city == null)
            {
                return(NotFound());
            }
            var lastPointOfInterestId = CitiesDataStore.Current.Cities.SelectMany(c => c.PointsOfInterest).Max(p => p.Id);
            var pointOfInterestToAdd  = new PointsOfInterestDto
            {
                Id          = ++lastPointOfInterestId,
                Name        = pointOfInterest.Name,
                Description = pointOfInterest.Description
            };

            city.PointsOfInterest.Add(pointOfInterestToAdd);

            return(CreatedAtRoute("GetPointOfInterestOfACity", new { cityId = cityId, id = pointOfInterestToAdd.Id }, pointOfInterestToAdd));
        }
        public IActionResult CreatePointsOfInterestDto(int cityid, [FromBody] PointsOfInterestCreationDto pointofinterest)
        {
            if (pointofinterest == null)
            {
                return(BadRequest()); // 400
            }
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }
            var city = CitiesDataStore.current.Cities.FirstOrDefault(c => c.Id == cityid);

            if (city == null)
            {
                return(NotFound());
            }
            var maxPointofInterest    = CitiesDataStore.current.Cities.SelectMany(c => c.Pointsofinterest).Max(p => p.Id);
            var finalpointsofinterest = new PointsOfInterestDto()
            {
                Id          = ++maxPointofInterest,
                Name        = pointofinterest.Name,
                Description = pointofinterest.Description
            };

            city.Pointsofinterest.Add(finalpointsofinterest);
            return(CreatedAtRoute("GetPointsOfInterest", new { cityId = cityid, id = finalpointsofinterest.Id }, finalpointsofinterest));
        }
예제 #4
0
        public IActionResult UpdatePointsOfInterest(int cityId, int pointOfInterestId,
                                                    [FromBody] PointsOfInterestForUpdateDto pointOfInterest)
        {
            if (pointOfInterest == null)
            {
                return(BadRequest());
            }

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

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

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

            PointsOfInterestDto currentPointOfInterest =
                city.PointsOfInterest.FirstOrDefault(i => i.Id == pointOfInterestId);

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

            currentPointOfInterest.Name        = pointOfInterest.Name;
            currentPointOfInterest.Description = pointOfInterest.Description;

            return(CreatedAtRoute("GetPointOfInterest",
                                  new { cityId = cityId, POIId = currentPointOfInterest.Id },
                                  currentPointOfInterest));
        }
        public IActionResult CreatePointOfInterest(int cityId, [FromBody] PointsOfInterestForCreationDto pointOfInterest)
        {
            if (pointOfInterest == null)
            {
                return(BadRequest(ModelState));
            }

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

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

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            //mock thr response, as is in memory data

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

            //create the resource
            PointsOfInterestDto newPointOfInterest = new PointsOfInterestDto()
            {
                Id          = maxPointOfInterestId++,
                Description = pointOfInterest.Description,
                Name        = pointOfInterest.Name
            };

            return(CreatedAtRoute("GetPointOfInterest", new { cityId = cityId, pointOfInterest = newPointOfInterest }));
        }
예제 #6
0
        public IActionResult PatchPointsOfInterest(int cityId, int pointOfInterestId,
                                                   [FromBody] JsonPatchDocument <PointsOfInterestForUpdateDto> pointOfInterestPatch)
        {
            if (pointOfInterestPatch == null)
            {
                return(BadRequest());
            }

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

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

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

            PointsOfInterestDto currentPointOfInterest =
                city.PointsOfInterest.FirstOrDefault(i => i.Id == pointOfInterestId);

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

            PointsOfInterestForUpdateDto newPointOfInterest =
                new PointsOfInterestForUpdateDto()
            {
                Name        = currentPointOfInterest.Name,
                Description = currentPointOfInterest.Description
            };

            pointOfInterestPatch.ApplyTo(newPointOfInterest, ModelState);

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

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

            currentPointOfInterest.Name        = newPointOfInterest.Name;
            currentPointOfInterest.Description = newPointOfInterest.Description;

            return(CreatedAtRoute("GetPointOfInterest",
                                  new { cityId = cityId, POIId = currentPointOfInterest.Id },
                                  newPointOfInterest));
        }
예제 #7
0
        public IActionResult CreatePointInteres(int cityId,
                                                [FromBody] PointsOfInterestForCreationDto pointOfInteres)
        {
            if (pointOfInteres == null)
            {
                return(BadRequest());
            }



            if (pointOfInteres.Description == pointOfInteres.Name)
            {
                ModelState.TryAddModelError("Description", "El provedor es diferente a la descripciòn");
            }


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



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

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



            var maxPointOfInterestId = CitiesDataStore.Curent.Cities.SelectMany(
                c => c.PointOfInterest).Max(p => p.Id);


            var finalPointOfInteres = new PointsOfInterestDto()
            {
                Id          = ++maxPointOfInterestId,
                Name        = pointOfInteres.Name,
                Description = pointOfInteres.Description
            };

            city.PointOfInterest.Add(finalPointOfInteres);


            return(CreatedAtRoute("GetPointOfInterest", new
            {
                cityId = cityId,
                id = finalPointOfInteres.Id
            }, finalPointOfInteres));
        }
예제 #8
0
        public IActionResult GetPOIById(int cityId, int POIId)
        {
            CityDto city = CitiesDataStore.Current.Cities.FirstOrDefault(c => c.Id == cityId);

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

            PointsOfInterestDto POI = city.PointsOfInterest.FirstOrDefault(p => p.Id == POIId);

            if (POI == null)
            {
                return(StatusCode(401, null));
            }

            return(Ok(POI));
        }
        public void GetPOIList_CityExist_ReturnPOIList()
        {
            //Arrange
            var city = CityPoiItemBuilder.GenerateCity();

            FakeCityRepository.GetPointsOfInterestForCity(city.Id).Returns(city.PointsOfInterest);
            FakeCityRepository.CityExists(city.Id).Returns(true);

            var poiDto = new PointsOfInterestDto
            {
                PoiList = city.PointsOfInterest
            };

            //Action
            var result = PoiController.GetPointsOfInterestForCity(city.Id);


            // Assert
            result.Should().BeOfType <ObjectResult>().Which.Value.ShouldBeEquivalentTo(poiDto);
        }
        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(ModelState));
            }

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

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

            //demo purposes - to be improved
            var maxPointOfInterestId = CitiesDataStore.Current.Cities.SelectMany(
                c => c.PointsOfInterest).Max(p => p.Id);

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

            city.PointsOfInterest.Add(finalPointOfInterest);

            return(CreatedAtRoute("GetPointOfInterest", new
                                  { cityId = cityID, id = finalPointOfInterest.Id }, finalPointOfInterest));
        }
예제 #11
0
        public IActionResult DeletePointsOfInterest(int cityId, int pointOfInterestId)
        {
            CityDto city = CitiesDataStore.Current.Cities.FirstOrDefault(c => c.Id == cityId);

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

            PointsOfInterestDto currentPointOfInterest =
                city.PointsOfInterest.FirstOrDefault(i => i.Id == pointOfInterestId);

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

            city.PointsOfInterest.Remove(currentPointOfInterest);

            // set email to tell customer that POI removed
            _mailService.Sent("***subject to send***", "*body*");
            return(NoContent());
        }
예제 #12
0
        public IActionResult CreatePointOfInterest(int cityId,
                                                   [FromBody] PointsOfInterestForCreationDto pointOfInterest)
        {
            if (pointOfInterest == null)
            {
                return(BadRequest());
            }

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

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

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

            int pointOfInterestId = CitiesDataStore.Current.Cities.SelectMany(
                c => c.PointsOfInterest).Max(p => p.Id);

            PointsOfInterestDto newPointOfInterest = new PointsOfInterestDto()
            {
                Id          = pointOfInterestId + 1,
                Name        = pointOfInterest.Name,
                Description = pointOfInterest.Description
            };

            city.PointsOfInterest.Add(newPointOfInterest);

            return(CreatedAtRoute("GetPointOfInterest",
                                  new { cityId = cityId, POIId = newPointOfInterest.Id },
                                  newPointOfInterest));
        }
예제 #13
0
        public IActionResult CreatePointOfInterest(int cityId, PointofInterestForCreationDto pointofInterestForCreation)
        {
            var city = CitiesDataStore.Current.Cities.FirstOrDefault(c => c.Id == cityId);

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

            var maxPointOfInterestId = city.PointsOfInterests.Max(p => p.Id);

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

            city.PointsOfInterests.Add(finalPointOfInterest);

            return(CreatedAtRoute("GetPointOfInterest",
                                  new { cityId, id = finalPointOfInterest.Id },
                                  finalPointOfInterest));
        }