Пример #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);
                        }
                    }
                }
            }
        }
Пример #2
0
        /// <summary>
        /// The user selects a movie by index and gets the chosen movie returned
        /// </summary>
        /// <param name="updateOrDelete">a string that indicates whether to update or delete the movie</param>
        /// <returns>the chosen movie</returns>
        public static Movie SelectMovie(string updateOrDelete)
        {
            List <Movie> movies = MovieRepository.GetMovies();

            StandardMessages.ListAllItems("movies");

            int i = 1;

            foreach (Movie movie in movies)
            {
                Console.WriteLine($"{i} {movie.Name} {movie.ReleseYear}");
                i++;
            }

            StandardMessages.SelectItemToDelete("movie", updateOrDelete);
            string input = Console.ReadLine();

            int.TryParse(input, out int indexSelected);

            bool isValid = Validations.SelectedIndex(indexSelected, i, movies.Count);

            if (isValid)
            {
                return(movies[indexSelected - 1]);
            }
            else if (indexSelected == 0)
            {
                return(null);
            }
            else
            {
                return(null);
            }
        }
Пример #3
0
        /// <summary>
        /// Prints the select a book message and lets the user select an index of a book to borrow
        /// </summary>
        /// <param name="updateOrDelete"></param>
        /// <returns>the selected index by the user</returns>
        private static int SelectedBookInput(string updateOrDelete)
        {
            StandardMessages.SelectItemToDelete("book", updateOrDelete);
            string input = Console.ReadLine();

            int.TryParse(input, out int indexSelected);
            return(indexSelected);
        }
Пример #4
0
        private static void LoanProcessAvailableBooks(Member member, Book book, DateTime startDate, DateTime endDate)
        {
            Loan loan = Factory.CreateLoan(startDate, endDate, member);

            loan.BookArticle = book;
            BookLoanRepository.InsertBookLoan(loan);
            StandardMessages.LoanComplete(book.Name, loan.EndDate);
        }
Пример #5
0
        private static void LoanProcessAvailableMovies(Member member, Movie movie, DateTime startDate, DateTime endDate)
        {
            Loan loan = Factory.CreateLoan(startDate, endDate, member);

            loan.MovieArticle = movie;
            MovieLoanRepository.InsertMovie(loan);
            StandardMessages.LoanComplete(movie.Name, loan.EndDate);
        }
Пример #6
0
        /// <summary>
        /// Prints the list of books to the user
        /// </summary>
        /// <returns>the number of books in the list</returns>
        private static int PrintsAndReturnNumberOfBooks()
        {
            int i = 1;

            StandardMessages.ListAllItems("books");
            foreach (Book book in books)
            {
                Console.WriteLine($"{i} {book.Name} {book.Author}");
                i++;
            }
            return(i - 1);
        }
Пример #7
0
        /// <summary>
        /// prints all books in the datebase
        /// </summary>
        public static void PrintBooksList()
        {
            List <Book> books = BookRepository.GetBooks();

            StandardMessages.ListAllItems("books");
            foreach (Book book in books)
            {
                Console.WriteLine($"{book.Name} {book.ReleseYear} {book.Genre} {book.Author} {book.Pages}");
            }
            Console.WriteLine("\nPress enter to continue...");
            Console.ReadLine();
        }
Пример #8
0
        /// <summary>
        /// prints all movies in the database
        /// </summary>
        public static void PrintMoviesList()
        {
            List <Movie> movies = MovieRepository.GetMovies();

            StandardMessages.ListAllItems("movies");
            foreach (Movie movie in movies)
            {
                TimeSpan t        = TimeSpan.FromMinutes(movie.Duration);
                string   duration = string.Format("{0:D2}h:{1:D2}m", t.Hours, t.Minutes);

                Console.WriteLine($"{movie.Name} {movie.ReleseYear} {movie.Genre} {duration} {movie.AgeLimit}");
            }
            Console.WriteLine("\nPress enter to continue...");
            Console.ReadLine();
        }
Пример #9
0
        /// <summary>
        /// the user gets to choose which movie loan of the members movie loans to return
        /// the book loans endDate gets updated to DateTime.Today
        /// </summary>
        public static void UpdateMovieLoan(Member member)
        {
            Loan loanToReturn = SelectLoanById.SelectMovieLoan(member);

            if (loanToReturn != null)
            {
                DateTime returnDate = DateTime.Today;
                MovieLoanRepository.ReturnMovie(loanToReturn, returnDate);

                StandardMessages.ItemReturned("movie");
            }
            else
            {
                StandardMessages.NothingToReturn("movies");
            }
        }
Пример #10
0
        public static void UpdateBookLoan(Member member)
        {
            Loan loanToReturn = SelectLoanById.SelectBookLoan(member);

            if (loanToReturn != null)
            {
                DateTime returnDate = DateTime.Today;
                BookLoanRepository.ReturnBook(loanToReturn, returnDate);

                StandardMessages.ItemReturned("book");
            }
            else
            {
                StandardMessages.NothingToReturn("books");
            }
        }
Пример #11
0
        /// <summary>
        /// The user selects a book loan by index and gets the chosen book loan returned
        /// </summary>
        /// <returns>the chosen book loan</returns>
        public static Loan SelectBookLoan(Member member)
        {
            List <Book> book = BookRepository.GetBooks();

            if (book.Count > 0)
            {
                List <Loan> loans = BookLoanRepository.GetBookLoansByMember(member);
                StandardMessages.ListAllItems("your book loans");

                int i = 1;
                foreach (Loan loan in loans)
                {
                    var outputDate = loan.EndDate.ToString("yyyy-MM-dd");
                    Console.WriteLine($"{i} {loan.Member.Name} {loan.BookArticle.Name} {outputDate}");
                    i++;
                }
                StandardMessages.SelectItemToDelete("book", "return");
                string input = Console.ReadLine();
                if (input != "0")
                {
                    int index = Validations.ParseInt(input);

                    bool isValid = Validations.SelectedIndex(index, i, loans.Count);
                    if (isValid)
                    {
                        return(loans[index - 1]);
                    }
                    else
                    {
                        StandardMessages.InvalidOption();
                        input = Console.ReadLine();
                        return(null);
                    }
                }
                else
                {
                    return(null);
                }
            }
            else
            {
                StandardMessages.NothingToReturn("books");
                return(null);
            }
        }
Пример #12
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}");
                }
            }
        }
Пример #13
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);
            }
        }
Пример #14
0
 /// <summary>
 /// Checks if the indexSelected is not 0, which means exit
 /// checks if the indexSelected is not greater than i-1 which means that there is no such index
 /// checks if the count is greater than zero, otherwise there is no index to be chosen
 /// </summary>
 /// <param name="indexSelected">index int chosen by the user</param>
 /// <param name="i">the number of objects in the list -1</param>
 /// <param name="count">Makes sure there is an option to chose... if there is no objects "int i" will still be 1</param>
 /// <returns>true if the selectedIndex is valid, otherwise false</returns>
 public static bool SelectedIndex(int indexSelected, int i, int count)
 {
     if (indexSelected == 0)
     {
         return(false);
     }
     else if (indexSelected > i)
     {
         StandardMessages.OutOfRange();
         return(false);
     }
     else if (count >= 1)
     {
         return(true);
     }
     else
     {
         return(false);
     }
 }
Пример #15
0
        /// <summary>
        /// the user gets to select a book 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 book</param>
        public static void BorrowABook(Member member)
        {
            Book book = SelectBookById.SelectBook("lend");

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

                bool newDate = true;
                while (newDate)
                {
                    DateTime endDate = startDate.AddMonths(1);

                    int availableBooks = CheckLoansToCopies.Book(book.Id, book.NumberOfCopies, startDate, endDate);
                    if (availableBooks > 0)
                    {
                        LoanProcessAvailableBooks(member, book, startDate, endDate);
                        newDate = false;
                    }
                    else
                    {
                        StandardMessages.OutOfCopies();
                        string input = Console.ReadLine();

                        if (input == "0")
                        {
                            newDate = false;
                        }
                        else
                        {
                            startDate = SelectNewLoanDate.SelectNewDateBook(book.Id);
                        }
                    }
                }
            }
        }