public async Task <ActionResult <MoviesResponseModel> > GetAllMovies() { MoviesResponseModel moviesResponseModel = new MoviesResponseModel(); moviesResponseModel = await Task.Run(() => _lessonPlannerRepository.GetAllMovies()); return(Ok(moviesResponseModel)); }
public MoviesResponseModel GetAllMovies() { MoviesResponseModel moviesResponseModel = new MoviesResponseModel(); moviesResponseModel.Data = new List <MoviesDto>(); DataTable dataTable = new DataTable(); SqlConnection conn = new SqlConnection(DbHelper.DbConnectionString); try { SqlCommand command = new SqlCommand(@"dbo.uspGetAllMovies", conn); command.CommandType = CommandType.StoredProcedure; conn.Open(); SqlDataAdapter dataAdapter = new SqlDataAdapter(command); dataAdapter.Fill(dataTable); moviesResponseModel.Message = "Success"; moviesResponseModel.StatusCode = 200; foreach (DataRow row in dataTable.Rows) { MoviesDto movies = new MoviesDto(); movies.MovieID = row["MovieID"] != DBNull.Value ? Convert.ToInt64(row["MovieID"].ToString()) : 0; movies.MainTopicID = row["MainTopicID"] != DBNull.Value ? Convert.ToInt64(row["MainTopicID"].ToString()) : 0; movies.MainTopicNumber = row["MainTopicNumber"] != DBNull.Value ? Convert.ToString(row["MainTopicNumber"]) : string.Empty; movies.MovieDescription = row["MovieDescription"] != DBNull.Value ? Convert.ToString(row["MovieDescription"].ToString()) : string.Empty; moviesResponseModel.Data.Add(movies); } } catch (Exception ex) { moviesResponseModel.StatusCode = 500; moviesResponseModel.Message = ex.Message; moviesResponseModel.Data = null; } finally { dataTable.Clear(); dataTable = null; conn.Close(); } return(moviesResponseModel); }
private async Task <IEnumerable <Movie> > GetAllMoviePages(IRestRequest request) { var items = new List <Movie>(); MoviesResponseModel responseModel = null; do { var response = await _restClient.ExecuteGetAsync(request); responseModel = JsonConvert.DeserializeObject <MoviesResponseModel>(response.Content); items.AddRange(responseModel.Movies); var currentPage = responseModel.Page; request.AddParameter(_pageParameter, ++currentPage); } while (responseModel.Page != responseModel.TotalPages); return(items); }