Ejemplo n.º 1
0
 public BookCopy FindById(object Id)
 {
     using (var bookCopyRepo = new BookCopyRepository())
     {
         return(bookCopyRepo.FindById(Id));
     }
 }
Ejemplo n.º 2
0
        // GET: Member/AddBook
        public ActionResult Index(int IdBook)
        {
            int IdReader = SessionUtils.ConnectedUser.IdReader;

            DateTime today = DateTime.Today;
            BookReservationRepository BR = new BookReservationRepository(ConfigurationManager.ConnectionStrings["CnstrDev"].ConnectionString);

            BookCopyRepository Bcr = new BookCopyRepository(ConfigurationManager.ConnectionStrings["CnstrDev"].ConnectionString);
            int nbBookAvailable    = Bcr.getNbBookCopy(IdBook);

            if (nbBookAvailable == 0)
            {
                SessionUtils.ErrorReservation = "We couldn't save this book to you! No copy of this book available for the moment.";
                return(RedirectToAction("Index", new { controller = "Home", area = "" }));
            }

            else
            {
                int            IdBookCopyReserved = BR.InsertWithBook(SessionUtils.ConnectedUser.IdReader, IdBook, today);
                BookRepository br = new BookRepository(ConfigurationManager.ConnectionStrings["CnstrDev"].ConnectionString);
                Book           B  = br.GetOne(IdBook);
                BookModel      Bm = MapToDbModels.BookToBookModel(B);
                return(View(Bm));
            }
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Constructor
 /// </summary>
 public LoanService()
 {
     loanRepository     = RepositoryFactory.Loans;
     memberRepository   = RepositoryFactory.Members;
     bookCopyRepository = RepositoryFactory.BookCopys;
     bookRepository     = RepositoryFactory.Books;
 }
Ejemplo n.º 4
0
        public IEnumerable <Payable> GetReturnedBooksPayables()
        {
            ICollection <Payable> Payables = new List <Payable>();

            using (var bookCopyRepo = new BookCopyRepository())
                using (var transRepo = new BookTransactionInfoRepository())
                    using (var userRepo = new LibraryUserRepository())
                    {
                        var trans = transRepo.GetReturnedBooksPayableTransactions();
                        foreach (var tran in trans)
                        {
                            Payable p = new Payable();

                            p.BookCopy        = bookCopyRepo.FindById(tran.BookCopyId);
                            p.TransactionInfo = tran;
                            p.LibraryUserId   = tran.LibraryUserId;
                            p.AmountToPay     = tran.AmountToPay;
                            p.BookInvolved    = _BookCopyService.GetBookInfo(tran.BookCopyId).BookTitle;
                            p.UserInvolved    = userRepo.FindById(tran.LibraryUserId).Fullname;

                            Payables.Add(p);
                        }
                        return(Payables);
                    }
        }
Ejemplo n.º 5
0
        public SaveBookResult Save(BookCopyViewModel viewModel, UserSessionObject user)
        {
            var result = new SaveBookResult();

            BookCopyDomainModelBuilder builder = BuilderResolverService.Get <BookCopyDomainModelBuilder, BookCopyViewModel>(viewModel);

            Constructor.ConstructDomainModelData(builder);
            BookCopyData domainModel = builder.GetDataModel();

            if (viewModel.Id == 0)
            {
                domainModel.RefUserCreatedBy = user.UserId;
            }

            int id = BookCopyRepository.SaveData(domainModel);

            if (id != 0)
            {
                BookViewModel bookViewModel = Get(viewModel.BookId);
                bookViewModel.NumOfAvailableCopies = bookViewModel.NumOfAvailableCopies + 1;
                SaveBookResult updateResult = Save(bookViewModel, user);

                if (updateResult.Success)
                {
                    result = new SaveBookResult(id, viewModel.BookAuthorAndTitle,
                                                "Successfully added copy of book " + viewModel.BookAuthorAndTitle);
                }
            }

            return(result);
        }
Ejemplo n.º 6
0
        private void RefreshBooksListBox()
        {
            _studentRepository     = new StudentRepository();
            _bookRepository        = new BookRepository();
            _bookCopyRepository    = new BookCopyRepository();
            _borrowEventRepository = new BorrowEventRepository();
            BooksListBox.Items.Clear();

            var studentBooksBorrowed = _borrowEventRepository.GetBorrowEventsByStudent(StudentComboBox.Text).ToList();

            var readOnlyBookCopies =
                _bookCopyRepository.GetAllBookCopies().Where(bookCopy => bookCopy.Status == BookStatus.ReadOnly)
                .GroupBy(bookCopy => bookCopy.Book.ToString()).ToList();

            var readOnlyBooks = new List <Book>();

            foreach (var bookCopy in readOnlyBookCopies)
            {
                readOnlyBooks.Add(_bookRepository.GetAllBooks().First(book => book.ToString() == bookCopy.Key));
            }

            foreach (var book in _bookRepository.GetAllBooks().OrderBy(book => book.Name).ThenBy(book => book.Publisher.ToString()))
            {
                if (studentBooksBorrowed.Any(borrowEvent => borrowEvent.BookCopy.Book.ToString() == book.ToString()) ||
                    readOnlyBooks.Contains(book))
                {
                    continue;
                }
                BooksListBox.Items.Add(book);
            }
        }
Ejemplo n.º 7
0
 public LoanService(RepositoryFactory repFactory, ReturnedLoanService returnedLoanService)
 {
     loanRepository         = repFactory.CreateLoanRepository();
     returnedLoanRepository = repFactory.CreateReturnedLoanRepository();
     bookCopyRepository     = repFactory.CreateBookCopyRepository();
     _returnedLoanService   = returnedLoanService;
 }
Ejemplo n.º 8
0
 private void DeleteEachBookCopy(List <BookCopyData> bookCopies, UserSessionObject user)
 {
     foreach (var item in bookCopies)
     {
         BookCopyRepository.DeleteById(item.Id, user.UserId);
     }
 }
Ejemplo n.º 9
0
        public DeleteBookResult DeleteCopy(int bookCopyId, UserSessionObject user)
        {
            var          result       = new DeleteBookResult();
            BookCopyData bookCopyData = BookCopyRepository.GetDataById(bookCopyId);

            if (bookCopyData != null)
            {
                List <BookCopyData> list = new List <BookCopyData>()
                {
                    bookCopyData
                };
                if (CheckIfAnyCopyIsBorrowed(list))
                {
                    result.Message = "Book copy is currently borrowed. Can't be deleted.";
                }
                else
                {
                    BookCopyRepository.DeleteById(bookCopyData.Id, user.UserId);

                    BookData book = BookRepository.GetDataById(bookCopyData.BookId);
                    book.NumOfAvailableCopies = book.NumOfAvailableCopies - 1;
                    BookRepository.SaveData(book);

                    result = new DeleteBookResult(book.Id, book.BookAuthorAndTitle, bookCopyData.Id);
                }
            }
            else
            {
                result.Message = "Please select book copy for delete.";
            }

            return(result);
        }
Ejemplo n.º 10
0
 public IEnumerable <BookCopy> GetBorrowedBooks()
 {
     using (var bookCopyRepo = new BookCopyRepository())
     {
         return(bookCopyRepo.Where(b => b.IsBorrowed == true));
     }
 }
Ejemplo n.º 11
0
 /// <summary>
 /// Constructor for servicefactory
 /// </summary>
 public ServiceFactory()
 {
     bookCopyRepo = repoFactory.GetBookCopyrepository();
     bookRepo     = repoFactory.GetBookRepository();
     authorRepo   = repoFactory.GetAuthorRepository();
     loanRepo     = repoFactory.GetLoanRepository();
     memberRepo   = repoFactory.GetMemberRepository();
 }
Ejemplo n.º 12
0
 public BookInfo GetBookInfo(Guid bookCopyId)
 {
     using (var bookInfoRepo = new BookInfoRepository())
         using (var bookCopyRepo = new BookCopyRepository())
         {
             var bookCopy = bookCopyRepo.FindById(bookCopyId);
             return(bookInfoRepo.Where(b => b.Id.Equals(bookCopy.BookInfoId)).FirstOrDefault());
         }
 }
Ejemplo n.º 13
0
        private void copiesOfBooksToolStripMenuItem_Click(object sender, EventArgs e)
        {
            BookCopyRepository bookCopyRepository;

            bookCopyRepository = new BookCopyRepository();
            List <BookCopy> bookCopies = bookCopyRepository.Get();

            dataGridView1.DataSource = bookCopies;
        }
Ejemplo n.º 14
0
 private void RefreshBooksListBox()
 {
     _bookRepository     = new BookRepository();
     _bookCopyRepository = new BookCopyRepository();
     BooksListBox.Items.Clear();
     foreach (var book in _bookRepository.GetAllBooks().OrderBy(book => book.Name).ThenBy(book => book.Publisher.ToString()))
     {
         BooksListBox.Items.Add(book);
     }
 }
Ejemplo n.º 15
0
        public List <BookCopyViewModel> GetAvailableCopies()
        {
            var viewModels   = new List <BookCopyViewModel>();
            var domainModels = new List <BookCopyData>();

            domainModels = BookCopyRepository.GetAvailableCopies();
            viewModels   = ConvertDataToViewModels(domainModels);

            return(viewModels);
        }
Ejemplo n.º 16
0
        public List <BookCopyViewModel> GetAllCopies(bool active)
        {
            var viewModels   = new List <BookCopyViewModel>();
            var domainModels = new List <BookCopyData>();

            domainModels = active ? BookCopyRepository.GetAllActiveData() : BookCopyRepository.GetAllData();
            viewModels   = ConvertDataToViewModels(domainModels);

            return(viewModels);
        }
Ejemplo n.º 17
0
 public AddBorrowEventForm()
 {
     _studentRepository     = new StudentRepository();
     _bookRepository        = new BookRepository();
     _bookCopyRepository    = new BookCopyRepository();
     _borrowEventRepository = new BorrowEventRepository();
     InitializeComponent();
     LoadStudentComboBox();
     DateOfRentPicker.MaxDate = DateTime.Now.Date;
 }
Ejemplo n.º 18
0
 public AddBookForm()
 {
     _bookRepository      = new BookRepository();
     _authorRepository    = new AuthorRepository();
     _publisherRepository = new PublisherRepository();
     _bookCopyRepository  = new BookCopyRepository();
     InitializeComponent();
     LoadGenreComboBox();
     LoadAuthorComboBox();
     LoadPublisherComboBox();
 }
        public LibraryTransactionBase(BookCopy bookCopy)
        {
            BookCopy = bookCopy;

            using (var bookCopyRepo = new BookCopyRepository())
            {
                BookTag         = BookCopy.BookTagShort;
                BookTitle       = bookCopyRepo.BookInfoOf(BookCopy).BookTitle;
                TransactionDate = DateTime.Now;
            }
        }
        public async Task DeleteAsyncBookTest_ValidBookCopyId_HappyPath()
        {
            //arrange
            _access.WithDeleteResult(true);

            _sut = new BookCopyRepository(_access.Object, _mapper.Object);

            //act
            var result = await _sut.DeleteAsync(BookCopyTestUtils.GenerateValidBookCopy().Id);

            //assert
            Assert.IsTrue(result);
            _access.Verify(m => m.DeleteWithIdAsync(It.IsAny <int>()), Times.Once);
        }
        public async Task DeleteAsyncBookTest_NullBookCopy_ExceptionalCase()
        {
            //arrange
            _access.WithDeleteResult(true);

            _sut = new BookCopyRepository(_access.Object, _mapper.Object);

            //act
            var result = await _sut.DeleteAsync(null);

            //assert
            Assert.IsFalse(result);
            _access.Verify(m => m.DeleteWithIdAsync(It.IsAny <int>()), Times.Never);
        }
Ejemplo n.º 22
0
        public BookCopyViewModel GetCopy(int?bookCopyId)
        {
            var viewModel = new BookCopyViewModel();

            if (bookCopyId.HasValue)
            {
                BookCopyData             domainModel = BookCopyRepository.GetDataById(bookCopyId.Value);
                BookCopyViewModelBuilder builder     = BuilderResolverService.Get <BookCopyViewModelBuilder, BookCopyData>(domainModel);
                Constructor.ConstructViewModelData(builder);
                viewModel = builder.GetViewModel();
            }

            return(viewModel);
        }
Ejemplo n.º 23
0
        private void DeleteCopiesButton_Click(object sender, EventArgs e)
        {
            if (BooksListBox.CheckedItems.Count == 0)
            {
                var selectError = new ErrorForm("You must select a book to delete copies!");
                selectError.ShowDialog();
                return;
            }

            if (string.IsNullOrWhiteSpace(NumberOfCopiesToDeleteTextBox.Text))
            {
                return;
            }

            var selected = BooksListBox.SelectedItem.ToString();
            var deletedAllAvailableCopies = false;


            for (var i = 0; i < int.Parse(NumberOfCopiesToDeleteTextBox.Text); i++)
            {
                var copyToDelete = _bookCopyRepository.GetAllBookCopies().FirstOrDefault(bookCopy =>
                                                                                         bookCopy.Book.ToString() == selected && bookCopy.Status == BookStatus.Available);

                if (copyToDelete == null)
                {
                    deletedAllAvailableCopies = true;
                    break;
                }
                _bookCopyRepository.TryDelete(copyToDelete);
            }

            if (_bookCopyRepository.GetAllBookCopies().FirstOrDefault(bookCopy => bookCopy.Book.ToString() == selected) == null)
            {
                _bookRepository     = new BookRepository();
                _bookCopyRepository = new BookCopyRepository();
                var checkedBook = _bookRepository.GetAllBooks()
                                  .FirstOrDefault(book => book.ToString() == selected);

                _bookRepository.TryDelete(checkedBook);
            }
            else if (deletedAllAvailableCopies)
            {
                var borrowedError = new ErrorForm("Borrowed copies cannot be deleted until returned!");
                borrowedError.ShowDialog();
            }

            NumberOfCopiesToDeleteTextBox.Text = "";
            RefreshBookInfoListBox();
            RefreshBooksListBox();
        }
        public async Task GetAllAsync_EmptyEnumerable_HappyPath()
        {
            //arrange
            _access.WithGetAllAsyncResult(new List <IBookCopyMap>());
            _mapper.WithUnmap(BookCopyTestUtils.GenerateValidBookCopy());

            _sut = new BookCopyRepository(_access.Object, _mapper.Object);

            //act
            var result = await _sut.GetAllAsync();

            //assert
            Assert.IsNotNull(result);
            _access.Verify(m => m.SelectAllAsync(), Times.Once);
        }
        public async Task InsertAsyncTest_ValidBookCopy_HappyPath()
        {
            //arrange
            _mapper.WithMap(BookCopyMapTestUtils.GenerateValidBookCopyMap());
            _access.WithInsertResult(true);

            _sut = new BookCopyRepository(_access.Object, _mapper.Object);

            //act
            var result = await _sut.InsertAsync(BookCopyTestUtils.GenerateValidBookCopy());

            //assert
            Assert.IsTrue(result);
            _access.Verify(m => m.InsertOneAsync(It.IsAny <BookCopyMap>()), Times.Once);
        }
Ejemplo n.º 26
0
        public RelationUserBookCopyViewModel CreateLoanModel(int bookCopyId)
        {
            BookCopyData copy = BookCopyRepository.GetDataById(bookCopyId);
            BookData     book = BookRepository.GetDataById(copy.BookId);

            var viewModel = new RelationUserBookCopyViewModel
            {
                BookCopyId       = bookCopyId,
                BookFullName     = book.BookAuthorAndTitle,
                DateOfIssue      = DateTime.Now,
                DateDueForReturn = DateTime.Now.AddDays(14)
            };

            return(viewModel);
        }
        public async Task GetAllAsync_NullEnumerable_ExceptionalCase()
        {
            //arrange
            _access.WithGetAllAsyncResult(null);
            _mapper.WithUnmap(BookCopyTestUtils.GenerateValidBookCopy());

            _sut = new BookCopyRepository(_access.Object, _mapper.Object);

            //act
            var result = await _sut.GetAllAsync();

            //assert
            Assert.IsNull(result);
            _access.Verify(m => m.SelectAllAsync(), Times.Once);
        }
        public async Task InsertAsyncTest_NullBookCopyMap_ExceptionalCase()
        {
            //arrange
            _mapper.WithMap(null);
            _access.WithInsertResult(true);

            _sut = new BookCopyRepository(_access.Object, _mapper.Object);

            //act
            var result = await _sut.InsertAsync(BookCopyTestUtils.GenerateValidBookCopy());

            //assert
            Assert.IsFalse(result);
            _access.Verify(m => m.InsertOneAsync(It.IsAny <BookCopyMap>()), Times.Never);
        }
Ejemplo n.º 29
0
        private void RefreshBooksListBox()
        {
            _bookCopyRepository    = new BookCopyRepository();
            _borrowEventRepository = new BorrowEventRepository();
            BooksListBox.Items.Clear();

            var borrowedBookCopiesByBook = _bookCopyRepository.GetAllBookCopies()
                                           .Where(bookCopy => bookCopy.Status == BookStatus.Borrowed)
                                           .GroupBy(bookCopy => bookCopy.Book.ToString());

            foreach (var bookCopy in borrowedBookCopiesByBook)
            {
                BooksListBox.Items.Add(bookCopy.Key);
            }
        }
        public async Task GetWithIsbnAsync_NullIsbn_Fails()
        {
            //arrange
            var invalidBooks = BookCopyMapTestUtils.GenerateValidBookCopyMapEnumerable();

            _access.WithGetByIsbnAsyncResult(invalidBooks);

            _sut = new BookCopyRepository(_access.Object, _mapper.Object);

            //act
            var result = await _sut.GetByIsbnAsync(null);

            //assert
            _access.Verify(m => m.GetByIsbnAsync(It.IsAny <string>()), Times.Never);
            Assert.IsNull(result);
        }