public async Task <int> AddOrUpdateHall(HallDalDtoModel hallDalDto) { using (SqlConnection connection = new SqlConnection(_settings.ConnectionString)) { int id = await connection.ExecuteScalarAsync <int>( "AddOrUpdateHall", new { Id = hallDalDto.Id, CinemaId = hallDalDto.CinemaId, Name = hallDalDto.HallName }, commandType : CommandType.StoredProcedure); return(id); } }
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); }