public static BookToRentModel GetViewMode(BookInfo bookInfo, UserInfo userInfo) { BookToRentModel model = new BookToRentModel(); model.ID = bookInfo.ID; model.BookName = bookInfo.BookName; string displayName = string.Empty; string authorNameValue = string.Empty; model.AuthorName = BookManage.BookModel.GetAuthorName(bookInfo, out displayName, out authorNameValue); model.AuthorName = displayName; model.ISBN = bookInfo.ISBN; if (bookInfo.PublisherInfo != null) { model.PublisherName = bookInfo.PublisherInfo.PublisherName; } model.Publish_Date = bookInfo.Publish_Date.ToString(UntityContent.IOSDateTemplate); model.Avaliable_Inventory = Convert.ToInt32(bookInfo.Avaliable_Inventory).ToString(); model.Max_Inventory = Convert.ToInt32(bookInfo.Max_Inventory).ToString(); model.Book_Description = "Waiting for DB......"; int canBorrowCount = Unity.Helper.DataUnity.GetCanBorrowCount(userInfo); IBorrowAndReturnRecordInfoDataProvider iBorrowAndReturnRecordInfoDataProvider = new BorrowAndReturnRecordInfoDataProvider(); int alreadyBorrowedCount = iBorrowAndReturnRecordInfoDataProvider.GetBooksInHandCount(userInfo); model.Can_Borrow_Count = canBorrowCount.ToString(); if (alreadyBorrowedCount >= canBorrowCount) { model.Still_Can_Borrow_Count = Convert.ToInt32(0).ToString(); model.Still_Can_Borrow = false; } else { model.Still_Can_Borrow_Count = (canBorrowCount - alreadyBorrowedCount).ToString(); model.Still_Can_Borrow = true; } return model; }
public string RequstBook(string q) { try { int id = Convert.ToInt32(q); BookInfo bookInfo = this.IBookInfoDataProvider.GetBookInfoByID(id); BookDetailInfo bookDetailInfo = this.IBookDetailInfoDataProvider.GetAvaliableBookDetailInfoByBookInfoID(id); if (bookDetailInfo == null) { Exception ex = new Exception("There is no avaliable Book!"); throw (ex); } else { BookToRentModel model = new BookToRentModel(); BorrowAndReturnRecordInfo borrowAndReturnRecordInfo = new BorrowAndReturnRecordInfo(); BookModel bookModel = new BookModel(); ProcessRecord processRecord = model.GetEntity(id, this.LoginUser(), out borrowAndReturnRecordInfo, out bookDetailInfo, out bookModel); this.IBorrowAndReturnRecordInfoDataProvider.Add(borrowAndReturnRecordInfo); this.IProcessRecordDataProvider.Add(processRecord); this.IBookDetailInfoDataProvider.Update(bookDetailInfo); this.IBookInfoDataProvider.Update(bookModel.GetEntity()); } } catch (Exception ex) { return ex.Message; } return "true"; }