Example #1
0
        public ActionResult BorrowConfirmed(int id)
        {
            BooksViewModels bookViewModel = db.Books.Find(id);
            BorrowedBooks   borrowed;

            if (bookViewModel.Quantity == 0)
            {
                return(Json(new { success = false, responseText = "Nie można wypożyczyć wybranej książki!" }, JsonRequestBehavior.AllowGet));
            }
            else if (bookViewModel.Quantity < 2)
            {
                bookViewModel.Quantity        = 0;
                db.Entry(bookViewModel).State = EntityState.Modified;
            }
            else
            {
                bookViewModel.Quantity--;
                db.Entry(bookViewModel).State = EntityState.Modified;
            }

            borrowed = new BorrowedBooks();

            borrowed.UserEmail  = User.Identity.GetUserName();
            borrowed.BookID     = bookViewModel.ID;
            borrowed.BookTitle  = bookViewModel.Title;
            borrowed.BorrowDate = DateTime.Now;

            db.Borrowed.Add(borrowed);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Example #2
0
        public static bool borrowBook(int _id, int _customerId, int _bookId)
        {
            try
            {
                Customers customer = CustomerCRUD.getCustomer(_customerId);
                Books     book     = BookCRUD.getBook(_bookId);
                if ((book == null) || (book.state == 0) || (customer.money <= 0))
                {
                    return(false);
                }

                BookCRUD.updateState(book.id, 0); // 1-book in stock, 0-book not in stock
                BookCRUD.updateReturnDate(book.id, DateTime.Today.AddDays(14));

                LibraryLinqDataContext db       = new LibraryLinqDataContext();
                BorrowedBooks          borrowed = new BorrowedBooks();
                borrowed.id         = _id;
                borrowed.bookId     = book.id;
                borrowed.customerId = customer.id;
                db.BorrowedBooks.InsertOnSubmit(borrowed);
                db.SubmitChanges();
                return(true);
            }
            catch (Exception)
            {
                return(false);
            }
        }
Example #3
0
        public IHttpActionResult PutBorrowedBooks(int id, BorrowedBooks borrowedBooks)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != borrowedBooks.borrowed_book_id)
            {
                return(BadRequest());
            }

            db.Entry(borrowedBooks).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!BorrowedBooksExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
        public JsonResult AddBorrow(int SelectedBook = 0, int selectedBorrower = 0)
        {
            string status = "";

            if (selectedBorrower != 0 && SelectedBook != 0)
            {
                BorrowedBooks obj = new BorrowedBooks();
                obj.BookID     = SelectedBook;
                obj.BorrowerID = selectedBorrower;
                obj.BookStatus = true;

                try
                {
                    bool check = _repository.DecrementBooksNum(obj.BookID);
                    if (check)
                    {
                        _repository.Add(obj);
                        status = "Added";
                    }
                    else
                    {
                        status = "NotAdded";
                    }
                }catch (Exception ex)
                {
                }
            }
            return(Json(status, JsonRequestBehavior.AllowGet));
        }
Example #5
0
        public void OnPost()
        {
            if (!ModelState.IsValid)
            {
                return;
            }

            var borrower = this.Context.Borrowers.Find(this.BorrowerId);
            var bookId   = Convert.ToInt32(this.RouteData.Values["Id"]);
            var book     = this.Context.Books.Find(bookId);

            if (borrower == null || book == null)
            {
                return;
            }

            var borrowedBook = new BorrowedBooks()
            {
                BookId     = book.Id,
                BorrowerId = borrower.Id,
                StartDate  = this.StartDate,
                EndDate    = this.EndDate
            };

            this.Context.BorrowedBooks.Add(borrowedBook);
            this.Context.SaveChanges();
        }
Example #6
0
        public IHttpActionResult GetBorrowedBooks(int id)
        {
            BorrowedBooks borrowedBooks = db.BorrowedBooks.Find(id);

            if (borrowedBooks == null)
            {
                return(NotFound());
            }

            return(Ok(borrowedBooks));
        }
Example #7
0
 public bool BorrowBook(BorrowedBooks details)
 {
     try
     {
         DemoData.borrowedBooks.Add(details);
     }
     catch (Exception ex)
     {
         return false;
     }
     return true;
Example #8
0
        public IHttpActionResult PostBorrowedBooks([FromBody] BorrowedBooks borrowedBooks)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            db.BorrowedBooks.Add(borrowedBooks);
            db.SaveChanges();

            return(CreatedAtRoute("DefaultApi", new { id = borrowedBooks.borrowed_book_id }, borrowedBooks));
        }
Example #9
0
 public static int getCustomerId(int _id)
 {
     try
     {
         LibraryLinqDataContext db       = new LibraryLinqDataContext();
         BorrowedBooks          borrowed = db.BorrowedBooks.Where(p => p.id == _id).First();
         return(borrowed.customerId);
     }
     catch (Exception)
     {
         return(-1);
     }
 }
Example #10
0
        public ActionResult GiveBack(int id)
        {
            BorrowedBooks borrowed = db.Borrowed.Find(id);

            BooksViewModels book = db.Books.Find(borrowed.BookID);

            book.Quantity++;
            db.Entry(book).State = EntityState.Modified;
            db.Borrowed.Remove(borrowed);
            db.SaveChanges();

            return(RedirectToAction("AllBorrows"));
        }
Example #11
0
 public static BorrowedBooks getBorrowedBooks(int _bookId)
 {
     try
     {
         LibraryLinqDataContext db       = new LibraryLinqDataContext();
         BorrowedBooks          borrowed = db.BorrowedBooks.Where(p => p.bookId == _bookId).First();
         return(borrowed);
     }
     catch (Exception)
     {
         return(null);
     }
 }
Example #12
0
        public IHttpActionResult DeleteBorrowedBooks(int id)
        {
            BorrowedBooks borrowedBooks = db.BorrowedBooks.Find(id);

            if (borrowedBooks == null)
            {
                return(NotFound());
            }

            db.BorrowedBooks.Remove(borrowedBooks);
            db.SaveChanges();

            return(Ok(borrowedBooks));
        }
Example #13
0
        private void btnCheckTransaction_ItemClick(object sender, ItemClickEventArgs e)
        {
            ClearPanel();
            ss = SaveSender.CheckTransactionRecord;
            scMain.Panel2.Enabled   = true;
            scMain.SplitterPosition = 0;
            BorrowedBooks bb = new BorrowedBooks(ss);

            bb.Dock = DockStyle.Fill;
            scMain.Panel2.Controls.Add(bb);
            ClearCheckDoCheck(btnCheckTransaction);
            rpgReceiveTools.Visible   = false;
            rpgBorrowingTools.Visible = false;
            rpgBorrowingSave.Visible  = false;
        }
 protected void Page_Load(object sender, EventArgs e)
 {
     if (!IsPostBack)
     {
         DataTable dt = DatabaseHelper.Retrieve(@"
             select BorrowedId, BookCopy.Id, Title, ISBN, Author.FirstName+' '+Author.LastName as AuthorName, BranchName,
             Patron.FirstName+' '+Patron.LastName as PatronName, BorrowedDate, DueDate, ReturnDate
             from BookCopy join Book on (BookCopy.BookId = Book.Id) 
             join Author on (Book.AuthorId = Author.Id)
             join Library on (BookCopy.LibraryId = Library.Id)
             join Borrowed on (BookCopy.Id = Borrowed.BookCopyId)
             join Patron on (Borrowed.PatronId = Patron.LibraryCardNumber)
             order by DueDate desc
         ");
         BorrowedBooks.DataSource = dt.Rows;
         BorrowedBooks.DataBind();
     }
 }
Example #15
0
        public IActionResult OnPost(int id)
        {
            if (!ModelState.IsValid)
            {
                this.ViewData["ErrorMessage"] = "Please fill out the form";
                return(this.Page());
            }

            var book = this.Context.Books.FirstOrDefault(b => b.Id == id);

            if (book is null || book.StatusId == 2)
            {
                this.ViewData["ErrorMessage"] = "Book is invalid or already borrowed";
                return(this.Page());
            }

            if (this.ReturnDate != null && this.BorrowDate > this.ReturnDate)
            {
                this.ViewData["ErrorMessage"] = "Return Date must be later than Borrow Date";
                return(this.Page());
            }

            if (this.BorrowDate.ToShortDateString() == this.DateNow.ToShortDateString())
            {
                this.BorrowDate = this.DateNow;
            }

            var borrowedBook = new BorrowedBooks()
            {
                BookId     = id,
                BorrowerId = this.BorrowerId,
                BorrowDate = this.BorrowDate,
                ReturnDate = this.ReturnDate
            };


            book.StatusId = 2;
            this.Context.BorrowedBooks.Add(borrowedBook);
            this.Context.SaveChanges();

            return(this.RedirectToPage("/Index"));
        }
Example #16
0
 public void ApplyRequest(BorrowRequest request)
 {
     if (ApproveRequest(request))
     {
         Console.WriteLine(request.RequestNumber + " approved by " + Supervisor.ToString() + " for " + request.GetNumberOfDays() + "days");
         BorrowedBooks.Add(new KeyValuePair <DateTime, Book> (request.EndDay, request.BorrowedBook));
     }
     else
     {
         this.Supervisor = Supervisor.Supervisor;
         if (Supervisor == null)
         {
             Console.WriteLine("You cannot borrow a book for more than 60 days");
         }
         else
         {
             ApplyRequest(request);
         }
     }
 }
Example #17
0
 public static bool returnBook(int _bookId)
 {
     try
     {
         LibraryLinqDataContext db       = new LibraryLinqDataContext();
         BorrowedBooks          borrowed = db.BorrowedBooks.Where(p => p.bookId == _bookId).First();
         if (DateTime.Compare(DateTime.Today, (DateTime)BookCRUD.getBook(_bookId).returnDate) > 0)
         {
             TimeSpan days    = DateTime.Today - (DateTime)BookCRUD.getBook(_bookId).returnDate;
             int      penalty = -(BookCRUD.getBook(_bookId).penaltyCost *days.Days);
             CustomerCRUD.updateMoney(borrowed.customerId, penalty);
         }
         BookCRUD.updateState(_bookId, 1); // 1 - book back in stock
         db.BorrowedBooks.DeleteOnSubmit(borrowed);
         db.SubmitChanges();
         return(true);
     }
     catch (Exception)
     {
         return(false);
     }
 }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                DataTable dt;
                int       libraryCardNumber = int.Parse(CustomUser.Identity.Name);
                if (CustomUser.IsPatron)
                {
                    dt = DatabaseHelper.Retrieve(@"
                    select BorrowedId, BookCopy.Id, Title, ISBN, Author.FirstName+' '+Author.LastName as AuthorName, BranchName,
                    Patron.FirstName+' '+Patron.LastName as PatronName, BorrowedDate, DueDate, ReturnDate
                    from BookCopy join Book on (BookCopy.BookId = Book.Id) 
                    join Author on (Book.AuthorId = Author.Id)
                    join Library on (BookCopy.LibraryId = Library.Id)
                    join Borrowed on (BookCopy.Id = Borrowed.BookCopyId)
                    join Patron on (Borrowed.PatronId = Patron.LibraryCardNumber)
                    where ReturnDate is null and Patron.LibraryCardNumber = @LibraryCardNumber
                    order by DueDate desc
                ", new SqlParameter("@LibraryCardNumber", libraryCardNumber));
                }
                else
                {
                    dt = DatabaseHelper.Retrieve(@"
                    select BorrowedId, BookCopy.Id, Title, ISBN, Author.FirstName+' '+Author.LastName as AuthorName, BranchName,
                    Patron.FirstName+' '+Patron.LastName as PatronName, BorrowedDate, DueDate, ReturnDate
                    from BookCopy join Book on (BookCopy.BookId = Book.Id) 
                    join Author on (Book.AuthorId = Author.Id)
                    join Library on (BookCopy.LibraryId = Library.Id)
                    join Borrowed on (BookCopy.Id = Borrowed.BookCopyId)
                    join Patron on (Borrowed.PatronId = Patron.LibraryCardNumber)
                    where ReturnDate is null
                    order by DueDate desc
                ");
                }

                BorrowedBooks.DataSource = dt.Rows;
                BorrowedBooks.DataBind();
            }
        }
Example #19
0
        public static bool AddIntoBorrowed(string userId, int bookId, DateTime issueDate, DateTime returnDate)
        {
            bool          returned = false;
            BorrowedBooks borrowed = new BorrowedBooks(userId, bookId, issueDate, returnDate, returned);

            foreach (Book item in bookList)
            {
                if (item.Id == bookId)
                {
                    if (item.Available > 0)
                    {
                        item.Available -= 1;
                        borrowedList.Add(borrowed);
                        return(true);
                    }
                    else
                    {
                        return(false);
                    }
                }
            }
            return(false);
        }
Example #20
0
        private void ReceiveReturns()
        {
            BorrowedBooks bb = (BorrowedBooks)mf.scMain.Panel2.Controls[0];

            bb.ReceiveBookReturns();
        }
Example #21
0
        private void Approve()
        {
            BorrowedBooks bb = (BorrowedBooks)mf.scMain.Panel2.Controls[0];

            bb.ApproveBorrowRequest();
        }
Example #22
0
        private void Reject()
        {
            BorrowedBooks bb = (BorrowedBooks)mf.scMain.Panel2.Controls[0];

            bb.RejectBorrowRequest();
        }