コード例 #1
0
        public IActionResult UpdatePointOfInterest(int templeId, int pId, [FromBody] PointOfInterestUpdateDto pointOfInterestUpdate)
        {
            if (pointOfInterestUpdate == null)
            {
                return(BadRequest());
            }

            if (pointOfInterestUpdate.Description == pointOfInterestUpdate.Name)
            {
                ModelState.AddModelError("Description", "The provided description should be different from the name.");
            }

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


            //first try to find the temple
            TempleDTO temple = Gettemple(templeId);

            if (temple == null)
            {
                _logger.LogInformation($"temple with templeID {templeId} was not found");
                return(NotFound());
            }

            //next find the point of interest
            PointOfInterestDto pointOfInterestStore = GetPointOfInterest(pId, temple);

            if (pointOfInterestStore == null)
            {
                return(NotFound());
            }

            pointOfInterestStore.Name        = pointOfInterestUpdate.Name;
            pointOfInterestStore.Description = pointOfInterestUpdate.Description;

            return(NoContent());
        }
コード例 #2
0
 private static PointOfInterestDto GetPointOfInterest(int pId, TempleDTO temple)
 {
     return(temple.PointsOfInterest.FirstOrDefault(p => p.Id == pId));
 }