public async Task <IActionResult> GetShowCollection(Guid tourId, [ModelBinder(BinderType = typeof(ArrayModelBinder))] IEnumerable <Guid> showIds) { if (showIds == null || !showIds.Any()) { return(BadRequest()); } // check if the tour exists if (!await _tourManagementRepository.TourExists(tourId)) { return(NotFound()); } var showEntities = await _tourManagementRepository.GetShows(tourId, showIds); if (showIds.Count() != showEntities.Count()) { return(NotFound()); } var showCollectionToReturn = Mapper.Map <IEnumerable <Show> >(showEntities); return(Ok(showCollectionToReturn)); }
public async Task <IActionResult> CreateShowCollection( Guid tourId, [FromBody] IEnumerable <ShowForCreation> showCollection) { if (showCollection == null) { return(BadRequest()); } if (!await _tourMgmtRepo.TourExists(tourId)) { return(NotFound()); } var showEntities = Mapper.Map <IEnumerable <Entities.Show> >(showCollection); foreach (var show in showEntities) { await _tourMgmtRepo.AddShow(tourId, show); } if (!await _tourMgmtRepo.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> GetShows(Guid tourId) { if (!(await _tourManagementRepostitory.TourExists(tourId))) { return(NotFound()); } var showsFromRepo = await _tourManagementRepostitory.GetShows(tourId); var shows = Mapper.Map <IEnumerable <Show> >(showsFromRepo); return(Ok(shows)); }