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); }
public bool addNewBorrow(Borrow borrow) { try { context.borrows.Add(borrow); context.SaveChanges(); } catch { return false; } return true; }
public bool updateBorrow(Borrow borrow) { try { context.Entry(borrow).State = EntityState.Modified; context.SaveChanges(); } catch { return false; } return true; }