Ejemplo n.º 1
0
        public async Task AddJournal(Journal j1)
        {
            string insertQuery = "INSERT INTO AbstractItems(Name,Writer,PrintDate,Publisher,IDOfGenre,Discount,Quantity,Price,Subject)" +
                                 $"VALUES(@name , @writer , @printDate , @publisher , @genreID , @discount , @quantity , @price , @subject)";

            try
            {
                SqliteCommand command = new SqliteCommand(insertQuery);
                command.Parameters.AddWithValue("@name", j1.Name);
                command.Parameters.AddWithValue("@writer", j1.Writer);
                command.Parameters.AddWithValue("@printDate", j1.PrintDate);
                command.Parameters.AddWithValue("@publisher", j1.Publisher);
                command.Parameters.AddWithValue("@genreID", j1.Genre.ID);
                command.Parameters.AddWithValue("@discount", j1.Discount);
                command.Parameters.AddWithValue("@quantity", j1.Quantity);
                command.Parameters.AddWithValue("@price", j1.Price);
                command.Parameters.AddWithValue("@subject", j1.Subject);
                SqlFileAccess.SqlPerformQuery(command);
            }
            catch (Exception e)
            {
                if (e is SqliteException || e is ArgumentOutOfRangeException)
                {
                    await GeneralRepository.SaveToLogFile(e.ToString());

                    throw new JournalException("Cant add journal");
                }
                else
                {
                    await GeneralRepository.SaveToLogFile(e.ToString());

                    throw new DALException("Unknown Error");
                }
            }
        }
Ejemplo n.º 2
0
        public async Task DeleteJournal(Journal j1)
        {
            string deleteQuery = $"DELETE FROM AbstractItems WHERE ItemID = @id";

            try
            {
                SqliteCommand command = new SqliteCommand(deleteQuery);
                command.Parameters.AddWithValue("@id", j1.ItemID);
                SqlFileAccess.SqlPerformQuery(command);
            }
            catch (Exception e)
            {
                if (e is SqliteException || e is ArgumentOutOfRangeException)
                {
                    await GeneralRepository.SaveToLogFile(e.ToString());

                    throw new JournalException("Cant delete journal");
                }
                else
                {
                    await GeneralRepository.SaveToLogFile(e.ToString());

                    throw new DALException("Unknown Error");
                }
            }
        }
Ejemplo n.º 3
0
        public async Task DeleteGenre(Genre g1)
        {
            string deleteQuery = $"DELETE FROM Genres WHERE GenreID = @genreID";

            try
            {
                SqliteCommand command = new SqliteCommand(deleteQuery);
                command.Parameters.AddWithValue("@genreID", g1.ID);
                SqlFileAccess.SqlPerformQuery(command);
            }
            catch (Exception e)
            {
                if (e is SqliteException || e is ArgumentOutOfRangeException)
                {
                    await GeneralRepository.SaveToLogFile(e.ToString());

                    throw new GenreException("Cant delete genre");
                }
                else
                {
                    await GeneralRepository.SaveToLogFile(e.ToString());

                    throw new DALException("Unknown Error");
                }
            }
        }
Ejemplo n.º 4
0
        public async Task UpdateGenre(int genreID, Genre updatedGenre)
        {
            string updateGenre = "UPDATE Genres " +
                                 $"Set GenreName = @genreName" +
                                 $"WHERE GenreID = @genreID";

            try
            {
                SqliteCommand command = new SqliteCommand(updateGenre);
                command.Parameters.AddWithValue("@genreName", updatedGenre.Name);
                command.Parameters.AddWithValue("@genreID", updatedGenre.ID);
                SqlFileAccess.SqlPerformQuery(command);
            }
            catch (Exception e)
            {
                if (e is SqliteException || e is ArgumentOutOfRangeException)
                {
                    await GeneralRepository.SaveToLogFile(e.ToString());

                    throw new GenreException("Cant update genre");
                }
                else
                {
                    await GeneralRepository.SaveToLogFile(e.ToString());

                    throw new DALException("Unknown Error");
                }
            }
        }
Ejemplo n.º 5
0
        public async Task AddGenre(Genre g1)
        {
            string insertQuery = "INSERT INTO Genres(GenreName)" +
                                 $"VALUES(@genreName)";

            try
            {
                SqliteCommand command = new SqliteCommand(insertQuery);
                command.Parameters.AddWithValue("@genreName", g1.Name);
                SqlFileAccess.SqlPerformQuery(command);
            }
            catch (Exception e)
            {
                if (e is SqliteException || e is ArgumentOutOfRangeException)
                {
                    await GeneralRepository.SaveToLogFile(e.ToString());

                    throw new GenreException("Cant add genre");
                }
                else
                {
                    await GeneralRepository.SaveToLogFile(e.ToString());

                    throw new DALException("Unknown Error");
                }
            }
        }
        /// <summary>
        /// Update a book by giving the book id and the new book data
        /// </summary>
        /// <param name="id"></param>
        /// <param name="updatedBook"></param>
        /// <returns></returns>
        public async Task UpdateBook(int id, Book updatedBook)
        {
            string updateQuery = "UPDATE AbstractItems " +
                                 $"Set Name = @name , Writer = @writer , PrintDate = @printDate , Publisher = @publisher , " +
                                 $"IDOfGenre = @genreID , Discount = @discount , Quantity = @quantity , Price = @price , Isbn = @isbn , " +
                                 $"Edition = @edition , Summary = @summary " +
                                 $"WHERE ItemID = @id";

            try
            {
                SqliteCommand command = new SqliteCommand(updateQuery);
                command.Parameters.AddWithValue("@name", updatedBook.Name);
                command.Parameters.AddWithValue("@writer", updatedBook.Writer);
                command.Parameters.AddWithValue("@printDate", updatedBook.PrintDate);
                command.Parameters.AddWithValue("@publisher", updatedBook.Publisher);
                command.Parameters.AddWithValue("@genreID", updatedBook.Genre.ID);
                command.Parameters.AddWithValue("@discount", updatedBook.Discount);
                command.Parameters.AddWithValue("@quantity", updatedBook.Quantity);
                command.Parameters.AddWithValue("@price", updatedBook.Price);
                command.Parameters.AddWithValue("@isbn", updatedBook.ISBN);
                command.Parameters.AddWithValue("@edition", updatedBook.Edition);
                command.Parameters.AddWithValue("@summary", updatedBook.Summary);
                command.Parameters.AddWithValue("@id", id);
                SqlFileAccess.SqlPerformQuery(command);
            }
            catch (Exception e)
            {
                if (e is SqliteException || e is ArgumentOutOfRangeException)
                {
                    await GeneralRepository.SaveToLogFile(e.ToString());

                    throw new BookException("Cant Update book");
                }
                else
                {
                    await GeneralRepository.SaveToLogFile(e.ToString());

                    throw new DALException("Unknown Error");
                }
            }
        }
Ejemplo n.º 7
0
        public async Task UpdateJournal(int id, Journal updatedJournal)
        {
            string updateQuery = "UPDATE AbstractItems " +
                                 $"Set Name = @name , Writer = @writer , PrintDate = @printDate , Publisher = @publisher , " +
                                 $"IDOfGenre = @genreID , Discount = @discount , Quantity = @quantity , Price = @price , Subject = @subject " +
                                 $"WHERE ItemID = @id";

            try
            {
                SqliteCommand command = new SqliteCommand(updateQuery);
                command.Parameters.AddWithValue("@name", updatedJournal.Name);
                command.Parameters.AddWithValue("@writer", updatedJournal.Writer);
                command.Parameters.AddWithValue("@printDate", updatedJournal.PrintDate);
                command.Parameters.AddWithValue("@publisher", updatedJournal.Publisher);
                command.Parameters.AddWithValue("@genreID", updatedJournal.Genre.ID);
                command.Parameters.AddWithValue("@discount", updatedJournal.Discount);
                command.Parameters.AddWithValue("@quantity", updatedJournal.Quantity);
                command.Parameters.AddWithValue("@price", updatedJournal.Price);
                command.Parameters.AddWithValue("@subject", updatedJournal.Subject);
                command.Parameters.AddWithValue("@id", id);
                SqlFileAccess.SqlPerformQuery(command);
            }
            catch (Exception e)
            {
                if (e is SqliteException || e is ArgumentOutOfRangeException)
                {
                    await GeneralRepository.SaveToLogFile(e.ToString());

                    throw new JournalException("Cant update journal");
                }
                else
                {
                    await GeneralRepository.SaveToLogFile(e.ToString());

                    throw new DALException("Unknown Error");
                }
            }
        }