public async Task <List <Journal> > GetAllJournals() { List <Journal> journals = new List <Journal>(); string GetJournalsQuery = "SELECT ItemID, Name, Writer, PrintDate, Publisher, IDOfGenre, Discount, Quantity,Price, Subject " + "FROM AbstractItems " + "WHERE Isbn is null"; try { SqliteCommand command = new SqliteCommand(GetJournalsQuery); List <string> journalsString = SqlFileAccess.GetData(command); for (int i = 0; i < journalsString.Count; i++) { journals.Add(await TextToJournal(journalsString[i])); } return(journals); } catch (Exception e) { if (e is SqliteException || e is ArgumentOutOfRangeException) { await GeneralRepository.SaveToLogFile(e.ToString()); throw new JournalException("Cant get all journals"); } else { await GeneralRepository.SaveToLogFile(e.ToString()); throw new DALException("Unknown Error"); } } }
/// <summary> /// Returns a list of all the isbns exist /// </summary> /// <returns></returns> public async Task <List <string> > GetAllIsbn() { string getAllIsbnQuery = "SELECT Isbn FROM AbstractItems WHERE Isbn is not null "; try { SqliteCommand command = new SqliteCommand(getAllIsbnQuery); return(SqlFileAccess.GetData(command)); } catch (Exception e) { if (e is SqliteException || e is ArgumentOutOfRangeException) { await GeneralRepository.SaveToLogFile(e.ToString()); throw new BookException("Cant get isbns"); } else { await GeneralRepository.SaveToLogFile(e.ToString()); throw new DALException("Unknown Error"); } } }
/// <summary> /// Get a journal by its id /// </summary> /// <param name="id"></param> /// <returns>Journal if found, if not found returns null</returns> public async Task <Journal> GetJournal(int id) { List <Journal> journals = new List <Journal>(); string GetBooksQuery = "SELECT ItemID, Name, Writer, PrintDate, Publisher, IDOfGenre, Discount, Quantity,Price,Subject " + "FROM AbstractItems " + $"WHERE ItemID = @id AND ISBN IS NULL"; try { SqliteCommand command = new SqliteCommand(GetBooksQuery); command.Parameters.AddWithValue("@id", id); List <string> journalsString = SqlFileAccess.GetData(command); if (journalsString.Count == 0) { return(null); } journals.Add(await TextToJournal(journalsString[0])); return(journals[0]); } catch (Exception e) { if (e is SqliteException || e is ArgumentOutOfRangeException) { await GeneralRepository.SaveToLogFile(e.ToString()); throw new JournalException("Cant get journal"); } else { await GeneralRepository.SaveToLogFile(e.ToString()); throw new DALException("Unknown Error"); } } }
public async Task <List <Book> > GetAllBooks() { List <Book> books = new List <Book>(); string GetBooksQuery = "SELECT ItemID, Name, Writer, PrintDate, Publisher, IDOfGenre, Discount, Quantity,Price, Isbn, Edition, Summary " + "FROM AbstractItems " + "WHERE Subject is null"; try { SqliteCommand command = new SqliteCommand(GetBooksQuery); List <string> booksString = SqlFileAccess.GetData(command); for (int i = 0; i < booksString.Count; i++) { books.Add(await TextToBook(booksString[i])); } return(books); } catch (Exception e) { if (e is SqliteException || e is ArgumentOutOfRangeException) { await GeneralRepository.SaveToLogFile(e.ToString()); throw new BookException("Cant get all books"); } else { await GeneralRepository.SaveToLogFile(e.ToString()); throw new DALException("Unknown Error"); } } }
/// <summary> /// Get a general item by its id /// </summary> /// <param name="id"></param> /// <returns></returns> public async Task <AbstractItem> GetItemByID(int id) { List <AbstractItem> items = new List <AbstractItem>(); string GetItemsQuery = "SELECT ItemID, Name, Writer, PrintDate, Publisher, IDOfGenre, Discount, Quantity,Price " + "FROM AbstractItems " + $"WHERE ItemID = @id"; try { SqliteCommand command = new SqliteCommand(GetItemsQuery); command.Parameters.AddWithValue("@id", id); List <string> itemsString = SqlFileAccess.GetData(command); if (itemsString.Count == 0) { return(null); } items.Add(await TextToItem(itemsString[0])); return(items[0]); } catch (Exception e) { if (e is SqliteException || e is ArgumentOutOfRangeException) { await SaveToLogFile(e.ToString()); throw new GeneralItemException("Cant get Item By ID"); } else { await SaveToLogFile(e.ToString()); throw new DALException("Unknown Error"); } } }
/// <summary> /// Get all genres exist /// </summary> /// <returns>List of all genres or null if not genres exist</returns> public async Task <List <Genre> > GetAllGenres() { List <Genre> genres = new List <Genre>(); string GetgenresQuery = "SELECT GenreID,GenreName " + "FROM Genres "; try { SqliteCommand command = new SqliteCommand(GetgenresQuery); List <string> genresString = SqlFileAccess.GetData(command); for (int i = 0; i < genresString.Count; i++) { genres.Add(TextToGenre(genresString[i])); } return(genres); } catch (Exception e) { if (e is SqliteException || e is ArgumentOutOfRangeException) { await GeneralRepository.SaveToLogFile(e.ToString()); throw new GenreException("Cant get all genres"); } else { await GeneralRepository.SaveToLogFile(e.ToString()); throw new DALException("Unknown Error"); } } }
/// <summary> /// Get genre by its id /// </summary> /// <param name="id"></param> /// <returns>return the genre found, or an empty genre if not found</returns> public async Task <Genre> GetGenreByID(int id) { string getGenreQuery = $"SELECT GenreID,GenreName FROM Genres WHERE GenreID = @id"; try { SqliteCommand command = new SqliteCommand(getGenreQuery); command.Parameters.AddWithValue("@id", id); List <string> genreString = SqlFileAccess.GetData(command); if (genreString.Count == 0) { return(new Genre()); } return(TextToGenre(genreString[0])); } catch (Exception e) { if (e is SqliteException || e is ArgumentOutOfRangeException) { await GeneralRepository.SaveToLogFile(e.ToString()); throw new GenreException("Cant get genre by id"); } else { await GeneralRepository.SaveToLogFile(e.ToString()); throw new DALException("Unknown Error"); } } }
public async Task <List <string> > GetAllItemNames() { string getAllNamesQuery = "SELECT Name FROM AbstractItems"; try { SqliteCommand command = new SqliteCommand(getAllNamesQuery); return(SqlFileAccess.GetData(command)); } catch (Exception e) { if (e is SqliteException) { await GeneralRepository.SaveToLogFile(e.ToString()); throw new QueryException("Cant get all authors"); } else { await GeneralRepository.SaveToLogFile(e.ToString()); throw new DALException("Unknown Error"); } } }