Пример #1
0
        public void BookIssueToStudent(int studentId, string BookBarcode)
        {
            var book    = _unitOfWorkLibraryService.BookRepository.GetBookByBarCode(BookBarcode);
            var student = _unitOfWorkLibraryService.StudentRepository.GetStudentById(studentId);

            if (student != null)
            {
                if (book != null)
                {
                    var issuedBook = new IssueBook
                    {
                        StudentId   = studentId,
                        BookId      = book.BookId,
                        BookBarCode = BookBarcode,
                        IssueDate   = DateTime.UtcNow
                    };
                    _unitOfWorkLibraryService.BookIssueRepositor.IssueBook(issuedBook);

                    var bookCount = book.CopyCount;
                    bookCount     -= 1;
                    book.CopyCount = bookCount;
                    _unitOfWorkLibraryService.BookIssueRepositor.DecreamentBookCountAfterIssue(book);
                    _unitOfWorkLibraryService.save();
                }
                else
                {
                    throw new InvalidOperationException("This book Is not available");
                }
            }
            else
            {
                throw new InvalidOperationException($"Student Id {studentId} Not a valid Student");
            }
        }
        public void BookReturn(int studentId, string bookBarcode)
        {
            var book    = _unitOfWorkLibraryService.BookRepository.GetBookByBarCode(bookBarcode);
            var student = _unitOfWorkLibraryService.StudentRepository.GetStudentById(studentId);

            if (student != null && book != null)
            {
                var returnBook = new ReturnBook
                {
                    StudentId   = studentId,
                    BookId      = book.BookId,
                    BookBarCode = bookBarcode,
                    ReturnDate  = DateTime.Now
                };

                _unitOfWorkLibraryService.ReturnBookRepository.ReturndBook(returnBook);

                var bookCount = book.CopyCount;
                bookCount     += 1;
                book.CopyCount = bookCount;

                _unitOfWorkLibraryService.ReturnBookRepository.IncreamentBookCountAfterReturn(book);
                _unitOfWorkLibraryService.save();
            }
            else
            {
                throw new InvalidOperationException(" Invalid  Operation ");
            }
        }
        public double CalculateFine(int studentId)
        {
            var bookIssuedate = _unitOfWorkLibraryService.BookIssueRepositor.GetBookIssueDate(studentId);
            var bokReturnDate = _unitOfWorkLibraryService.ReturnBookRepository.GetBookReturnDate(studentId);

            var dayCount = (bokReturnDate - bookIssuedate).Days - 1;

            if (dayCount > 7)
            {
                var    delayDays = dayCount - 7;
                double fine      = delayDays * 10;

                _unitOfWorkLibraryService.StudentRepository.SetStudentFine(studentId, fine);
                _unitOfWorkLibraryService.save();
                return(fine);
            }
            else
            {
                return(0);
            }
        }
 public void InsertBook(Book book)
 {
     _unitOfWorkLibraryService.BookRepository.EntryBook(book);
     _unitOfWorkLibraryService.save();
 }