コード例 #1
0
        public ActionResult <Tour> Create([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));
            }

            var returnTour = repository.Create(tour);

            return(Ok(returnTour));
        }