Example #1
0
        /// <summary>
        /// Shows member's all rents
        /// </summary>
        /// <param name="member"></param>
        private void ShowMyRents(Member member)
        {
            Console.Clear();
            Console.WriteLine("All my Rents");
            Console.WriteLine("------------\n");


            List <Rent> myRents = RentRepository.GetMyRents(member);

            if (myRents.Count == 0)
            {
                Console.WriteLine("\nThere is no rents registered");
            }
            else
            {
                for (int i = 0; i < myRents.Count; i++)
                {
                    int j = i;
                    if (myRents[i].RentedBook != null)
                    {
                        Console.WriteLine($"[{++j}][Book] [Title]: {myRents[i].RentedBook.Title} is rented from {myRents[i].StartDate} until {myRents[i].EndDate}");
                    }
                    else
                    {
                        Console.WriteLine($"[{++j}][Film] [Title]: {myRents[i].RentedFilm.Title} is rented from {myRents[i].StartDate} until {myRents[i].EndDate}");
                    }
                }
            }
            PressKeyToGoBackToMainMenu(member);
        }
Example #2
0
 public BoatService()
 {
     bm_repository = new BoatModelRepository();
     b_repository  = new BoatRepository();
     i_repository  = new ImageRepository();
     r_repository  = new RentRepository();
 }
Example #3
0
        /// <summary>
        /// Gets member's all rents from db and shows
        /// </summary>
        /// <param name="id"></param>
        /// <returns>A list of member's rents</returns>
        private List <Rent> ShowRentsByMemberId(ObjectId id)
        {
            List <Rent> rents = RentRepository.GetRentsByMemberId(id);

            if (rents.Count == 0)
            {
                Console.WriteLine("\nThere is no rents registered");
                PressKeyToGoBackToRentMenu();
            }
            else
            {
                for (int i = 0; i < rents.Count; i++)
                {
                    int j = i;
                    if (rents[i].RentedBook != null)
                    {
                        Console.WriteLine($"[{++j}][Book] [Title]: {rents[i].RentedBook.Title} is rented from {rents[i].StartDate} until {rents[i].EndDate}");
                    }
                    else
                    {
                        Console.WriteLine($"[{++j}][Film] [Title]: {rents[i].RentedFilm.Title} is rented from {rents[i].StartDate} until {rents[i].EndDate}");
                    }
                }
            }

            return(rents);
        }
Example #4
0
        /// <summary>
        /// Gets all rents of a member by member id from db and returns to view
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public ActionResult MemberRents(string id)
        {
            ObjectId    memberId = new ObjectId(id);
            List <Rent> rents    = RentRepository.GetRentsByMemberId(memberId);

            return(View(rents));
        }
Example #5
0
        /// <summary>
        /// Gets a rent by id from db
        /// </summary>
        /// <param name="id"></param>
        /// <returns>A rent as an object</returns>
        public ActionResult Delete(string id)
        {
            ObjectId retnId = new ObjectId(id);
            Rent     rent   = RentRepository.GetRentById(retnId);

            return(View(rent));
        }
Example #6
0
        public RentModel CancelRentVehicle(RentModel rentModel)
        {
            RentModel rent = null;

            try
            {
                VehicleRepository vehicleRepository = new VehicleRepository();
                Vehicle           vehicle           = vehicleRepository.SelectedByNumber(rentModel.vehiclenumber);

                if (vehicle == null)
                {
                    throw new Exception("CustomerBisuness::RentVehicle: Vehcile Is Not Found! \n");
                }

                //Rent Update
                RentRepository rentRepository = new RentRepository();

                rentModel.isactive = 0;
                rentRepository.Update(rentModel);

                rent = rentRepository.SelectedByVehicleAndMember(rentModel.vehiclenumber, rentModel.membernumber);

                //Vehicle Update
                vehicle.istaken = 0;
                vehicleRepository.Update(vehicle);
            }
            catch (Exception ex)
            {
                throw new Exception("CustomerBisuness::RentVehicle: Error occured.\n", ex);
            }
            return(rent);
        }
Example #7
0
        static void Main(string[] args)
        {
            RentalContext       ctx         = new RentalContext();
            RentRepository      rentRepo    = new RentRepository(ctx);
            VideoGameRepository gameRepo    = new VideoGameRepository(ctx);
            PersonRepository    personRepo  = new PersonRepository(ctx);
            RentLogic           rentLogic   = new RentLogic(rentRepo);
            VideoGameLogic      gameLogic   = new VideoGameLogic(gameRepo);
            PersonLogic         personLogic = new PersonLogic(personRepo);

            Console.WriteLine(">List all rents");
            rentLogic.GetAllRentals().ToList().ForEach(x => Console.WriteLine(x.AllData));

            Console.WriteLine("\n\n##################################################\n");

            Console.WriteLine("\n\n>List all games");
            gameLogic.GetAllGames().ToList().ForEach(x => Console.WriteLine(x.AllData));

            Console.WriteLine("\n\n##################################################\n");

            Console.WriteLine("\n\n>List all people");
            personLogic.GetAllPeople().ToList().ForEach(x => Console.WriteLine(x.AllData));

            //##################################################


            Console.WriteLine(rentLogic.MostFine());
            Console.WriteLine(rentLogic.MostRentedGame());
            Console.WriteLine(rentLogic.MostRentsByPerson());
        }
Example #8
0
        /// <summary>
        /// Gets a list of all rents from db, sorts the list by member name and returns to view
        /// </summary>
        /// <returns>a list of all rents</returns>
        public ActionResult Index()
        {
            List <Rent>           rents = RentRepository.GetRents();
            SortRentsByMemberName sortRentsByMemberName = new SortRentsByMemberName();

            rents.Sort(sortRentsByMemberName);
            return(View(rents));
        }
Example #9
0
 public MessageService()
 {
     a_repository = new AccountRepository();
     b_repository = new BoatRepository();
     bm_repository = new BoatModelRepository();
     m_repository = new MessageRepository();
     r_repository = new RentRepository();
 }
Example #10
0
        public ActionResult BookRents(string id)
        {
            ObjectId    bookId = new ObjectId(id);
            Book        book   = BookRepository.GetBookById(bookId);
            List <Rent> rents  = RentRepository.GetAllSameBookRented(book);

            return(View(rents));
        }
Example #11
0
        public ActionResult FilmRents(string id)
        {
            ObjectId    filmId = new ObjectId(id);
            Film        film   = FilmRepository.GetFilmById(filmId);
            List <Rent> rents  = RentRepository.GetAllSameFilmRented(film);

            return(View(rents));
        }
        public void Setup()
        {
            RentalContext       ctx        = new RentalContext();
            RentRepository      rentRepo   = new RentRepository(ctx);
            VideoGameRepository gameRepo   = new VideoGameRepository(ctx);
            PersonRepository    personRepo = new PersonRepository(ctx);

            rentLogic   = new RentLogic(rentRepo);
            gameLogic   = new VideoGameLogic(gameRepo);
            personLogic = new PersonLogic(personRepo);
        }
Example #13
0
        public void GetAdress()
        {
            Adress adress;

            using (var context = new RentMyCarContext(options))
            {
                var service = new RentRepository(context);
                adress = service.GetAdress(_userLb.UserName, 2);
            }
            Assert.AreEqual("Warszawa", adress.City);
            Assert.AreEqual("02-787", adress.PostalCode);
        }
Example #14
0
        public void GetRent()
        {
            Rent rent;

            using (var context = new RentMyCarContext(options))
            {
                var service = new RentRepository(context);
                rent = service.GetRent(_userLb.UserName, 2);
            }
            Assert.AreEqual(_ferrari.Model, rent.Car.Model);
            Assert.AreEqual("02-787", rent.Adress.PostalCode);
        }
Example #15
0
        public void AddRent()
        {
            using (var context = new RentMyCarContext(options))
            {
                context.Users.Add(this._userFr);
                context.Users.Add(this._userLb);
                context.SaveChanges();

                var service = new CarRepository(context);
                service.AddCar(_userFr.UserName, _ferrari);
                service.AddCar(_userLb.UserName, _lambo);
            }

            Rent rent1 = new Rent()
            {
                EndDate = DateTime.Now.AddDays(5),
                Adress  = new Adress()
                {
                    PostalCode   = "02-785",
                    StreetName   = "Zlota",
                    StreetNumber = 52,
                    City         = "Warszawa"
                },
                CarId = _lambo.CarId
            };
            Rent rent2 = new Rent()
            {
                EndDate = DateTime.Now.AddDays(5),
                Adress  = new Adress()
                {
                    PostalCode   = "02-787",
                    StreetName   = "Pulawska",
                    StreetNumber = 99,
                    City         = "Warszawa"
                },
                CarId = _ferrari.CarId
            };

            using (var context = new RentMyCarContext(options))
            {
                var service = new RentRepository(context);
                service.AddRent(this._userFr.UserName, rent1);
                service.AddRent(this._userLb.UserName, rent2);
            }

            using (var context = new RentMyCarContext(options))
            {
                Assert.AreEqual(2, context.Rents.Count());
                Assert.AreEqual(_lambo.Model, context.Rents.Include(r => r.Car).FirstOrDefault().Car.Model);
                Assert.AreEqual(_userFr.UserName, context.Rents.Include(r => r.User).FirstOrDefault().User.UserName);
            }
        }
Example #16
0
        public void GetRents()
        {
            IEnumerable <Rent> rentsFr;

            using (var context = new RentMyCarContext(options))
            {
                var service = new RentRepository(context);
                rentsFr = service.GetRents(_userFr.UserName);
            }

            Assert.AreEqual(1, rentsFr.Count());
            Assert.AreEqual(_lambo.Model, rentsFr.FirstOrDefault().Car.Model);
        }
Example #17
0
        private UnitOfWork()
        {
            _context = new CarRentalAppContext();

            Bills                 = new BillRepository(_context);
            Cars                  = new CarRepository(_context);
            Clients               = new ClientRepository(_context);
            Classifications       = new ClassificationRepository(_context);
            Rents                 = new RentRepository(_context);
            Roles                 = new RoleRepository(_context);
            Users                 = new UserRepository(_context);
            _context.Database.Log = AppLogger.LogSqlInFile;
        }
Example #18
0
        protected void ButtonRent_Click(object sender, EventArgs e)
        {
            Rent rent = new Rent()
            {
                BookID     = int.Parse(Request.QueryString["ID"]),
                UserID     = int.Parse(DropDownListUser.SelectedItem.Value),
                RentDate   = DateTime.Now,
                ReturnDate = DateTime.Now.AddDays(15)
            };

            RentRepository.AddRent(rent);
            Response.Redirect("AllRecords.aspx");
        }
Example #19
0
        public ActionResult DeleteConfirmed(string id)
        {
            try
            {
                ObjectId retnId = new ObjectId(id);
                RentRepository.DeleteRentById(retnId);

                return(RedirectToAction("Index"));
            }
            catch
            {
                return(View());
            }
        }
 public RentAddAction(
     RentRepository rentRepository,
     VehicleRepository vehicleRepository,
     RentRateRepository rentRateRepository,
     EmployeeRepository employeeRepository,
     CustomerRepository customerRepository
     )
 {
     _rentRepository     = rentRepository;
     _vehicleRepository  = vehicleRepository;
     _rentRateRepository = rentRateRepository;
     _employeeRepository = employeeRepository;
     _customerRepository = customerRepository;
 }
Example #21
0
        public void SetAdress()
        {
            Adress adress = new Adress()
            {
                PostalCode   = "02-785",
                StreetName   = "Zlota",
                StreetNumber = 52,
                City         = "Warszawa"
            };

            using (var context = new RentMyCarContext(options))
            {
                var service = new RentRepository(context);
                adress = service.GetAdress(_userLb.UserName, 2);
            }
            Assert.AreEqual("Warszawa", adress.City);
            Assert.AreEqual("02-785", adress.PostalCode);
        }
Example #22
0
        public UnitOfWork(LibraryDbContext context)
        {
            DbContext = context;
            Books     = new BookRepository(context);
            Users     = new UserRepository(context);
            Rents     = new RentRepository(context);
            Roles     = new RoleRepository(context);

            if (Roles.FindByCondition(role => role.Name == "Admin").Count() == 0)
            {
                Roles.Add(new Role("Admin"));
            }

            if (Roles.FindByCondition(role => role.Name == "Reader").Count() == 0)
            {
                Roles.Add(new Role("Reader"));
            }
        }
        /// <summary>
        /// Checks if film if free to rent between entered start and end rent's date
        /// </summary>
        /// <param name="film"></param>
        /// <returns>True if film if free to rent and false if not</returns>
        private bool FilmIsFreeToRent(Rent rent)
        {
            List <Rent> allSameFilmRented = RentRepository.GetAllSameFilmRented(rent.RentedFilm);
            int         rentedCopies      = 0;

            for (int i = 0; i < allSameFilmRented.Count; i++)
            {
                if (rent.EndDate >= allSameFilmRented[i].StartDate && rent.StartDate <= allSameFilmRented[i].EndDate)
                {
                    rentedCopies++;
                }
            }
            if (rentedCopies >= rent.RentedFilm.Copies)
            {
                return(false);
            }
            return(true);
        }
Example #24
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));
            }
        }
Example #25
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));
            }
        }
Example #26
0
        public RentModel RentVehicle(RentModel rentModel)
        {
            RentModel rent = null;

            try
            {
                VehicleRepository vehicleRepository = new VehicleRepository();
                Vehicle           vehicle           = vehicleRepository.SelectedByNumber(rentModel.vehiclenumber);

                if (vehicle == null)
                {
                    throw new Exception("CustomerBisuness::RentVehicle: Vehcile Is Not Found! \n");
                }

                MemberRepository repository   = new MemberRepository();
                Member           isHaveMember = repository.SelectedByNumber(rentModel.membernumber);

                if (isHaveMember == null)
                {
                    throw new Exception("CustomerBisuness::RentVehicle: Customer Is Not Found! \n");
                }

                if (vehicleRepository.VehicleIsTaken(rentModel.vehiclenumber))
                {
                    throw new Exception("CustomerBisuness::RentVehicle: Vehicle Is Not Available! \n");
                }

                RentRepository rentRepository = new RentRepository();
                rentRepository.Insert(rentModel);
                rent = rentRepository.SelectedByVehicleAndMember(rentModel.vehiclenumber, rentModel.membernumber);

                //Vehicle Update
                vehicle.istaken = 1;
                vehicleRepository.Update(vehicle);
            }
            catch (Exception ex)
            {
                throw new Exception("CustomerBisuness::RentVehicle: Error occured.\n", ex);
            }
            return(rent);
        }
Example #27
0
        /// <summary>
        /// gets a rented item and delete it from db
        /// </summary>
        private void ReturnItem()
        {
            List <Rent> memberRents = ShowRents();

            int rentIdToReturn;

            while (true)
            {
                Console.Write("\nEnter RENT ID you want to DELETE: ");
                string inputRentId = Console.ReadLine();
                if (inputRentId.Length != 0 && IsDigitsOnly(inputRentId) && int.Parse(inputRentId) > 0 && int.Parse(inputRentId) <= memberRents.Count)
                {
                    rentIdToReturn = int.Parse(inputRentId) - 1;
                    break;
                }
            }

            RentRepository.DeleteRentById(memberRents[rentIdToReturn].Id);

            Console.WriteLine($"\nItem returned SUCCESSFULLY");

            PressKeyToGoBackToRentMenu();
        }
 protected void Page_Load(object sender, EventArgs e)
 {
     Repeater1.DataSource = RentRepository.GetAllRents();
     Repeater1.DataBind();
 }
 public ReportEmployeeRents(EmployeeRepository employeeRepository, RentRepository rentRepository)
 {
     _employeeRepository = employeeRepository;
     _rentRepository     = rentRepository;
 }
Example #30
0
 public RentDeleteAction(RentRepository rentRepository)
 {
     _rentRepository = rentRepository;
 }