public IActionResult PutCity(decimal id, City city)
        {
            if (id != city.Id)
            {
                return(BadRequest(BadRequestEmptyJsonResult));
            }
            if (!_repository.Exists(city.Id))
            {
                return(NotFound(NotFoundEmptyJsonResult));
            }
            if (_repository.Exists(city.Name))
            {
                return(Conflict(ConflictJsonResult("City with that name already exists")));
            }

            try
            {
                _repository.Update(city);
                _repository.Save();
            }
            catch (DbUpdateConcurrencyException e)
            {
                return(StatusCode(500, InternalServerErrorJsonResult(e.Message)));
            }

            return(Ok(OkEmptyJsonResult));
        }
Exemple #2
0
        protected override bool IsValid(PropertyValidatorContext context)
        {
            string name = (string)context.PropertyValue;

            return(_repository.Exists(name));
        }