Exemplo n.º 1
0
        /// <summary>
        /// Add New Book Loan Touple to Database And Fines.
        /// </summary>
        /// <param name="bookId">Book Id</param>
        /// <param name="branchId">Branch Id</param>
        /// <param name="cardNumber">Card Number</param>
        /// <param name="dateOut">Date Out</param>
        /// <param name="dueDate">Due Date</param>
        public bool AddNewBookLoanAndFines(string bookId, int branchId, int cardNumber, DateTime dateOut, DateTime dueDate)
        {
            tblBOOK_LOANS bookLoans;
            tblFINE       fines;
            bool          result;
            int           newLoanId;

            try
            {
                using (LibraryEntities entity = new LibraryEntities())
                {
                    #region Add New Book Loans
                    bookLoans           = new tblBOOK_LOANS();
                    bookLoans.Book_id   = bookId.Trim();
                    bookLoans.Branch_id = branchId;
                    bookLoans.Card_no   = cardNumber;
                    bookLoans.Date_out  = dateOut;
                    bookLoans.Due_date  = dueDate;
                    entity.AddTotblBOOK_LOANS(bookLoans);
                    entity.SaveChanges();

                    newLoanId = (from latest in entity.tblBOOK_LOANS
                                 where latest.Book_id == bookId.Trim() && latest.Branch_id == branchId &&
                                 latest.Card_no == cardNumber
                                 select latest.Loan_id).FirstOrDefault();
                    #endregion

                    #region Add New Fines
                    fines             = new tblFINE();
                    fines.Book_id     = bookId.Trim();
                    fines.Loan_id     = newLoanId;
                    fines.paid        = true;
                    fines.Fine_amount = 0;
                    fines.Branch_id   = branchId;
                    entity.AddTotblFINES(fines);
                    entity.SaveChanges();
                    #endregion
                    result = true;
                }
                return(result);
            }
            catch (Exception e)
            {
                result = false;
                return(result);
                // Exception In Entity
            }
        }