Пример #1
0
        /// <summary>
        /// Compares start date and end date to already lend out movie, if the dates interferes with each other, numberOfCopies -= 1
        /// </summary>
        /// <param name="movieId">the movie to borrow</param>
        /// <param name="numberOfCopies">number of copies of the chosen movie</param>
        /// <param name="date">the selected start date</param>
        /// <returns>how many copies that remains</returns>
        public static int Movie(ObjectId id, int numberOfCopies, DateTime startDate, DateTime endDate)
        {
            List <Loan> loans = MovieLoanRepository.GetMovieLoansById(id);

            foreach (Loan loan in loans)
            {
                int checkStartDate = Validations.CompareDates(startDate, loan.StartDate);
                int checkEndDate   = Validations.CompareDates(endDate, loan.EndDate);

                if (checkStartDate >= 0 && checkEndDate <= 0)
                {
                    numberOfCopies -= 1;
                }
                else if (true)
                {
                    checkStartDate = Validations.CompareDates(endDate, loan.StartDate);
                    checkEndDate   = Validations.CompareDates(endDate, loan.EndDate);

                    if (checkStartDate >= 0 && checkEndDate <= 0)
                    {
                        numberOfCopies -= 1;
                    }
                }
            }
            return(numberOfCopies);
        }
Пример #2
0
        /// <summary>
        /// Prints all movie loans with the id of the movie the user wanted to borrow
        /// </summary>
        /// <param name="id">movie id of the wanted book</param>
        public static void PrintMovieLoansList(ObjectId id)
        {
            List <Loan> loans = MovieLoanRepository.GetMovieLoansById(id);

            StandardMessages.ListAllItems("loans");
            DateTime today = DateTime.Today;

            foreach (Loan loan in loans)
            {
                int result = Validations.CompareDates(today, loan.EndDate);
                if (result < 0)
                {
                    var startDate = loan.StartDate.ToString("yyyy-MM-dd");
                    var endDate   = loan.EndDate.ToString("yyyy-MM-dd");
                    Console.WriteLine($"{loan.MovieArticle.Name} - {loan.Member.Name} - {startDate} - {endDate}");
                }
            }
        }