Beispiel #1
0
        public JsonResult createBorrow(int bookId)
        {
            string message = "";
            object oId = this.Session["connected"];
            if (oId != null)
            {
                Borrower currentBorrower = new BorrowerController().getBorrowerByUserID(oId.ToString());
                if (currentBorrower != null)
                {
                    Borrow newBorrow = new Borrow();
                    newBorrow.bookId = bookId;
                    newBorrow.borrowDate = DateTime.Today;
                    newBorrow.borrowerId = currentBorrower.id;

                    if (!borrowBook(bookId))
                    {
                        message = "there are no available copies of this book";
                    }
                    else if (!addNewBorrow(newBorrow))
                    {
                        message = "there's a problem.... try again later";
                    }
                }
                else
                {
                    message = "current user isn't attached to any borrower!!!";
                }
            }
            else
            {
                message = "there is no user connected";
            }

            return Json(message, JsonRequestBehavior.AllowGet);
        }
Beispiel #2
0
        public bool addNewBorrow(Borrow borrow)
        {
            try
            {
                context.borrows.Add(borrow);
                context.SaveChanges();
            }
            catch
            {
                return false;
            }

            return true;
        }
Beispiel #3
0
 public bool updateBorrow(Borrow borrow)
 {
     try
     {
         context.Entry(borrow).State = EntityState.Modified;
         context.SaveChanges();
     }
     catch
     {
         return false;
     }
     return true;
 }