Esempio n. 1
0
 /// <summary>
 /// New
 /// </summary>
 /// <param name="id">Book Id</param>
 /// <returns></returns>
 public ActionResult New(int id)
 {
     var q = bookService.Find(b => b.Id == id);
     BorrowInfo borrow = new BorrowInfo();
     ViewBag.BookTitle = q.Title;
     borrow.BookId = q.Id;
     borrow.UserName = LoginUser.UserName;
     return View(borrow);
 }
Esempio n. 2
0
 public bool Add(BorrowInfo model)
 {
     bool result = false;
     TransactionOptions transactionOption = new TransactionOptions();
     //isolation level
     transactionOption.IsolationLevel = IsolationLevel.ReadCommitted;
     // over time
     transactionOption.Timeout = new TimeSpan(0, 0, 60);
     using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required, transactionOption))
     {
         try
         {
             //minus 1 stock qty,if qty=0,the book can't be borrowed
             var currentBook = bookDal.Find(b => b.Id == model.BookId);
             if (currentBook == null || currentBook.StockQty == 0)
                 return false;
             currentBook.StockQty = currentBook.StockQty - 1;
             bookDal.Update(currentBook);
             //add one borrow info record
             model.MDate = DateTime.Now;
             model.IsActive = true;
             model.MUser = 1;
             borrowDal.Add(model);
             scope.Complete();
             result = true;
         }
         catch(Exception ex)
         {
             throw ex;
         }
         finally
         {
             scope.Dispose();
         }
     }
     return result;
 }
Esempio n. 3
0
        public ActionResult New(BorrowInfo borrow)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    borrowService.Add(borrow);
                }
                catch(Exception ex)
                {
                    ModelState.AddModelError("error", ex.Message);
                }
            }

            //return RedirectToAction("List", "Book");
            return View();
        }