public async Task <ActionResult> Create([FromBody] BorrowFormModel model) { if (!Roles.IsAdmin(User.Identity.Name) && !Roles.IsLibrarian(User.Identity.Name)) { return(Forbid()); } var entity = Mapper.Map <Borrow>(model); var user = Users.GetUser(model.UserId); var librarian = Users.GetUser(User.Identity.Name); var book = Books.GetBook(model.BookId); if (book == null || user == null || librarian == null) { return(NotFound()); } if (!Roles.IsLibrarian(librarian.UserID) && !librarian.IsAdmin) { Unauthorized(); } entity.Book = book; entity.Librarian = librarian; entity.User = user; entity.ReturnLibrarian = null; Borrows.Create(entity); return(CreatedAtAction(nameof(Fetch), new { borrowId = entity.BorrowId }, Mapper.Map <BorrowFormModel>(entity))); }
public async Task <ActionResult <bool> > CanWriteReview(string authorFullName, string bookTitle) { var borrow = Borrows.IsBorrowed(authorFullName, bookTitle, User.Identity.Name); var review = Reviews.IsReviewed(authorFullName, bookTitle, User.Identity.Name); return(borrow && !review); }
public ActionResult DeleteConfirmed(Guid id) { Borrows borrows = db.borrow.Find(id); db.borrow.Remove(borrows); db.SaveChanges(); return(RedirectToAction("Index")); }
public async Task <ActionResult <ProfileViewModel> > GetPropertiesForProfile() { ProfileViewModel entity = new ProfileViewModel(); var booksCount = Borrows.GetUserInactiveBooksCount(User.Identity.Name); var avgRating = Reviews.GetAvgUserRate(User.Identity.Name); entity.BooksCount = booksCount; entity.AvgRatings = avgRating; return(entity); }
public async Task <ActionResult <BorrowFormModel> > Fetch(int borrowId) { var entity = Borrows.GetBorrow(borrowId); if (entity == null) { return(NotFound()); } return(Mapper.Map <BorrowFormModel>(entity)); }
public ActionResult Edit([Bind(Include = "Borro_ID,Due_date,Return_date,Issue,Memb_ID,Book_id")] Borrows borrows) { if (ModelState.IsValid) { borrows.Return_date = borrows.Due_date.AddDays(15); db.Entry(borrows).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.Book_id = new SelectList(db.Book, "Book_ID", "Title", borrows.Book_id); ViewBag.Memb_ID = new SelectList(db.member, "Memb_ID", "Name", borrows.Memb_ID); return(View(borrows)); }
// GET: Borrows/Details/5 public ActionResult Details(Guid?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Borrows borrows = db.borrow.Find(id); if (borrows == null) { return(HttpNotFound()); } return(View(borrows)); }
// GET: Borrows/Edit/5 public ActionResult Edit(Guid?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Borrows borrows = db.borrow.Find(id); if (borrows == null) { return(HttpNotFound()); } ViewBag.Book_id = new SelectList(db.Book, "Book_ID", "Title", borrows.Book_id); ViewBag.Memb_ID = new SelectList(db.member, "Memb_ID", "Name", borrows.Memb_ID); return(View(borrows)); }
public async Task <ActionResult <BorrowListItemModel> > GetList([FromQuery] string search) { if (!Roles.IsAdmin(User.Identity.Name) && !Roles.IsLibrarian(User.Identity.Name)) { return(Forbid()); } var list = Borrows.GetList(search); if (list == null) { return(NotFound()); } return(Ok(Mapper.Map <IEnumerable <BorrowListItemModel> >(list))); }
public async Task <ActionResult> ReturnBook(int borrowId) { if (!Roles.IsLibrarian(User.Identity.Name) && !Roles.IsAdmin(User.Identity.Name)) { return(Forbid()); } var entity = Borrows.GetBorrow(borrowId); if (entity == null) { return(NotFound()); } entity.Status = BorrowStatus.Inactive; entity.ReturnLibrarian = Users.GetUser(User.Identity.Name); entity.ReturnTime = DateTime.UtcNow; Borrows.Update(entity); return(Accepted()); }
public async Task <Borrows> BorrowTransaction(BorrowRequest borrowRequest) { var borrowTransaction = new Borrows() { Readerid = borrowRequest.Readerid, Docid = borrowRequest.Docid, Libid = borrowRequest.Libid, Copyid = borrowRequest.Copyid, Duedate = borrowRequest.Duedate, Btime = borrowRequest.Btime, Position = borrowRequest.Position }; await _library.Borrows.AddAsync(borrowTransaction); var copy = _library.Copy.FirstOrDefault(x => x.Copyid == borrowTransaction.Copyid); if (copy != null) { copy.Available = false; } await _library.SaveChangesAsync(); return(borrowTransaction); }
/// <summary> /// 是否能够续借,如果能够续借则延期一个月 /// </summary> /// <param name="borrowId">借书id</param> /// <returns>是否能够续借</returns> public static bool ableToExtend(int borrowId) { var borrows = DbContext.DBstatic.Queryable <Borrows>().InSingle(borrowId); if (borrows.Renew == 2) { return(false); } var extendBorrows = new Borrows { Borrow_id = borrowId, Book_id = borrows.Book_id, Reader_id = borrows.Reader_id, State = borrows.State, Renew = borrows.Renew + 1, Borrow_Time = borrows.Borrow_Time, Return_Time = borrows.Return_Time, Expire_Time = borrows.Expire_Time.AddMonths(1) }; DbContext.DBstatic.Updateable(extendBorrows).ExecuteCommand(); return(true); }