Beispiel #1
0
        /// <summary>
        /// the user gets to select a movie and check whether its available or not, if not the user gets to choose a new date yyyy-MM-dd
        /// </summary>
        /// <param name="member">the member to borrow the movie</param>
        public static void BorrowAMovie(Member member)
        {
            Movie movie = SelectMovieById.SelectMovie("lend");

            if (movie != null && member != null)
            {
                DateTime startDate = DateTime.Today;

                bool newDate = true;
                while (newDate)
                {
                    DateTime endDate = startDate.AddMonths(1);
                    int      result  = CheckLoansToCopies.Movie(movie.Id, movie.NumberOfCopies, startDate, endDate);
                    if (result > 0)
                    {
                        LoanProcessAvailableMovies(member, movie, startDate, endDate);
                        newDate = false;
                    }
                    else
                    {
                        StandardMessages.OutOfCopies();
                        string input = Console.ReadLine();

                        if (input == "0")
                        {
                            newDate = false;
                        }
                        else
                        {
                            startDate = SelectNewLoanDate.SelectNewDateMovie(movie.Id);
                        }
                    }
                }
            }
        }
Beispiel #2
0
        /// <summary>
        /// The user selects a movie loan by index and gets the chosen movie loan returned
        /// </summary>
        /// <returns>the chosen movie loan</returns>
        public static Loan SelectMovieLoan(Member member)
        {
            Movie movie = SelectMovieById.SelectMovie("return");

            if (movie != null)
            {
                List <Loan> loans = MovieLoanRepository.GetMovieLoansByMember(member);
                StandardMessages.ListAllItems("movie loans");

                int i = 1;
                foreach (Loan loan in loans)
                {
                    var outputDate = loan.EndDate.ToString("yyyy-MM-dd");
                    Console.WriteLine($"{i} {loan.Member.Name} {loan.MovieArticle.Name} {outputDate}");
                    i++;
                }
                StandardMessages.SelectItemToDelete("movie", "return");
                string input = Console.ReadLine();

                if (input != "0")
                {
                    int index = Validations.ParseInt(input);
                    index = Validations.TryAgain(index);

                    bool isValid = Validations.SelectedIndex(index, i, loans.Count);
                    if (isValid)
                    {
                        return(loans[index - 1]);
                    }
                    else
                    {
                        StandardMessages.InvalidOption();
                        return(null);
                    }
                }
                return(null);
            }
            else
            {
                return(null);
            }
        }