Example #1
0
        public Landmark Add([FromBody] Landmark landmark)
        {
            // Log the API call
            _logger.LogInformation("Adding a landmark to persistent storage");

            // Get or create the user that matches the passed in username
            var user = _landmarkRepository.GetUser(landmark.Username);

            if (user == null)
            {
                throw new Exception($"User '{landmark.Username}' not found");
            }

            // Add the landmark
            return(_landmarkRepository.AddLandmark(user.Username, landmark.Latitude, landmark.Longitude, landmark.Comment));
        }
Example #2
0
        public async Task <IActionResult> AddLandmark([FromBody] Landmark landmark)
        {
            if (landmark == null)
            {
                return(BadRequest());
            }

            if (landmark.LandmarkName == string.Empty)
            {
                ModelState.AddModelError("Landmark Name", "The landmark name cannot be empty");
            }

            if (!ModelState.IsValid) // model binding may fail
            {
                return(BadRequest(ModelState));
            }

            var createdLandmark = await _landmarkRepository.AddLandmark(landmark);

            return(Created("landmark", createdLandmark));
        }