Esempio n. 1
0
        /// <summary>
        /// Fine Payment
        /// </summary>
        /// <param name="finePayment"></param>
        public bool FinePayment(List <uspGetFinesById_Result> finePayment)
        {
            tblFINE fines;
            bool    result = true;

            try{
                using (LibraryEntities entity = new LibraryEntities())
                {
                    foreach (uspGetFinesById_Result finesItem in finePayment)
                    {
                        fines = new tblFINE();
                        fines = (from fin in entity.tblFINES
                                 where fin.Book_id == finesItem.Book_id &&
                                 fin.Branch_id == finesItem.Branch_id && fin.Loan_id == finesItem.Loan_id
                                 select fin).FirstOrDefault();
                        fines.paid = true;
                        entity.SaveChanges();
                    }
                    result = true;
                }
                return(result);
            }
            catch (Exception e)
            {
                result = false;
                return(result);
                // Excetpion in update
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Update Fines Table
        /// </summary>
        public void UpdateFines()
        {
            List <int>    currentLoanIds;
            tblBOOK_LOANS loans;
            tblFINE       fine;
            double        overDays = 0;
            double        totalFine;
            double        finePerDay = 0.25;

            try
            {
                using (LibraryEntities entity = new LibraryEntities())
                {
                    #region Get Loans And Update Fines
                    // Get the all loans of which Fines are Due.
                    #region Fines - Associated with books not returned yet
                    currentLoanIds = new List <int>();
                    currentLoanIds = (from allLoans in entity.tblBOOK_LOANS
                                      where allLoans.Date_in == null && DateTime.Now > allLoans.Due_date
                                      select allLoans.Loan_id).ToList();

                    #endregion

                    //Get All loans which haven't payed Fines
                    #region Fines - Associated with books returned and Not Paid Yet
                    List <int> loanIds = new List <int>();
                    loanIds = (from allLoans in entity.tblBOOK_LOANS
                               join fines in entity.tblFINES on allLoans.Loan_id equals fines.Loan_id
                               where  allLoans.Date_in > allLoans.Due_date && fines.paid == false
                               select allLoans.Loan_id).ToList();
                    currentLoanIds.AddRange(loanIds);
                    #endregion

                    //update the Fines to above result
                    foreach (int loanid in currentLoanIds)
                    {
                        fine      = new tblFINE();
                        loans     = new tblBOOK_LOANS();
                        loans     = (from loan in entity.tblBOOK_LOANS where loan.Loan_id == loanid select loan).FirstOrDefault();
                        overDays  = (DateTime.Now - Convert.ToDateTime(loans.Due_date)).TotalDays;
                        overDays  = Math.Floor(overDays);
                        totalFine = overDays * finePerDay;
                        totalFine = Math.Round(totalFine, 2);
                        fine      = (from fines in entity.tblFINES
                                     where fines.Loan_id == loanid
                                     select fines).FirstOrDefault();
                        fine.paid        = false;
                        fine.Fine_amount = Convert.ToDecimal(totalFine);
                        entity.SaveChanges();
                    }
                    #endregion
                }
            }
            catch (Exception e)
            {
                // Excetpion in Entity
            }
        }
Esempio n. 3
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
            }
        }