Exemple #1
0
        ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////


        //Adds BookCirculation for a book / Owner is giving his book
        public BookCirculation InsertBookCirculation(BookRequest request)
        {
            try
            {
                var bookToBeBorrowed = db.Books.Find(request.BookRequested.BookId);
                var borrower         = db.Users.Find(request.RequestedBy.Id);

                BookCirculation circulation = new BookCirculation()
                {
                    RequestIdForThisCirculation = request.BookRequestId,
                    BookAssociated = bookToBeBorrowed,
                    Borrower       = borrower,
                    OwnerGaveBook  = true,
                };

                db.BookCirculations.Add(circulation);

                var requestForThisCirculation = db.BookRequests.Find(request.BookRequestId);
                requestForThisCirculation.RequestStatus = RequestStatuses.Accepted;

                db.SaveChanges();

                return(circulation);
            }
            catch (SqlException)
            {
                throw;
            }
        }
Exemple #2
0
        //Book returns to the owner
        public void OwnerReceivedBookBack(BookCirculation circulation)
        {
            try
            {
                var book = db.Books.Include(b => b.Owner).Where(b => b.BookId == circulation.BookAssociated.BookId).SingleOrDefault();
                var requestForThisCirculation = db.BookRequests.Find(circulation.RequestIdForThisCirculation);

                var borrower = requestForThisCirculation.RequestedBy;

                var circulationForThisBook = db.BookCirculations.Find(circulation.BookCirculationId);
                requestForThisCirculation.RequestStatus = RequestStatuses.Closed;

                book.AvailabilityStatus                  = true;
                book.Carrier                             = db.Users.Find(book.Owner.Id);
                book.BorrowerAskedToReturnThisBook       = false;
                circulationForThisBook.CirculationStatus = CirculationStatuses.Completed;
                circulationForThisBook.ReturnedOn        = DateTime.Now;
                db.SaveChanges();
            }
            catch (SqlException)
            {
                throw;
            }
        }