Exemplo n.º 1
0
        /// <summary>
        /// Remove 1 from the quantity of books if book quantity is 1 or more
        /// </summary>
        /// <param name="itemID"></param>
        /// <returns></returns>
        public async Task SellBook(string itemID, string username)
        {
            int id;

            if (int.TryParse(itemID, out id) == false)
            {
                await GeneralLibraryLogic.SaveToLogFile("Wrong id cannot convert to int");

                throw new BLLBookException("Cannot sell a book id is not correct");
            }
            Book b1 = await GetBook(itemID);

            if (b1.Quantity > 0)
            {
                b1.Quantity -= 1;
            }
            else
            {
                await GeneralLibraryLogic.SaveToLogFile("Cannot sell a book out of stock");

                throw new BLLBookException("Cannot sell a book out of stock");
            }
            try
            {
                await UpdateBook(itemID, b1.Name, b1.Writer, b1.PrintDate.ToString(), b1.Publisher, b1.Genre.Name, b1.Discount.ToString(), b1.Quantity.ToString(), b1.Price.ToString(), b1.ISBN, b1.Edition, b1.Summary);

                await _saleService.AddNewSale(username, id, 1);
            }
            catch (Exception e)
            {
                if (e is BookException ||
                    e is DALException)
                {
                    await GeneralLibraryLogic.SaveToLogFile(e.ToString());

                    throw new BLLBookException("Cannot sell a book atm try again later or call a manager");
                }
                else
                {
                    await GeneralLibraryLogic.SaveToLogFile(e.ToString());

                    throw new LibraryException("Unknown error inform a manager!");
                }
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Removes 1 from the quantity of the journal if the quantity is 1 or more
        /// </summary>
        /// <param name="itemID"></param>
        /// <returns></returns>
        public async Task SellJournal(string itemID, string username)
        {
            int id;

            if (int.TryParse(itemID, out id) == false)
            {
                await GeneralLibraryLogic.SaveToLogFile("ID is not valid cannot convert to int!");

                throw new BLLJournalException("ID is not valid cannot convert to int!");
            }
            try
            {
                Journal j1 = await GetJournal(itemID);

                if (j1.Quantity > 0)
                {
                    j1.Quantity -= 1;
                }
                await UpdateJournal(itemID, j1.Name, j1.Writer, j1.PrintDate.ToString(), j1.Publisher, j1.Genre.Name, j1.Discount.ToString(), j1.Quantity.ToString(), j1.Price.ToString(), j1.Subject);

                await _saleService.AddNewSale(username, id, 1);
            }
            catch (Exception e)
            {
                if (e is BLLJournalException ||
                    e is DALException)
                {
                    await GeneralLibraryLogic.SaveToLogFile(e.ToString());

                    throw new BLLJournalException("Cannot sell a journal atm try again later or call a manager");
                }
                else
                {
                    await GeneralLibraryLogic.SaveToLogFile(e.ToString());

                    throw new LibraryException("Unknown error inform a manager!");
                }
            }
        }