private void ISSUE_A_BOOK() { BookTransaction theTranObject = new BookTransaction(); theTranObject.TransactionDate = DateTime.Parse(txt_TransactionDate.Text.ToString()); theTranObject.TransactionType = rbList_TransactionType.SelectedValue.ToString(); theTranObject.UserType = rbList_UserType.SelectedValue.ToString(); theTranObject.BookID = long.Parse(ddl_Books.SelectedValue.ToString()); theTranObject.AccessionNo = GetAccessionNumber(theTranObject.BookID); theTranObject.TitleAccessionNo = ddl_Books.SelectedItem.Text.ToString(); theTranObject.UserID = int.Parse(ddl_TransactionToFromUser.SelectedValue.ToString()); theTranObject.UserName = ddl_TransactionToFromUser.SelectedItem.Text.ToString().Trim(); theTranObject.ActualReturnDate = DateTime.Today; theTranObject.FineAmount = CalculateFineAmount(theTranObject); int ReturnValue = LibraryManagement.GetInstance.InsertBookTransaction_ISSUE(theTranObject); if (ReturnValue > 0) { string s = string.Format("TransactionRef#- {0}", ReturnValue); lbl_TheMessage.Text = ReadXML.GetSuccessMessage("OK_BOOK_ISSUED").Replace("{0}", ddl_Books.SelectedItem.Text).Replace("{1}", "<br/>" + ddl_TransactionToFromUser.SelectedItem.Text + "<br/>" + s); dialog_Message.Show(); RemoveItemFromBookList(theTranObject.BookID); // Remove the book from the list of books dropdwon list PageVar.BooksList = LibraryManagement.GetInstance.GetBooksList(true); // refesh the cache after the successful transaction } else { lbl_TheMessage.Text = ReadXML.GetFailureMessage("KO_BOOK_ISSUED"); dialog_Message.Show(); } }
/// <summary> /// Add a transaction to the list /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void btn_Add2List_Click(object sender, EventArgs e) { if (ddl_TransactionToFromUser.SelectedIndex == 0 || ddl_Books.SelectedIndex == 0) { lbl_TheMessage.Text = string.Format("Please select a BOOK and an user ({0}) to perform a transaction!", rbList_UserType.SelectedItem.Value.ToString().ToLower()); dialog_Message.Show(); return; } List <BookTransaction> bookList4Transaction = new List <BookTransaction>(); BookTransaction theTranObject = new BookTransaction(); theTranObject.TransactionDate = DateTime.Parse(txt_TransactionDate.Text.ToString()); theTranObject.TransactionType = rbList_TransactionType.SelectedValue.ToString(); theTranObject.UserType = rbList_UserType.SelectedValue.ToString(); theTranObject.BookID = long.Parse(ddl_Books.SelectedValue.ToString()); theTranObject.AccessionNo = GetAccessionNumber(theTranObject.BookID); theTranObject.TitleAccessionNo = ddl_Books.SelectedItem.Text.ToString(); theTranObject.UserID = int.Parse(ddl_TransactionToFromUser.SelectedValue.ToString()); theTranObject.UserName = ddl_TransactionToFromUser.SelectedItem.Text.ToString().Trim(); if (!rbList_TransactionType.SelectedItem.Value.ToString().ToUpper().Equals("ISSUE")) { theTranObject.ActualReturnDate = DateTime.Today; } theTranObject.FineAmount = CalculateFineAmount(theTranObject); bookList4Transaction.Add(theTranObject); gview_Books4Transaction.DataSource = bookList4Transaction; if (rbList_TransactionType.SelectedItem.Value.ToString().ToUpper().Equals("ISSUE")) { gview_Books4Transaction.Columns[2].Visible = false; gview_Books4Transaction.Columns[3].Visible = false; } else if (rbList_TransactionType.SelectedItem.Value.ToString().ToUpper().Equals("RECEIVE")) { gview_Books4Transaction.Columns[2].Visible = true; gview_Books4Transaction.Columns[3].Visible = true; } else if (rbList_TransactionType.SelectedItem.Value.ToString().ToUpper().Equals("MISSING")) { gview_Books4Transaction.Columns[2].HeaderText = "Missing Date"; gview_Books4Transaction.Columns[2].Visible = true; gview_Books4Transaction.Columns[3].HeaderText = "Missing Fine"; gview_Books4Transaction.Columns[3].Visible = true; } else if (rbList_TransactionType.SelectedItem.Value.ToString().ToUpper().Equals("DAMAGED")) { gview_Books4Transaction.Columns[2].HeaderText = "Damaged Date"; gview_Books4Transaction.Columns[2].Visible = true; gview_Books4Transaction.Columns[3].HeaderText = "Damaged Fine"; gview_Books4Transaction.Columns[3].Visible = true; } gview_Books4Transaction.DataBind(); //gview_Books4Transaction.Columns[3].Visible = theTranObject.TransactionType.Equals("RECEIVE") ? true : false; }
public static void Booksold(String bookname, int qty) { var book = db.books.SingleOrDefault(a => a.Name == bookname); if (book == null) { return; } book.Booksold(qty); { var booktransaction1 = new BookTransaction { TransactionDate = DateTime.Now, TransactionType = TypesofTransaction.purchase, Bookname = bookname, Quantity = qty, updatedQuantity = book.Quantity, bookid = book.BookId, }; db.booktransactions.Add(booktransaction1); db.SaveChanges(); } //public void PrintAllBooks() //{ // for (int i = 0; i < NumberOfBooks; i++) // { // Console.WriteLine(books[i].Name); // } //} }
public int InsertBookTransaction_Issue(BookTransaction bTran) { int RetValue = 0; using (SqlCommand InsertCommand = new SqlCommand()) { InsertCommand.CommandType = CommandType.StoredProcedure; InsertCommand.Parameters.Add(GetParameter("@ReturnValue", SqlDbType.Int, RetValue)).Direction = ParameterDirection.Output; InsertCommand.Parameters.Add(GetParameter("@TransactionDate", SqlDbType.DateTime, bTran.TransactionDate)); InsertCommand.Parameters.Add(GetParameter("@TransactionType", SqlDbType.VarChar, bTran.TransactionType)); InsertCommand.Parameters.Add(GetParameter("@Transaction2UserID", SqlDbType.Int, bTran.UserID)); InsertCommand.Parameters.Add(GetParameter("@Transaction2UserType", SqlDbType.VarChar, bTran.UserType)); InsertCommand.Parameters.Add(GetParameter("@TransactionFlag", SqlDbType.VarChar, "ISSUED")); InsertCommand.Parameters.Add(GetParameter("@TransactionBookID", SqlDbType.BigInt, bTran.BookID)); InsertCommand.Parameters.Add(GetParameter("@ExpectedReceiveDate", SqlDbType.DateTime, bTran.ExpetedReturnDate)); InsertCommand.CommandText = "[pICAS_Library_Book_Transactions_ISSUE]"; ExecuteStoredProcedure(InsertCommand); if (InsertCommand.Parameters[0].Value.ToString().Equals(string.Empty)) { RetValue = 0; } else { RetValue = int.Parse(InsertCommand.Parameters[0].Value.ToString()); } } return(RetValue); }
public String IssueBook(int bid, int mid) { BookTransaction ob = new BookTransaction(); transob = new TransactionImpl(); int noOfBooks = transob.getNoBooks(mid); if (noOfBooks < 2) { int tid = transob.getNewTid(); ob.TransactionId = tid; ob.MemberId = mid; ob.BookId = bid; ob.IssueDate = DateTime.Today; ob.IsLost = "N"; bool status = transob.insert(ob); if (status) { return("Success"); } else { return("Try Again !!"); } } else { return("Max Limit Reached"); } }
public Boolean insert(BookTransaction btObj) { OracleTransaction trans = null; try { con.Open(); trans = con.BeginTransaction(); cmd = new OracleCommand("insert into AAEK_TRANSACTION(TID,MID,BID,ISSUE_DATE,IS_LOST) values(:Tid,:Mid,:Bid,:Issuedt,:Islost)", con); cmd.Parameters.AddWithValue("Tid", OracleType.Number).Value = btObj.TransactionId; cmd.Parameters.AddWithValue("Mid", OracleType.Number).Value = btObj.MemberId; cmd.Parameters.AddWithValue("Bid", OracleType.Number).Value = btObj.BookId; //cmd.Parameters.AddWithValue("Returndt", OracleType.VarChar).Value = btObj.ReturnDate; cmd.Parameters.AddWithValue("Issuedt", OracleType.VarChar).Value = btObj.IssueDate; cmd.Parameters.AddWithValue("Islost", OracleType.VarChar).Value = btObj.IsLost; cmd.Transaction = trans; int row = cmd.ExecuteNonQuery(); trans.Commit(); con.Close(); if (row == 1) { return(true); } else { return(false); } } catch (Exception e) { trans.Rollback(); con.Close(); return(false); } }
public Boolean update(BookTransaction btObj) { OracleTransaction trans = null; try { con.Open(); trans = con.BeginTransaction(); cmd = new OracleCommand("update AAEK_TRANSACTION set RETURN_DATE=:Returndt,IS_LOST=:Islost where TID=:Tid", con); cmd.Parameters.AddWithValue("Tid", OracleType.Number).Value = btObj.TransactionId; cmd.Parameters.AddWithValue("Returndt", OracleType.VarChar).Value = btObj.ReturnDate; cmd.Parameters.AddWithValue("Islost", OracleType.Char).Value = btObj.IsLost; cmd.Transaction = trans; int row = cmd.ExecuteNonQuery(); trans.Commit(); con.Close(); if (row == 1) { return(true); } else { return(false); } } catch (Exception e) { trans.Rollback(); con.Close(); return(false); } }
/// <summary> /// Method to issue book to customer /// </summary> /// <param name="transaction"></param> /// <returns></returns> public bool IssueBook(BookTransaction transaction) { try { //Check if book is available IEnumerable <Librarian> librarians = unitOfWork.LibrarianRepository.Get(); var libraryId = librarians.Where(x => x.LibrarianID == transaction.LibrarianID).Select(x => x.LibraryID).First(); IEnumerable <BooksAtLibrary> booksAtLibrary = unitOfWork.BooksAtLibraryRepository.Get(); var numberOfCopies = booksAtLibrary.Where(x => x.LibraryID == Convert.ToInt32(libraryId) && x.ISBN == transaction.ISBN).Select(x => x.NumberOfCopies).First(); if (Convert.ToInt32(numberOfCopies) > 0) { //Insert a transaction row unitOfWork.BookTransactionRepository.Insert(transaction); //Update number of copies in booksAtLibrary var booksAtLibraryRow = booksAtLibrary.Where(x => x.LibraryID == Convert.ToInt32(libraryId)).FirstOrDefault(); booksAtLibraryRow.NumberOfCopies--; unitOfWork.BooksAtLibraryRepository.Update(booksAtLibraryRow); unitOfWork.Save(); return(true); } else { return(false); } } catch (NullReferenceException ex) { //ToDO:: Need to check how to handle exception return(false); } }
public void GetAllRecords() { using (var tx = session.BeginTransaction()) { Users user = null; UserDetails userdetail = null; ContactDetails contactdetail = null; Address address = null; BookTransaction booktxn = null; var results = session.QueryOver(() => user) .JoinAlias(x => x.UserDetails, () => userdetail) .JoinAlias(x => x.ContactDetails, () => contactdetail) .JoinAlias(x => x.Addresses, () => address) .JoinAlias(x => x.BookTransactions, () => booktxn) .SelectList(list => list .Select(() => user.UserID) .Select(() => userdetail.FirstName) .Select(() => userdetail.LastName) .Select(() => contactdetail.MobileNo) .Select(() => contactdetail.EmailAddress) .Select(() => address.AddressLine) .Select(() => address.CityName) .Select(() => address.StateName) .Select(() => booktxn.IssueDate) .Select(() => booktxn.ReturnDate)) .List <object[]>(); tx.Commit(); } }
public int InsertBookTransaction_Receive(BookTransaction bTran) { int ReturnValue = 0; using (SqlCommand InsertCommand = new SqlCommand()) { InsertCommand.CommandType = CommandType.StoredProcedure; InsertCommand.Parameters.Add(GetParameter("@ReturnValue", SqlDbType.Int, ReturnValue)).Direction = ParameterDirection.Output; InsertCommand.Parameters.Add(GetParameter("@TransactionID", SqlDbType.Int, bTran.TransactionID)); //InsertCommand.Parameters.Add(GetParameter("@TransactionType", SqlDbType.VarChar, bTran.TransactionType)); InsertCommand.Parameters.Add(GetParameter("@TransactionDate", SqlDbType.DateTime, bTran.TransactionDate)); InsertCommand.Parameters.Add(GetParameter("@BookID", SqlDbType.Int, bTran.BookID)); InsertCommand.Parameters.Add(GetParameter("@ReceivedFromUserID", SqlDbType.Int, bTran.UserID)); InsertCommand.Parameters.Add(GetParameter("@UserType", SqlDbType.VarChar, bTran.UserType)); InsertCommand.Parameters.Add(GetParameter("@ExpetedReturnDate", SqlDbType.DateTime, bTran.ExpetedReturnDate)); InsertCommand.Parameters.Add(GetParameter("@ActualReturnDate", SqlDbType.DateTime, bTran.ActualReturnDate)); InsertCommand.Parameters.Add(GetParameter("@FineAmount", SqlDbType.Money, bTran.FineAmount)); InsertCommand.Parameters.Add(GetParameter("@FineAmount", SqlDbType.Money, bTran.FineAmount)); InsertCommand.CommandText = "pICAS_Library_Book_Transactions_RECEIVE"; ExecuteStoredProcedure(InsertCommand); if (InsertCommand.Parameters[0].Value.ToString().Equals(string.Empty)) { ReturnValue = 0; } else { ReturnValue = int.Parse(InsertCommand.Parameters[0].Value.ToString()); } } return(ReturnValue); }
public BookTransaction serach(int Tid) { OracleTransaction trans = null; try { con.Open(); BookTransaction bt = new BookTransaction(); trans = con.BeginTransaction(); cmd = new OracleCommand("select * from AAEK_TRANSACTION where TID=:Tid", con); cmd.Parameters.AddWithValue("Tid", OracleType.Number).Value = btObj.TransactionId; cmd.Transaction = trans; reader = cmd.ExecuteReader(); while (reader.Read()) { bt.TransactionId = reader.GetInt32(0); bt.MemberId = reader.GetInt32(1); bt.BookId = reader.GetInt32(2); bt.IssueDate = Convert.ToDateTime(reader.GetString(3)); bt.ReturnDate = Convert.ToDateTime(reader.GetString(4)); bt.IsLost = reader.GetString(5); } trans.Commit(); con.Close(); return(bt); } catch (Exception e) { trans.Rollback(); con.Close(); return(null); } }
public ActionResult DeleteConfirmed(string id) { BookTransaction bookTransaction = db.BookTransactions.Find(id); db.BookTransactions.Remove(bookTransaction); db.SaveChanges(); return(RedirectToAction("Index")); }
// GET: Borrowbook public ActionResult create() { ViewBag.Customers = new SelectList(unit.Customermanager.GetAll().ToList(), "ID", "CustomerName"); BookTransaction bookTransaction = new BookTransaction(); bookTransaction.EndDate = DateTime.Now.Date; return(View(bookTransaction)); }
public void Update(BookTransaction transaction) { using (var conn = _db.CreateDbContext()) { conn.Entry(transaction).State = EntityState.Modified; conn.SaveChanges(); } }
public ActionResult Edit([Bind(Include = "BorrowingCard")] BookTransaction bookTransaction) { if (ModelState.IsValid) { db.Entry(bookTransaction).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(bookTransaction)); }
public async Task <bool> CheckOutBook(BookTransaction transaction) { bool success = true; string sql = @"INSERT INTO book_transaction ( CustomerId, BookId, CheckOut ) Select @CustomerId, @BookId, @CheckOut FROM DUAL WHERE NOT EXISTS ( SELECT TransactionId FROM book_transaction WHERE CustomerId = @CustomerId AND BookId = @BookId AND CheckIn IS NULL );"; string updateCopiesSql = @"UPDATE books SET AvailableCopies = AvailableCopies - 1 WHERE BookId = {0}"; updateCopiesSql = String.Format(updateCopiesSql, transaction.Book.BookId); var parameters = new { CustomerId = transaction.Customer.CustomerId, BookId = transaction.Book.BookId, CheckOut = transaction.CheckOut }; try { using (var conn = new MySqlConnection(connectionString)) { int rowsAffected = await conn.ExecuteAsync(sql, parameters).ConfigureAwait(false); if (rowsAffected == 0) { success = false; } else { rowsAffected = await conn.ExecuteAsync(updateCopiesSql).ConfigureAwait(false); } } } catch (Exception e) { success = false; Console.WriteLine(e.Message); } return(success); }
public ActionResult Create([Bind(Include = "BorrowingCard")] BookTransaction bookTransaction) { if (ModelState.IsValid) { db.BookTransactions.Add(bookTransaction); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(bookTransaction)); }
// GET: BookTransactions/Delete/5 public ActionResult Delete(string id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } BookTransaction bookTransaction = db.BookTransactions.Find(id); if (bookTransaction == null) { return(HttpNotFound()); } return(View(bookTransaction)); }
public async Task <Response <ReturnDateDto> > CreateBookTransaction([FromBody] BookTransaction transaction) { var response = new Response <ReturnDateDto>(); try { await _transactionManager.CreateBookTransaction(transaction); } catch (Exception ex) { response.ErrorList.Add(ex.Adapt <ApiException>()); } return(response); }
public void Delete(Book book, LibraryMember libraryMember) { BookTransaction transaction = new BookTransaction(); using (var conn = _db.CreateDbContext()) { transaction = conn.Transactions.Where(t => t.LibraryMemberId == libraryMember.Id && t.BookId == book.Id).FirstOrDefault(); if (transaction != null) { conn.Entry(transaction).State = EntityState.Deleted; conn.SaveChanges(); } } }
public JsonResult save(BookTransaction bookTransaction) { if (unit.BorrowBookManger.GetAll().Where(a => a.CustomerID == bookTransaction.CustomerID && a.EndDate == null).FirstOrDefault() == null) { var BorrowBook = unit.BorrowBookManger.GetAll().Where(a => a.BookID == bookTransaction.BookID && a.EndDate == null).Count(); var NumberOfCopies = unit.bookManager.GetById(bookTransaction.BookID).NumberOfCopies; if (BorrowBook >= NumberOfCopies) { return(Json(new { msg = "No Copy Of This Book Avilble Right Now", status = false }, JsonRequestBehavior.AllowGet)); } var result = unit.BorrowBookManger.Add(bookTransaction); return(result == null?Json(new { msg = "Some thing Wrong Happend Plesae try Again", status = false }, JsonRequestBehavior.AllowGet) : Json(new { msg = "Book Borrowed Successfuly", status = true }, JsonRequestBehavior.AllowGet)); } return(Json(new { msg = "This Customer Have Another Borrowed Book ", status = false }, JsonRequestBehavior.AllowGet)); }
private void btnLean_Click(object sender, EventArgs e) { var book = bookRepository.GetById(BookTransactionData.BookId); if (BookTransactionData.BookStatus == BookStatus.OnTheShelf) { BookTransaction bookTransaction = new BookTransaction { BookId = BookTransactionData.BookId, PersonId = Int32.Parse(cmbPerson.SelectedValue.ToString()), StartDate = dateTimeStartDate.Value, EndDate = dateTimeEndDate.Value }; var bookTransactionId = bookTransactionRepository.Post(bookTransaction); if (book != null) { book.LastTransactionId = bookTransactionId; book.Status = BookStatus.InUser; bookRepository.Put(book); } } else if (BookTransactionData.BookStatus == BookStatus.InUser) { if (book.LastTransactionId != null) { var bookTransaction = book.BookTransaction; bookTransaction.ReturnDate = dateTimeReturnDate.Value; bookTransaction.Amount = CalculatePenalty(); bookTransactionRepository.Put(bookTransaction); } if (book != null) { book.LastTransactionId = null; book.Status = BookStatus.OnTheShelf; bookRepository.Put(book); } } FrmBooks.frmBook.LoadGridData(); this.Close(); }
public void CheckoutBook(List <Book> books, LibraryMember libraryMember) { DateTime dateTime = DateTime.Now; foreach (Book b in books) { BookTransaction transaction = new BookTransaction { BookId = b.Id, LibraryMemberId = libraryMember.Id, CheckoutDate = dateTime, DueDate = dateTime.AddDays(14), }; b.CopiesLeft -= 1; _booksService.Update(b); Add(transaction); } }
public JsonResult Retrieve(BookTransaction bookTransaction) { var Book = unit.BorrowBookManger.GetAll().Where(a => a.CustomerID == bookTransaction.CustomerID && a.EndDate == null).FirstOrDefault(); if (Book != null) { Book.EndDate = bookTransaction.EndDate; if (unit.BorrowBookManger.Update(Book)) { return(Json(new { msg = "Book Retrieve Successfully", status = true }, JsonRequestBehavior.AllowGet)); } else { return(Json(new { msg = "There are an error Try Again", status = false }, JsonRequestBehavior.AllowGet)); } } else { return(Json(new { msg = "This User Dont Have Borrowed Book", status = false }, JsonRequestBehavior.AllowGet)); } }
public IHttpActionResult ReserveBook(int bookID, int userID) { try { BookStock bs = BookStockRepository.GetCacheBookStocks().FirstOrDefault(x => x.BookID == bookID && x.Status == BookStockStatus.Available); if (bs == null) { //The stocks of the book you have researched for is insufficient return(Json("0")); } int returnedCount = BookTransactionRepository.GetCacheBookTransactions().Where(x => x.UserID == userID && x.Status != BookTransactionStatus.Returned).Count(); if (returnedCount == 3) { return(Json("-2")); } BookTransaction bt = new BookTransaction(); bt.BookID = bookID; bt.DateOfReserved = DateTime.Now; bt.ExpirationOfReserveDate = DateTime.Now.AddDays(7); bt.UserID = userID; bt.Status = BookTransactionStatus.Reserved; BookTransactionRepository btr = new BookTransactionRepository(); btr.AddEntity(bt); bs.Status = BookStockStatus.Reserved; BookStockRepository bsr = new BookStockRepository(); bsr.UpdateEntity(bs); LogRepository.NewLog(bookID, userID); } catch (Exception) { return(Json("-1")); } return(Json("1")); }
private double CalculateFineAmount(BookTransaction b) { //TODO: calculate here how many days a user has taken or lend a book //TODO : read a setting for the fine amount per day int totalDays = 5; double fineAmountPerDay = 1.25; double totalFineAmount = 0; if (b.TransactionType.Equals("ISSUE")) { totalFineAmount = 0.00; } else if (b.TransactionType.Equals("RECEIVE")) { if (b.ActualReturnDate > b.ExpetedReturnDate) { totalFineAmount = totalDays * fineAmountPerDay; } } else if (b.TransactionType.Equals("MISSING")) { //TODO: GET THE BOOK PRICE FROM THE LIST // GET THE % OF FINE FOR MISSING BOOK // CALCUALTE TOTAL AMOUNT Book theBook = LibraryManagement.GetInstance.GetBooksList().Find(buk => buk.BookID == b.BookID); totalFineAmount = theBook.BookPrice * 2; } else if (b.TransactionType.Equals("DAMAGED")) { //totalFineAmount = totalDays * fineAmountPerDay * 200; //TODO: GET THE BOOK PRICE FROM THE LIST // GET THE % OF FINE FOR MISSING BOOK // CALCUALTE TOTAL AMOUNT Book theBook = LibraryManagement.GetInstance.GetBooksList().Find(buk => buk.BookID == b.BookID); totalFineAmount = theBook.BookPrice; } return(totalFineAmount); }
public async void CheckInBook() { if (!PerformCheckInValidation()) { DisplayErrorMessage(BookCheckInConditionError); return; } var transaction = new BookTransaction { Customer = new Customer { CustomerId = SuppliedCustomerId }, Book = new Book { BookId = SelectedBook.BookId }, CheckIn = DateTime.Now }; bool success = await bookManager.CheckInBook(transaction).ConfigureAwait(false); SuppliedCustomerId = 0; OnPropertyChanged("SuppliedCustomerId"); if (success) { ++SelectedBook.AvailableCopies; CollectionViewSource.GetDefaultView(this.Books).Refresh(); DisplayInfoMessage(BookCheckInSuccess, "Success!"); } else { DisplayErrorMessage(BookCheckInError); } }
public IHttpActionResult PostBook([FromBody] JObject transaction) { var issueTransaction = new BookTransaction() { ISBN = transaction.Value <string>("ISBN"), BorrowedDate = DateTime.Now, DueDate = DateTime.Now.AddDays(15), CustomerId = transaction.Value <int>("CustomerId"), LibrarianID = transaction.Value <int>("LibrarianId"), Status = ISSUED_STATUS, FineAmount = 0 }; bool isIssued = transactionService.IssueBook(issueTransaction); if (isIssued) { return(Ok(issueTransaction)); } else { return(Content(HttpStatusCode.NotFound, BOOK_NOT_AVAILABLE)); } }
//public static IEnumerable<Book>GetBookQTYbyName(string BookName, int qty) //{ // var book=books.Where(a => a.Name == BookName); //book.UpdateInventory(qty); //} public static void AddInventory(String bookname, int qty) { var book = db.books.SingleOrDefault(a => a.Name == bookname); if (book == null) { return; } book.AddInventory(qty); var booktransaction = new BookTransaction { TransactionDate = DateTime.Now, TransactionType = TypesofTransaction.purchase, Bookname = bookname, Quantity = qty, updatedQuantity = book.Quantity, bookid = book.BookId, }; db.booktransactions.Add(booktransaction); db.SaveChanges(); }
public async Task CreateBookTransaction(BookTransaction transaction) { #region Validate if member exists var member = _context.Members.SingleOrDefault(m => m.MemberId == transaction.MemberId); if (member == null) { _logger.LogError($"Member with id {transaction.MemberId} not found!"); throw new Exception("Member not found!"); } #endregion #region Validate if book with given Isbn Id exists in DB var book = _context.Books.SingleOrDefault(b => b.IsbnId == transaction.IsbnId); if (book == null) { _logger.LogError($"Book with IsbnId {transaction.IsbnId} not found!"); throw new Exception("Book not found!"); } #endregion #region Validate if there are enough books to lend if (book.Count < 1) { _logger.LogError($"Book with IsbnId {transaction.IsbnId} is out of stock!"); throw new Exception("Book out of stock!"); } #endregion transaction.StartDate = DateTime.Today; transaction.IsActive = true; _context.BookTransactions.Add(transaction); await _context.SaveChangesAsync(); #region Decrease Book Count book.Count -= 1; _context.Books.Update(book); await _context.SaveChangesAsync(); #endregion }