示例#1
0
        public ActionResult <Tour> Update([FromBody] Tour tour)
        {
            if (tour.Price == null | tour.Price == 0)
            {
                ModelState.AddModelError("Price", "Price must be positive number");
            }

            if (string.IsNullOrWhiteSpace(tour.Name))
            {
                ModelState.AddModelError("Name", "Tour name must be non empty string");
            }

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

            if (!repository.IfExist(tour))
            {
                return(NotFound("Tour not exist"));
            }

            repository.Update(tour);
            return(Ok(tour));
        }