Esempio n. 1
0
        public IActionResult EditSpot(int id, [FromBody] SpotUpdateDto spot)
        {
            var spotFromRepo = _repository.GetSpot(id);

            if (spot == null)
            {
                return(BadRequest());
            }
            if (spotFromRepo == null)
            {
                return(StatusCode(404, "Could not find spot to edit"));
            }
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            var mappedSpot = Mapper.Map <SpotDto>(spot);

            _repository.EditSpot(id, mappedSpot);

            if (!_repository.SaveChanges())
            {
                return(StatusCode(400, "Probably bad request, but not 500 - server is fine tho"));
            }
            return(Ok(_repository.GetSpot(id)));
        }