public async Task <IActionResult> Get(int hallId, int sessionId) { FullHallBlModel fullHallBl = await _hallsService.GetHallForSession(hallId, sessionId); if (fullHallBl == null) { return(NotFound()); } return(Ok(new HallApiModel( fullHallBl.Id, fullHallBl.CinemaId, fullHallBl.HallName, fullHallBl.CinemaName, fullHallBl.PlacesBl?.Select(Mapper.Map <PlaceApiModel>).ToArray(), fullHallBl.HallSchemeBlModels?.Select(Mapper.Map <HallSchemeApiModel>).ToArray() ))); }
public async Task <IActionResult> Put([NotNull][FromBody] HallApiModel hallApi) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } FullHallBlModel fullHallBlRequest = new FullHallBlModel( hallApi.Id, hallApi.CinemaId, hallApi.HallName, hallApi.CinemaName, hallApi.PlacesApi?.Select(Mapper.Map <BusinessLayer.Models.PlaceBlModel>).ToArray(), hallApi.HallSchemeApiModels?.Select(Mapper.Map <BusinessLayer.Models.HallSchemeBlModel>).ToArray() ); FullHallBlModel fullHallBl = await _hallsService.AddOrOrUpdateHall(fullHallBlRequest); return(Ok(fullHallBl)); }
public async Task <FullHallBlModel> AddOrOrUpdateHall(FullHallBlModel hallBlModel) { HallBlModel hallBlRequest = new HallBlModel( hallBlModel.Id, hallBlModel.CinemaId, hallBlModel.HallName, hallBlModel.CinemaName ); int hallModelResponseId = await _hallsRepository.AddOrUpdateHall(Mapper.Map <HallDalDtoModel>(hallBlRequest)); HallDalDtoModel hallDalDtoModelResponse = new HallDalDtoModel( (hallModelResponseId != 0) ? hallModelResponseId : hallBlModel.Id, hallBlModel.CinemaId, hallBlModel.HallName, hallBlModel.CinemaName ); List <PlaceBlModel> placesList = new List <PlaceBlModel>(); if (hallBlModel.PlacesBl != null) { foreach (PlaceBlModel place in hallBlModel.PlacesBl) { int placeResponseId = await _hallsRepository.AddOrUpdatePlace ( new PlaceDalDtoModel ( place.Id, place.HallId, place.Type.Name, place.Type.Id, place.PlaceNumber, place.RowNumber, place.Price, place.PriceId, place.PlaceStatus ) ); PlaceBlModel placeBlModel = new PlaceBlModel( (placeResponseId != 0) ? placeResponseId : place.Id, place.HallId, new PlaceTypeBlModel ( place.Type.Id, place.Type.Name ), place.PlaceNumber, place.RowNumber, place.Price, place.PriceId, place.PlaceStatus ); placesList.Add(placeBlModel); } } List <HallSchemeBlModel> schemeModelList = new List <HallSchemeBlModel>(); if (hallBlModel.HallSchemeBlModels != null) { foreach (HallSchemeBlModel hallScheme in hallBlModel.HallSchemeBlModels) { int hallSchemeResponseId = await _hallsRepository.AddOrUpdateHallScheme(Mapper.Map <HallSchemeDalDtoModel>(hallScheme)); HallSchemeBlModel hallSchemeBlModel = new HallSchemeBlModel( (hallSchemeResponseId != 0) ? hallSchemeResponseId : hallScheme.Id, hallScheme.HallId, hallScheme.RowNumber, hallScheme.PlacesCount ); schemeModelList.Add(hallSchemeBlModel); } } FullHallBlModel fullHallBlModel = new FullHallBlModel( hallDalDtoModelResponse.Id, hallDalDtoModelResponse.CinemaId, hallDalDtoModelResponse.HallName, hallDalDtoModelResponse.CinemaName, placesList.ToArray(), schemeModelList.ToArray() ); return(fullHallBlModel); }