public async Task <IActionResult> PartiallyUpdateTour(Guid tourId, [FromBody] JsonPatchDocument <TourForUpdate> jsonPatchDocument) { if (jsonPatchDocument == null) { return(BadRequest()); } var tourFromRepo = await _tourManagementRepository.GetTour(tourId); if (tourFromRepo == null) { return(BadRequest()); } var tourToPatch = Mapper.Map <TourForUpdate>(tourFromRepo); jsonPatchDocument.ApplyTo(tourToPatch); Mapper.Map(tourToPatch, tourFromRepo); await _tourManagementRepository.UpdateTour(tourFromRepo); if (!await _tourManagementRepository.SaveAsync()) { throw new Exception("Updating a tour failed on save."); } return(NoContent()); }
private async Task <IActionResult> GetSpecificTour <T>(Guid tourId, bool includeShows = false) where T : class { var tourFromRepo = await _tourManagementRepository.GetTour(tourId, includeShows); if (tourFromRepo == null) { return(BadRequest()); } return(Ok(Mapper.Map <T>(tourFromRepo))); }
public async Task <IActionResult> GetTourGeneric <T>(Guid tourId, bool includeShows = false) where T : class { var tourFromRepo = await _tourManagementRepository.GetTour(tourId, includeShows); if (tourFromRepo == null) { return(BadRequest()); } var tour = Mapper.Map <T>(tourFromRepo); return(Ok(tour)); }
public async Task <IActionResult> GetTour(Guid tourId) { var tourFromRepo = await _tourManagementRepository.GetTour(tourId); if (tourFromRepo == null) { return(BadRequest()); } var tour = Mapper.Map <Tour>(tourFromRepo); return(Ok(tour)); }
private async Task <IActionResult> GetSpecificTour <T>(Guid tourId, bool includeShows = false) where T : class { var tourFromRepo = await _tourManagementRepository.GetTour(tourId, includeShows); if (tourFromRepo == null) { return(BadRequest()); } // ************ The Mapper.Map will create an instance of T and then map stuff from tourFromRepo to it and return it return(Ok(Mapper.Map <T>(tourFromRepo))); // So, the above is really // var x = Mapper.Map<T>(tourFromRepo); // return Ok(x) }
public async Task <IActionResult> PartiallyUpdateTour(int tourId, [FromBody] JsonPatchDocument <TourForUpdate> jsonPatchDocument) { if (jsonPatchDocument == null) { return(BadRequest()); } var tourFromRepo = await _tourManagementRepository.GetTour(tourId); if (tourFromRepo == null) { return(BadRequest()); } var tourToPatch = Mapper.Map <TourForUpdate>(tourFromRepo); jsonPatchDocument.ApplyTo(tourToPatch, ModelState); if (!ModelState.IsValid) { return(UnprocessableEntity()); } if (!TryValidateModel(tourToPatch)) { return(UnprocessableEntity()); } Mapper.Map(tourToPatch, tourFromRepo); await _tourManagementRepository.UpdateTour(tourFromRepo); if (!await _tourManagementRepository.SaveAsync()) { throw new Exception("Updating a tour failed on save."); } return(NoContent()); }
private async Task <IActionResult> GetSpecificTour <T>(Guid tourId) where T : class { var tourFromRepo = await _tourManagementRepository.GetTour(tourId); if (tourFromRepo == null) { return(BadRequest()); } var tourDto = Mapper.Map <T>(tourFromRepo); return(Ok(tourDto)); }
public async Task<IActionResult> GetShows(Guid tourId) { var tourFromRepo = await _tourManagementRepository.GetTour(tourId, true); if (!(await _tourManagementRepository.TourExists(tourId))) { return NotFound(); } var showsFromRepo = await _tourManagementRepository.GetShows(tourId); var shows = Mapper.Map<IEnumerable<Show>>(showsFromRepo); return Ok(shows); }
public async Task <IActionResult> Get(string tourId) { try { var tourFromRepo = await _tourManagementRepository.GetTour(tourId); var tour = Mapper.Map <Tour>(tourFromRepo); return(Ok(tour)); } catch (Exception ex) { Debug.WriteLine(ex.Message); } return(Ok()); }