public IActionResult FullyUpdate(int cityId, int id, [FromBody] CreateUpdateCityOrPointsOfInterestVM createUpdatePointsOfInterest)
        {
            if (createUpdatePointsOfInterest == null)
            {
                return(BadRequest());
            }
            if (createUpdatePointsOfInterest.Name == createUpdatePointsOfInterest.Description)
            {
                ModelState.AddModelError("Description", "Name should be different from Description");
            }
            //check validation
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            if (!cityRepository.CityExist(cityId))
            {
                return(NotFound());
            }
            var pointOfInterest = cityRepository.GetPointsOfInterest(cityId, id);

            if (pointOfInterest == null)
            {
                return(NotFound());
            }
            Mapper.Map(createUpdatePointsOfInterest, pointOfInterest);
            if (!cityRepository.Save())
            {
                return(StatusCode(500, "proplem happend whern creating object"));
            }
            return(NoContent());
        }
        public IActionResult Create(int cityId, [FromBody] CreateUpdateCityOrPointsOfInterestVM createPointsOfInterest)
        {
            if (createPointsOfInterest == null)
            {
                return(BadRequest());
            }
            if (createPointsOfInterest.Name == createPointsOfInterest.Description)
            {
                ModelState.AddModelError("Description", "Name should be different from Description");
            }
            //check validation
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            if (!cityRepository.CityExist(cityId))
            {
                return(NotFound());
            }
            var point = Mapper.Map <Entity.PointsOfInterest>(createPointsOfInterest);

            cityRepository.CreatePointOfInterest(cityId, point);
            if (!cityRepository.Save())
            {
                return(StatusCode(500, "proplem happend whern creating object"));
            }
            var created = Mapper.Map <PointsOfInterestVM>(point);

            return(CreatedAtRoute("pointOfInterest", new { cityId = cityId, id = created.Id }, created));
        }
示例#3
0
        public IActionResult Create([FromBody] CreateUpdateCityOrPointsOfInterestVM createCity)
        {
            if (createCity == null)
            {
                return(BadRequest());
            }
            if (createCity.Name == createCity.Description)
            {
                ModelState.AddModelError("Description", "Name should be different from Description");
            }
            //check validation
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            var city = Mapper.Map <Entity.City>(createCity);

            cityRepository.CreateCity(city);
            if (!cityRepository.Save())
            {
                return(StatusCode(500, "proplem happend whern creating object"));
            }
            var created = Mapper.Map <CityVM>(city);

            return(CreatedAtRoute("city", new { id = created.Id }, created));
        }