Exemplo n.º 1
0
    public static bool changeToBorrowed(int code, int status)
    {
      Lendings lending = DalLending.checkLending(code);


      return DalBook.changeStatus(lending.IdBook, status);
    }
Exemplo n.º 2
0
    public static bool changeToFree(int code)
    {
      Lendings lending = DalLending.checkLending(code);
      return DalBook.changeStatus(lending.IdBook, 2);


    }
Exemplo n.º 3
0
    //   string mailBody = "<div><b>" + user.FirstName + "שלום</b>" +
    //"<p>Bookmark תודה שהשתמשת בשרותי </p>" +
    //"<p>מקוים שנהנית</p>" +
    //"<p>" + book.NameBook + "הספר" +
    //"" + library.NameLibrary + "מחכה לך בספריה" +
    //"<p>:קוד השאלה</p>" +
    //"<h3>" + lending.IdLending + "</h3>" +
    //"<p>נשמח לעמוד לשרותכם תמיד</p></div>";

    public static Books checkLending(int code)
    {

      Lendings lending = DalLending.checkLending(code);

      BooksInLibrary book = DalLending.lendingBook(lending.IdBook);
      return DalBook.getBookObj(book.IdBook);
    }
Exemplo n.º 4
0
 public static int checkDaysForFree(int code)
 {
   Lendings lending = DalLending.checkLending(code);
   var dayNow = DateTime.Now;
   var dateEnd = lending.EndDate;
   if (dayNow.Day - dateEnd.Day > 0)
     return dayNow.Day - dateEnd.Day;
   else return 0;
 }
Exemplo n.º 5
0
 public static bool changeStatus(int code)
 {
   int status;
   Lendings lending = DalLending.checkLending(code);
   BooksInLibrary book = DalLending.lendingBook(lending.IdBook);
   if (book.IdStatus == 3)
     status = 1;
   else
     status = 2;
   return DalBook.changeStatus(lending.IdBook, status);
 }
Exemplo n.º 6
0
    public static int checkStatus(int code)
    {
      Lendings lending = DalLending.checkLending(code);
      BooksInLibrary book = DalLending.lendingBook(lending.IdBook);
      if (book.IdStatus == 2)
      {
        return -1;

      }
      else if (book.IdStatus == 1)
        return checkDaysForFree(code);
      else return 0;

    }
Exemplo n.º 7
0
    public static bool updateStatusEveryDay()
    {
      DateTime dateTime = DateTime.Now;
      BooksInLibrary[] catchBooksArray = DalBook.getAllCatchBooks();//all catch books
      foreach (var catchBook in catchBooksArray)
      {
        int days = DalLending.getStartLending(catchBook.IdBook);
        if (days != -1)
        {
          if (DateTime.Now.Day - days > 2)
          {
            if (!DalBook.changeStatus(catchBook.IdBook, 2))//change status to free
              return false;
          }
        }
        else
        {
          return false;
        }
      }
      return true;

    }
Exemplo n.º 8
0
    public static bool addLending(Lendings lending)
    {
      BooksInLibrary book = BLBook.getBook(lending.IdBook);//gettin book according to bookId
      Users user = BLUser.getUser(lending.IdUser);//gettin user according to userId
      lending.StartDate = DateTime.Now;//setting the lend date for today
      lending.EndDate = lending.StartDate.AddDays(Convert.ToDouble(book.LendingDuration));
      //setting the lend expiration date for today plus the borrowing time
      Lendings newLending = DalLending.addLending(lending);//add new lending
      if (newLending != null)
      {
        if (changeBookStatuse(lending.IdBook, 3)) //3 means catch-statusLending table(1-borrowed,2-free,3-catch)
        {
          Books bookObj = BLBook.getBookObj(book.IdBook);
          string mailSubject = "lending book";
          if (BLSendinMail.SendingEmail(buildMailBodyForLending(lending, user.FirstName, bookObj.NameBook), mailSubject, user.EMail))//sending mail
          {
            return true;

          }
          else
          {
            DalLending.deleteLending(newLending.IdLending);//if can't send email deleting the lending from the DB
            return false;
          }
        }
        else
        {
          DalLending.deleteLending(newLending.IdLending);//if can't change the status of the book(to catch) deleting the lending from the DB
          return false;
        }
      }
      else
      {
        return false;//if can't create the new lending deleting the lending from the DB
      }
    }