public ActionResult Edit([Bind(Include = "ID,UserID,BookID,BorrowTime,ReturnTime,ExpiredDays,IsReturn")] BorrowAndReturn borrowAndReturn) { if (ModelState.IsValid) { unitOfWork.context.Entry(borrowAndReturn).State = EntityState.Modified; unitOfWork.Save(); return(RedirectToAction("Index")); } return(View(borrowAndReturn)); }
public ActionResult Create([Bind(Include = "ID,StudentID,BookID,IsReturn")] BorrowAndReturnInput borrowAndReturnInput) { var borrowAndReturn = new BorrowAndReturn(); if (ModelState.IsValid) { //db.BorrowAndReturns.Add(borrowAndReturn); //db.SaveChanges(); var userInfoObj = unitOfWork.UserInfoRepository.Get() .Where(ctx => ctx.StudentID.Equals(borrowAndReturnInput.StudentID) == true) .ToList(); if (userInfoObj.Count() == 0) { ModelState.AddModelError("StudentID", "No student with this ID"); } var book = unitOfWork.BookRepository.Get() .Where(item => item.ID == borrowAndReturnInput.BookID) .ToList(); if (book.Count() == 0) { ModelState.AddModelError("BookID", "No book with this ID"); } else { if (book[0].IsAvaliable == true) { ModelState.AddModelError("BookID", "The book has been borrowed!"); } else { book[0].IsAvaliable = true; borrowAndReturn = new BorrowAndReturn { BookID = borrowAndReturnInput.BookID, UserID = userInfoObj[0].UserID, BorrowTime = DateTime.Now, IsReturn = false }; unitOfWork.BorrowAndReturnRepository.Insert(borrowAndReturn); unitOfWork.Save(); return(RedirectToAction("Index")); } } } return(View(borrowAndReturnInput)); }
public ActionResult Details(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } //BorrowAndReturn borrowAndReturn = db.BorrowAndReturns.Find(id); BorrowAndReturn borrowAndReturn = unitOfWork.BorrowAndReturnRepository.GetByID(id); if (borrowAndReturn == null) { return(HttpNotFound()); } return(View(borrowAndReturn)); }
public ActionResult ADDEmq(BorrowAndReturn borrow) { borrow.EStateID = 1; db.BorrowAndReturn.Add(borrow); if (db.SaveChanges() > 0) { Response.Write("<script>alert('添加成功')</script>"); return(RedirectToAction("SelBorrow")); } else { Response.Write("<script>alert('添加失败')</script>"); return(RedirectToAction("Index")); } }
public ActionResult UpEmp(DateTime RDate) { int id = int.Parse(Request["BID"]); BorrowAndReturn bt = db.BorrowAndReturn.Find(id); bt.EStateID = 2; bt.RDate = RDate; if (db.SaveChanges() > 0) { return(RedirectToAction("SelBorrow")); } else { return(RedirectToAction("Return")); } }