public async Task <IActionResult> CreateShowCollection( Guid tourId, [FromBody] IEnumerable <ShowForCreation> showCollection) { if (showCollection == null) { return(BadRequest()); } if (!await _tourManagementRepository.TourExists(tourId)) { return(NotFound()); } var showEntities = Mapper.Map <IEnumerable <Entities.Show> >(showCollection); foreach (var show in showEntities) { await _tourManagementRepository.AddShow(tourId, show); } if (!await _tourManagementRepository.SaveAsync()) { throw new Exception("Adding a collection of shows failed on save."); } var showCollectionToReturn = Mapper.Map <IEnumerable <Show> >(showEntities); var showIdsAsString = string.Join(",", showCollectionToReturn.Select(a => a.ShowId)); return(CreatedAtRoute("GetShowCollection", new { tourId, showIds = showIdsAsString }, showCollectionToReturn)); }
public async Task <IActionResult> CreateShowCollection(Guid tourId, [FromBody] IEnumerable <ShowForCreation> showCollection) { if (showCollection == null) { return(BadRequest()); } if (!await _tourManagementRepository.TourExists(tourId)) { return(NotFound()); } var showEntities = Mapper.Map <IEnumerable <Entities.Show> >(showCollection); foreach (var show in showEntities) { await _tourManagementRepository.AddShow(tourId, show); } if (!await _tourManagementRepository.SaveAsync()) { throw new Exception("Error"); } return(Ok()); }