示例#1
0
        public ActionResult RentFilmToMember(string id, string memberId, DateTime startDate, DateTime endDate)
        {
            List <Member>    members          = MemberRepository.GetMembers();
            SortMemberByName sortMemberByName = new SortMemberByName();

            members.Sort(sortMemberByName);

            if (RentRepository.IsStartDateCorrect(startDate))
            {
                if (RentRepository.IsEndDateCorrect(endDate, startDate))
                {
                    ObjectId RentingMemberId = new ObjectId(memberId);
                    Member   member          = MemberRepository.GetMemberById(RentingMemberId);

                    ObjectId rentingFilmId = new ObjectId(id);
                    Film     film          = FilmRepository.GetFilmById(rentingFilmId);

                    Rent rent = new Rent(member, null, film, startDate, endDate);

                    if (FilmRepository.FilmIsFreeToRent(rent))
                    {
                        RentRepository.CreateRent(rent);
                        return(Redirect($"/Rents/MemberRents/{memberId}"));
                    }
                    else
                    {
                        TempData["textmsg"] = "<script>alert('This book is not free to Rent in this entered date period. Please try another dates');</script>";
                        return(View(members));
                    }
                }
                else
                {
                    TempData["textmsg"] = "<script>alert('You entered a date before rent start date. Please try a date after rent start date');</script>";
                    return(View(members));
                }
            }
            else
            {
                TempData["textmsg"] = "<script>alert('You entered a date before today date. Please try a date after today date');</script>";
                return(View(members));
            }
        }
示例#2
0
        public ActionResult RentBook(string id, string bookId, DateTime startDate, DateTime endDate)
        {
            List <Book>      books            = BookRepository.GetBooks();
            SortBooksByTitle sortBooksByTitle = new SortBooksByTitle();

            books.Sort(sortBooksByTitle);

            if (RentRepository.IsStartDateCorrect(startDate))
            {
                if (RentRepository.IsEndDateCorrect(endDate, startDate))
                {
                    ObjectId memberId = new ObjectId(id);
                    Member   member   = MemberRepository.GetMemberById(memberId);

                    ObjectId rentingBookId = new ObjectId(bookId);
                    Book     book          = BookRepository.GetBookById(rentingBookId);

                    Rent rent = new Rent(member, book, null, startDate, endDate);

                    if (BookRepository.BookIsFreeToRent(rent))
                    {
                        RentRepository.CreateRent(rent);
                        return(Redirect($"/Rents/MemberRents/{id}"));
                    }
                    else
                    {
                        TempData["textmsg"] = "<script>alert('This book is not free to Rent in this entered date period. Please try another dates');</script>";
                        return(View(books));
                    }
                }
                else
                {
                    TempData["textmsg"] = "<script>alert('You entered a date before rent start date. Please try a date after rent start date');</script>";
                    return(View(books));
                }
            }
            else
            {
                TempData["textmsg"] = "<script>alert('You entered a date before today date. Please try a date after today date');</script>";
                return(View(books));
            }
        }
示例#3
0
        /// <summary>
        /// Creates an rent object and saves in data base
        /// </summary>
        private void RentItem()
        {
            Console.Clear();
            Console.WriteLine("Rent an ITEM");
            Console.WriteLine("------------\n");

            List <Member> members = ShowMembers();
            int           id;

            while (true)
            {
                Console.Write("\nEnter member's ID to start rent: ");
                string inputedMemberId = Console.ReadLine();

                if (inputedMemberId.Length != 0 && IsDigitsOnly(inputedMemberId) && int.Parse(inputedMemberId) > 0 && int.Parse(inputedMemberId) <= members.Count)
                {
                    id = int.Parse(inputedMemberId) - 1;
                    break;
                }
            }

            Member rentingMember = members[id]; //Creates renting member to rent

            Console.WriteLine("\n** Select ITEM category **");

            string itemType = "";

            while (itemType.ToLower() != "b" && itemType.ToLower() != "f")
            {
                Console.Write("Select (b)ook or (f)ilm: ");
                itemType = Console.ReadLine();
            }

            if (itemType.ToLower() == "b")//If item to rent is a book
            {
                Console.Clear();
                Console.WriteLine($"You are goting to rent a BOOK to '{rentingMember.Name}'\n");

                List <Book> books = ShowBooks();

                if (books.Count == 0)
                {
                    PressKeyToGoBackToRentMenu();
                }

                int bookId;
                while (true)
                {
                    Console.Write("\nEnter BOOK ID you want to rent: ");
                    string inputBookId = Console.ReadLine();
                    if (inputBookId.Length != 0 && IsDigitsOnly(inputBookId) && int.Parse(inputBookId) > 0 && int.Parse(inputBookId) <= books.Count)
                    {
                        bookId = int.Parse(inputBookId) - 1;
                        break;
                    }
                }

                Book rentingBook = books[bookId];//Creates renting book to rent

                List <Rent> AllrentedThisBook = RentRepository.GetAllSameBookRented(rentingBook);

                foreach (Rent thisBookRent in AllrentedThisBook)
                {
                    Console.WriteLine($"{thisBookRent.RentedBook.Title} is rented from {thisBookRent.StartDate} to {thisBookRent.EndDate}");
                }

                DateTime startDate = GetStartDate();
                DateTime endDate   = GetEndDate(startDate);

                Rent newRent = new Rent(rentingMember, rentingBook, null, startDate, endDate); //Creates a new rent object

                if (BookRepository.BookIsFreeToRent(newRent))
                {
                    RentRepository.CreateRent(newRent);//Inserts a rent in db
                    Console.WriteLine($"\n'{rentingMember.Name}' rented '{rentingBook.Title}' SUCCESSFULLY");
                }
                else
                {
                    Console.WriteLine("\n** All copies of this book are rented out between these entered dates **");
                }
            }



            else if (itemType.ToLower() == "f")//If item to rent is a film
            {
                Console.Clear();
                Console.WriteLine($"You are goting to rent a Film to '{rentingMember.Name}'\n");

                List <Film> films = ShowFilms();

                if (films.Count == 0)
                {
                    PressKeyToGoBackToRentMenu();
                }

                int filmId;
                while (true)
                {
                    Console.Write("\nEnter FILM ID you want to rent: ");
                    string inputFilmId = Console.ReadLine();
                    if (inputFilmId.Length != 0 && IsDigitsOnly(inputFilmId) && int.Parse(inputFilmId) > 0 && int.Parse(inputFilmId) <= films.Count)
                    {
                        filmId = int.Parse(inputFilmId) - 1;
                        break;
                    }
                }

                Film rentingFilm = films[filmId];//Creates renting book to rent

                List <Rent> AllrentedThisFilm = RentRepository.GetAllSameFilmRented(rentingFilm);

                foreach (Rent thisFilmRent in AllrentedThisFilm)
                {
                    Console.WriteLine($"{thisFilmRent.RentedFilm.Title} is rented from {thisFilmRent.StartDate} to {thisFilmRent.EndDate}");
                }

                DateTime startDate = GetStartDate();
                DateTime endDate   = GetEndDate(startDate);

                Rent newRent = new Rent(rentingMember, null, rentingFilm, startDate, endDate);

                if (FilmRepository.FilmIsFreeToRent(newRent))
                {
                    RentRepository.CreateRent(newRent);
                    Console.WriteLine($"\n'{rentingMember.Name}' rented '{rentingFilm.Title}' SUCCESSFULLY");
                }
                else
                {
                    Console.WriteLine("\n** All copies of this book are rented out between these entered dates **");
                }
            }
            PressKeyToGoBackToRentMenu();
        }
        /// <summary>
        /// Creates an rent object and saves in data base
        /// </summary>
        private void RentItem()
        {
            Console.Clear();
            Console.WriteLine("Rent an ITEM");
            Console.WriteLine("------------\n");

            List <Member> members = ShowMembers();
            int           id;

            while (true)
            {
                Console.Write("\nEnter member's ID to start rent: ");
                string inputedMemberId = Console.ReadLine();

                if (inputedMemberId.Length != 0 && IsDigitsOnly(inputedMemberId) && int.Parse(inputedMemberId) > 0 && int.Parse(inputedMemberId) <= members.Count)
                {
                    id = int.Parse(inputedMemberId) - 1;
                    break;
                }
            }

            Member rentingMember = members[id]; //Creates renting member to rent

            Console.WriteLine("\n** Select ITEM category **");

            string itemType = "";

            while (itemType.ToLower() != "b" && itemType.ToLower() != "f")
            {
                Console.Write("Select (b)ook or (f)ilm: ");
                itemType = Console.ReadLine();
            }

            if (itemType.ToLower() == "b")//If item to rent is a book
            {
                Console.Clear();
                Console.WriteLine($"You are goting to rent a BOOK to '{rentingMember.Name}'\n");

                List <Book> books = ShowBooks();

                if (books.Count == 0)
                {
                    PressKeyToGoBackToRentMenu();
                }

                int bookId;
                while (true)
                {
                    Console.Write("\nEnter BOOK ID you want to rent: ");
                    string inputBookId = Console.ReadLine();
                    if (inputBookId.Length != 0 && IsDigitsOnly(inputBookId) && int.Parse(inputBookId) > 0 && int.Parse(inputBookId) <= books.Count)
                    {
                        bookId = int.Parse(inputBookId) - 1;
                        break;
                    }
                }

                Book rentingBook = books[bookId];//Creates renting book to rent

                List <Rent> AllrentedThisBook = RentRepository.GetAllSameBookRented(rentingBook);

                foreach (Rent thisBookRent in AllrentedThisBook)
                {
                    Console.WriteLine($"{thisBookRent.RentedBook.Title} is rented from {thisBookRent.StartDate} to {thisBookRent.EndDate}");
                }

                DateTime startDate = DateTime.Now;
                DateTime endDate   = DateTime.Now;
                while (true)
                {
                    int startDateResultat = 2;
                    try
                    {
                        Console.Write("\nEnter rent's START DATE(yyyy,mm,dd): ");
                        startDate         = DateTime.Parse(Console.ReadLine()).Date;
                        startDateResultat = DateTime.Compare(DateTime.Now.Date, startDate);//Checks to not enter a date before today's date
                    }
                    catch (Exception)
                    {
                        Console.WriteLine("You entered a WRONG  DATE FORMAT. Must be yyyy/mm/dd");
                    }

                    if (startDateResultat <= 0)//checks if date is in right format and start date is not before today's date
                    {
                        Console.WriteLine($"Rent start date is {startDate}");
                        break;
                    }
                    else if (startDateResultat > 0)
                    {
                        Console.WriteLine("Don't Entere a date before Today's date");
                    }
                }

                while (true)
                {
                    int endDateResultat = 2;
                    try
                    {
                        Console.Write("\nEnter rent's END DATE(yyyy,mm,dd): ");
                        endDate         = DateTime.Parse(Console.ReadLine()).Date;
                        endDateResultat = DateTime.Compare(endDate, startDate);//Checks to not enter an end date before start date
                    }
                    catch (Exception)
                    {
                        Console.WriteLine("You entered a WRONG  DATE FORMAT. Must be yyyy/mm/dd");
                    }

                    if (endDateResultat > 0)//checks if date is in right format and end date is not before start date
                    {
                        Console.WriteLine($"Rent end date is {endDate}");
                        break;
                    }
                    else
                    {
                        Console.WriteLine("Don't Entere a date before rent's start date");
                    }
                }

                Rent newRent = new Rent(rentingMember, rentingBook, null, startDate, endDate); //Creates a new rent object

                if (BookIsFreeToRent(newRent))
                {
                    RentRepository.CreateRent(newRent);//Inserts a rent in db
                    Console.WriteLine($"\n'{rentingMember.Name}' rented '{rentingBook.Title}' SUCCESSFULLY");
                }
                else
                {
                    Console.WriteLine("\n** All copies of this book are rented out between these entered dates **");
                }
            }



            else if (itemType.ToLower() == "f")//If item to rent is a film
            {
                Console.Clear();
                Console.WriteLine($"You are goting to rent a Film to '{rentingMember.Name}'\n");

                List <Film> films = ShowFilms();

                if (films.Count == 0)
                {
                    PressKeyToGoBackToRentMenu();
                }

                int filmId;
                while (true)
                {
                    Console.Write("\nEnter FILM ID you want to rent: ");
                    string inputFilmId = Console.ReadLine();
                    if (inputFilmId.Length != 0 && IsDigitsOnly(inputFilmId) && int.Parse(inputFilmId) > 0 && int.Parse(inputFilmId) <= films.Count)
                    {
                        filmId = int.Parse(inputFilmId) - 1;
                        break;
                    }
                }

                Film rentingFilm = films[filmId];//Creates renting book to rent

                List <Rent> AllrentedThisFilm = RentRepository.GetAllSameFilmRented(rentingFilm);

                foreach (Rent thisFilmRent in AllrentedThisFilm)
                {
                    Console.WriteLine($"{thisFilmRent.RentedFilm.Title} is rented from {thisFilmRent.StartDate} to {thisFilmRent.EndDate}");
                }

                DateTime startDate = DateTime.Now;
                DateTime endDate   = DateTime.Now;
                while (true)
                {
                    int startDateResultat = 2;
                    try
                    {
                        Console.Write("\nEnter rent's START DATE(yyyy,mm,dd): ");
                        startDate         = DateTime.Parse(Console.ReadLine()).Date;
                        startDateResultat = DateTime.Compare(DateTime.Now.Date, startDate);//Checks to not enter a date before today's date
                    }
                    catch (Exception)
                    {
                        Console.WriteLine("You entered a WRONG  DATE FORMAT. Must be yyyy/mm/dd");
                    }

                    if (startDateResultat <= 0)//checks if date is in right format and start date is not before today's date
                    {
                        Console.WriteLine($"Rent start date is {startDate}");
                        break;
                    }
                    else
                    {
                        Console.WriteLine("Don't entere a date before Today's date");
                    }
                }

                while (true)
                {
                    int endDateResultat = 2;
                    try
                    {
                        Console.Write("\nEnter rent's END DATE(yyyy,mm,dd): ");
                        endDate         = DateTime.Parse(Console.ReadLine()).Date;
                        endDateResultat = DateTime.Compare(endDate, startDate);//Checks to not enter an end date before start date
                    }
                    catch (Exception)
                    {
                        Console.WriteLine("You entered a WRONG  DATE FORMAT. Must be yyyy/mm/dd");
                    }

                    if (endDateResultat > 0)//checks if date is in right format and end date is not before start date
                    {
                        Console.WriteLine($"Rent end date is {endDate}");
                        break;
                    }
                    else
                    {
                        Console.WriteLine("Don't Entere a date before rent's start date");
                    }
                }

                Rent newRent = new Rent(rentingMember, null, rentingFilm, startDate, endDate);

                if (FilmIsFreeToRent(newRent))
                {
                    RentRepository.CreateRent(newRent);
                    Console.WriteLine($"\n'{rentingMember.Name}' rented '{rentingFilm.Title}' SUCCESSFULLY");
                }
                else
                {
                    Console.WriteLine("\n** All copies of this book are rented out between these entered dates **");
                }
            }
            PressKeyToGoBackToRentMenu();
        }