コード例 #1
0
        /// <summary>Book has only DOM domains.</summary>
        /// <param name="book">The book.</param>
        /// <returns>a a</returns>
        public bool BookHasOnlyDOMDomains(Book book)
        {
            Log.Info("Checking if book has only DOM domains.");
            SQLConfigurationDataService configuration = new SQLConfigurationDataService();

            if (book.Domains.Count <= configuration.GetConfiguration("MaxDOMBook").Value)
            {
                Log.Info("Book has only DOM domains.");
                return(true);
            }

            Log.Info("Book has more than DOM domains.");
            return(false);
        }
コード例 #2
0
        /// <summary>Determines whether [has fewer than NMC books borrowed] [the specified reader].</summary>
        /// <param name="reader">The reader.</param>
        /// <returns>
        /// <c>true</c> if [has fewer than NMC books borrowed] [the specified reader]; otherwise, <c>false</c>.</returns>
        public bool HasFewerThanNMCBooksBorrowed(Reader reader)
        {
            Log.Info("Checking if reader has fewer thank NMC books borrowed at the moment.");
            IConfigurationDataService cds = new SQLConfigurationDataService();

            using (var context = new LibraryContext())
            {
                Reader currentReader = context.Readers.Where(r => r.ID == reader.ID).SingleOrDefault();

                if (currentReader.Books.Count < cds.GetConfiguration("NrMaxBooksBorrowed").Value)
                {
                    Log.Info("Reader has fewer thank NMC books borrowed at the moment.");
                    return(true);
                }
            }

            Log.Info("Reader has more thank NMC books borrowed at the moment.");
            return(false);
        }
コード例 #3
0
        /// <summary>Determines whether this instance [can borrow more than d books from same domain] the specified domain.</summary>
        /// <param name="editions">The editions.</param>
        /// <returns>
        /// <c>true</c> if this instance [can borrow more than d books from same domain] the specified domain; otherwise, <c>false</c>.</returns>
        public bool MoreThanDBooksFromSameDomain(List <Edition> editions)
        {
            Log.Info("Checking if the books the reader tries to borrow are from the same domain.");
            IDomainDataService        dds = new SQLDomainDataService();
            IConfigurationDataService cds = new SQLConfigurationDataService();

            IDictionary <int, int> domainApparitions = new Dictionary <int, int>();

            using (var context = new LibraryContext())
            {
                foreach (Edition ed in editions)
                {
                    Edition currentEdition = context.Editions.Where(e => e.ID == ed.ID).Single();

                    foreach (Domain dom in currentEdition.Book.Domains)
                    {
                        var id = dds.GetRootDomain(dom).ID;

                        if (!domainApparitions.ContainsKey(id))
                        {
                            domainApparitions.Add(id, 1);
                        }
                        else
                        {
                            domainApparitions[id]++;
                        }
                    }
                }

                foreach (var counter in domainApparitions.Values)
                {
                    if (counter > cds.GetConfiguration("MaxBooksFromSameDomain").Value)
                    {
                        Log.Info("The books the reader tries to borrow are not from the same domain.");
                        return(false);
                    }
                }
            }

            Log.Info("The books the reader tries to borrow are from the same domain.");
            return(true);
        }
コード例 #4
0
        /// <summary>Borrows the books.</summary>
        /// <param name="reader">The reader.</param>
        /// <param name="editions">The editions.</param>
        public void BorrowBooks(Reader reader, List <Edition> editions)
        {
            Log.Info("Reader " + reader.Name + " borrowing books");

            IConfigurationDataService cds = new SQLConfigurationDataService();

            using (var context = new LibraryContext())
            {
                if (editions.Count <= cds.GetConfiguration("MaxBooksOneBorrow").Value&&
                    (editions.Count <= 3 || this.OnBorrowMoreThanThreeBooksMinTwoDiffDomains(editions)) &&
                    this.MoreThanDBooksFromSameDomain(editions))
                {
                    foreach (Edition ed in editions)
                    {
                        this.BorrowBook(reader, ed);
                    }
                }
            }

            Log.Info("Reader " + reader.Name + " successfully borrowed books");
        }