public async Task <ActionResult <BooksResponseModel> > Get([FromQuery] PaginationParams model) { var response = new BooksResponseModel(); var books = await Task.FromResult(_context.Books.Where(x => !x.Excluded).OrderBy(x => x.Title).ToList()); if (!string.IsNullOrEmpty(model.searchTerm)) { books = books.Where(x => x.Title.ToLower().Contains(model.searchTerm.ToLower()) || x.Description.ToLower().Contains(model.searchTerm) || x.Year.Contains(model.searchTerm) ).ToList(); } if (books.Any()) { response = ShowMensageResponse.BuildResponse(books, model); } else { response.Success = false; } return(Ok(response)); }
public async Task <ActionResult <BooksResponseModel> > GetAllBooks() { BooksResponseModel booksResponseModel = new BooksResponseModel(); booksResponseModel = await Task.Run(() => _lessonPlannerRepository.GetAllBooks()); return(Ok(booksResponseModel)); }
public BooksResponseModel GetAllBooks() { BooksResponseModel booksResponseModel = new BooksResponseModel(); booksResponseModel.Data = new List <BooksDto>(); DataTable dataTable = new DataTable(); SqlConnection conn = new SqlConnection(DbHelper.DbConnectionString); try { SqlCommand command = new SqlCommand(@"dbo.uspGetAllBooks", conn); command.CommandType = CommandType.StoredProcedure; conn.Open(); SqlDataAdapter dataAdapter = new SqlDataAdapter(command); dataAdapter.Fill(dataTable); booksResponseModel.Message = "Success"; booksResponseModel.StatusCode = 200; foreach (DataRow row in dataTable.Rows) { BooksDto booksModel = new BooksDto(); booksModel.BookID = row["BookID"] != DBNull.Value ? Convert.ToInt64(row["BookID"].ToString()) : 0; booksModel.MainTopicID = row["MainTopicID"] != DBNull.Value ? Convert.ToInt64(row["MainTopicID"].ToString()) : 0; booksModel.MainTopicNumber = row["MainTopicNumber"] != DBNull.Value ? Convert.ToString(row["MainTopicNumber"]) : string.Empty; booksModel.BookDescription = row["BookDescription"] != DBNull.Value ? Convert.ToString(row["BookDescription"].ToString()) : string.Empty; booksResponseModel.Data.Add(booksModel); } } catch (Exception ex) { booksResponseModel.StatusCode = 500; booksResponseModel.Message = ex.Message; booksResponseModel.Data = null; } finally { dataTable.Clear(); dataTable = null; conn.Close(); } return(booksResponseModel); }