Exemplo n.º 1
0
        public void RentalTestSetup()
        {
            idtMock = Substitute.For <IDatateTime>();


            sut = new Rentals(idtMock);
        }
Exemplo n.º 2
0
        public IHttpActionResult CreateNewRentals(NewRentalDto newRental)
        {
            //throw new NotImplementedException();
            var customer = _context.Customers.Single(
                c => c.Id == newRental.CustomerId);
            var movies = _context.Movies.Where(
                m => newRental.MovieIds.Contains(m.Id));

            foreach (var movie in movies)
            {
                if (movie.NumberAvailable == 0)
                {
                    return(BadRequest("Movie not available"));
                }
                movie.NumberAvailable--;
                var rental = new Rentals
                {
                    Customer   = customer,
                    Movie      = movie,
                    DateRented = DateTime.Now
                };
                _context.Rentals.Add(rental);
            }
            _context.SaveChanges();

            return(Ok());
        }
Exemplo n.º 3
0
        public void ClearDatabase()
        {
#if MSSQL
            Console.WriteLine("qfklqsjdfkljqsdlfjiljsdfkljqsdkldfjklsqdjdhfjsqdhfjqsdhljkfklqsdjfklqsdjfkljsqddlkfjlsqdkjf");
            RentalItems.RemoveRange(RentalItems);
            Rentals.RemoveRange(Rentals);
            Users.RemoveRange(Users);
            BookCopies.RemoveRange(BookCopies);
            Books.RemoveRange(Books);
            Categories.RemoveRange(Categories);
#else
#endif
            SaveChanges();
            Reseed(nameof(Users));
            Reseed(nameof(Books));
            Reseed(nameof(Rentals));
            Reseed(nameof(BookCopies));
            Reseed(nameof(Categories));
            Reseed(nameof(RentalItems));



            /**
             * Décommenter la ligne suivante pour réinitialiser le compteur de clef autoincrementée
             */
            //Reseed(nameof(Messages));
        }
Exemplo n.º 4
0
        private void ReturnMovie()
        {
            if (_dialogService.ShowMessageBox(
                    this,
                    Local.Strings.txtReturnConfirmation,
                    Local.Strings.txtConfirmationRequired,
                    MessageBoxButton.YesNo,
                    MessageBoxImage.Question) == MessageBoxResult.Yes)
            {
                var rentalsToRemove = new List <Rental>();
                foreach (var item in Rentals.Where(i => i.IsSelected))
                {
                    rentalsToRemove.Add(item.Model);
                }

                _videoStoreService.DeleteRentals(rentalsToRemove);

                // refresh
                _rentals = _videoStoreService.GetRentals();
                RefreshRentals();
                RefreshDatesOfRental();
                RefreshDueDates();
                RefreshUsers();
            }
        }
Exemplo n.º 5
0
        public void ClearDatabase()
        {
#if MSSQL
            Books.RemoveRange(Books);
            Users.RemoveRange(Users);
            BookCopies.RemoveRange(BookCopies);
            RentalItems.RemoveRange(RentalItems);
            Rentals.RemoveRange(Rentals);

            Categories.RemoveRange(Categories
                                   .Include(nameof(Category.Books))
                                   );
#else
            Categories.RemoveRange(Categories
                                   .Include(nameof(Category.Books))
                                   );
#endif
            SaveChanges();

            /**
             * Décommenter la ligne suivante pour réinitialiser le compteur de clef autoincrementée
             */
            Reseed(nameof(Users));
            Reseed(nameof(Books));
            Reseed(nameof(BookCopies));
            Reseed(nameof(Categories));
            Reseed(nameof(Rentals));
            Reseed(nameof(RentalItems));
        }
Exemplo n.º 6
0
        public virtual Rental AddRental(Video video)
        {
            var rental = new Rental(this, video);

            Rentals.Add(rental);
            return(rental);
        }
Exemplo n.º 7
0
        public IResult Add(Rentals entity)
        {
            entity.RentDate = DateTime.Now;

            rentalDal.Add(entity);
            return(new SuccessResult("Başarılı bir şekilde eklendi"));
        }
        public IHttpActionResult CreateNewRentals(NewRentals newRental)
        {
            var customer = db.Customers.Single(
                x => x.Id == newRental.Custmerid);

            var movies = db.Movies.Where(
                x => newRental.Movieids.Contains(x.Id));

            foreach (var movie in movies)
            {
                if (movie.MemberAvalible == 0)
                {
                    return(BadRequest("One or more Movies are invalid. "));
                }

                movie.MemberAvalible--;
                var rental = new Rentals
                {
                    Customers  = customer,
                    Movies     = movie,
                    DateRented = DateTime.Now
                };

                db.Rentals.Add(rental);
            }

            db.SaveChanges();
            return(Ok());
        }
Exemplo n.º 9
0
        public static Rentals convertRental(RentalRepresentation rental)
        {
            Rentals convertedRental = new Rentals()
            {
                actualPrice   = rental.actualPrice,
                customerID    = rental.customer.id,
                discount      = (float)rental.discount * 100,
                isClean       = rental.isClean,
                rentalID      = rental.id,
                rentalEnd     = rental.rentalEnd,
                isPaid        = rental.isPaid,
                payTypeID     = rental.payType.id,
                rentalRealEnd = rental.rentalRealEnd,
                rentalStart   = rental.rentalStart,
                toolID        = rental.tool.id
            };

            if (rental.group != null && rental.group.id != default(long))
            {
                convertedRental.groupID = rental.group.id;
            }

            convertedRental.Tools = convertTool(rental.tool);

            if (rental.customer.isFirm && rental.contact != null)
            {
                convertedRental.contactID  = rental.contact.id;
                convertedRental.Customers1 = convertCustomer(rental.contact);
            }

            return(convertedRental);
        }
Exemplo n.º 10
0
        public IHttpActionResult PutRentals(int id, Rentals rentals)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != rentals.RentalID)
            {
                return(BadRequest());
            }

            db.Entry(rentals).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!RentalsExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
Exemplo n.º 11
0
 private void Window_Loaded(object sender, RoutedEventArgs e)
 {
     rentals    = new Rentals();
     residences = new Residences();
     tenants    = new Tenants();
     PopulateResidences();
 }
Exemplo n.º 12
0
        public IHttpActionResult Post(RentalsDto rentalsDto)
        {
            var customer = _context.Customer.Single(c => c.Id == rentalsDto.CustomerId);
            var movies   = _context.Movies.Where(c => rentalsDto.MoviesId.Contains(c.Id)).ToList();

            if (customer == null && movies == null)
            {
                return(NotFound());
            }

            foreach (var movie in movies)
            {
                if (movie.NumbersAvailable == 0)
                {
                    return(BadRequest("Movie Not Available"));
                }

                movie.NumbersAvailable--;
                var rent = new Rentals
                {
                    DateRented = DateTime.Now,
                    Customer   = customer,
                    Movies     = movie,
                };
                _context.Rentals.Add(rent);
            }
            _context.SaveChanges();


            return(Ok());
        }
Exemplo n.º 13
0
        public ActionResult Rent(string book)
        {
            var user    = User.Identity.Name;
            var rentals = db.Rentals;
            IEnumerable <Rentals> userRentals = rentals.Where(m => m.rentalUser == user && m.rentalExpiration >= DateTime.Today);
            var dupCheck = false;

            foreach (Rentals rental in userRentals)
            {
                if (rental.rentalBook == book)
                {
                    dupCheck = true;
                }
            }
            if (dupCheck)
            {
                return(RedirectToAction("Index"));
            }

            else
            {
                var rental = new Rentals
                {
                    rentalUser       = User.Identity.Name,
                    rentalExpiration = DateTime.Today.AddDays(3)
                };

                rental.rentalBook = book;

                db.Rentals.Add(rental);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }
        }
Exemplo n.º 14
0
 async Task LoadRentalsAsync()
 {
     LoadStatus = LoadStatus.Loading;
     Rentals.Clear();
     Rentals.AddRange(await _rentalService.GetRentalsAsync(Owner));
     LoadStatus = LoadStatus.Loaded;
 }
Exemplo n.º 15
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,Name,Location")] Rentals rentals)
        {
            if (id != rentals.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(rentals);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!RentalsExists(rentals.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                ApplicationUser appUser = await GetCurrentUserAsync();

                rentals.ApplicationUserId = appUser.Id;
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(rentals));
        }
Exemplo n.º 16
0
        public IResult Add(Rentals rentals)
        {
            ValidationTool.Validate(new RentalsValidator(), rentals);

            _rentalsDal.Add(rentals);
            return(new SuccessResult(Messages.RentalAdded));
        }
Exemplo n.º 17
0
        //GET Rentals/Book
        public async Task <IActionResult> Book(int id)
        {
            ApplicationUser appUser = await GetCurrentUserAsync();

            List <User> users = await _context.User.ToListAsync();

            Rentals rentals = await _context.Rentals.FirstOrDefaultAsync(r => r.Id == id);

            RentalVM vm = new RentalVM()
            {
                //Get Rentals to display Name, Location for View
                Rentals     = await _context.Rentals.FirstOrDefaultAsync(r => r.Id == id),
                UserOptions = users.Where(u => u.ApplicationUserId == appUser.Id && u.isArchived == false).Select(u => new SelectListItem
                {
                    Value = u.Id.ToString(),
                    Text  = u.FirstName
                })
                              .ToList()
            };

            vm.UserOptions.Insert(0, new SelectListItem
            {
                Text  = "Choose a User",
                Value = "0"
            });

            return(View(vm));
        }
Exemplo n.º 18
0
        public void Setup()
        {
            date = Substitute.For <IDateTime>();
            sut  = new Rentals(date);

            date.Now().Returns(new System.DateTime(1222, 12, 12));
        }
Exemplo n.º 19
0
        private static void GoCarRent()
        {
            RentalsManager rentalmanager = new RentalsManager(new EfRentalsDAL());

            Console.WriteLine("(int)RentalId:");
            int RentalId1 = Convert.ToInt32(Console.ReadLine());

            Console.WriteLine("(int)CarId:");
            int CarId1 = Convert.ToInt32(Console.ReadLine());

            Console.WriteLine("(int)CustomerId:");
            int CustomerId1 = Convert.ToInt32(Console.ReadLine());

            Console.WriteLine("(DateTime)RentDate:");
            DateTime RentDate1 = Convert.ToDateTime(Console.ReadLine());

            Console.WriteLine("(DateTime)ReturnDate:");
            DateTime ReturnDate1 = Convert.ToDateTime(Console.ReadLine());
            Rentals  rental1     = new Rentals();

            rental1 = new Rentals()
            {
                RentalId   = RentalId1,
                CarId      = CarId1,
                CustomerId = CustomerId1,
                RentDate   = RentDate1,
                ReturnDate = ReturnDate1
            };
        }
Exemplo n.º 20
0
        public void ClearDatabase()
        {
#if MSSQL
            Categories.RemoveRange(Categories);
            RentalItems.RemoveRange(RentalItems);
            BookCopies.RemoveRange(BookCopies);
            Books.RemoveRange(Books);
            Rentals.RemoveRange(Rentals);
            Users.RemoveRange(Users);
#else
            Categories.RemoveRange(Categories);
            BookCopies.RemoveRange(BookCopies
                                   .Include(nameof(BookCopy.RentalItems))
                                   );
            Books.RemoveRange(Books);
            Users.RemoveRange(Users
                              .Include(nameof(User.Rentals))
                              );
#endif
            SaveChanges();

            Reseed(nameof(Users));
            Reseed(nameof(Books));
            Reseed(nameof(BookCopies));
            Reseed(nameof(Categories));
            Reseed(nameof(Rentals));
            Reseed(nameof(RentalItems));
        }
 public WinRental(Residence residence, Rentals rentals, Tenants tenants)
 {
     this.residence = residence;
     this.rentals   = rentals;
     this.tenants   = tenants;
     InitializeComponent();
 }
Exemplo n.º 22
0
        public async Task <IActionResult> Edit(Guid id, [Bind("Id,TimeStamp,Description,ImagePath")] Rentals rentals)
        {
            if (id != rentals.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(rentals);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!RentalsExists(rentals.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(rentals));
        }
Exemplo n.º 23
0
        public void StartMovieRental(NewRentalViewModel rvm)
        {
            var     config = new MapperConfiguration(cfg => { cfg.CreateMap <NewRentalViewModel, Rentals>(); cfg.IgnoreUnmapped(); });
            IMapper mapper = config.CreateMapper();
            Rentals r      = mapper.Map <NewRentalViewModel, Rentals>(rvm);

            rr.StartMovieRental(r);
        }
Exemplo n.º 24
0
        public void VideoStoreSetup()
        {
            idtMock = Substitute.For <IDatateTime>();

            Rental = new Rentals(idtMock);

            sut = new VideoStore(Rental);
        }
        public async Task <Rentals> SaveRental(Rentals rental)
        {
            using var context = _contextFactory.CreateDbContext();
            var r = context.Rentals.Add(rental);
            await context.SaveChangesAsync();

            return(r.Entity);
        }
        public ActionResult DeleteConfirmed(int id)
        {
            Rentals rentals = db.Rentals.Find(id);

            db.Rentals.Remove(rentals);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Exemplo n.º 27
0
 public int Rentals_Add(Rentals item)
 {
     using (var context = new StarTEDContext())
     {
         context.Rentals.Add(item);
         context.SaveChanges();
         return(item.RentalID);
     }
 }
Exemplo n.º 28
0
 public IResult Add(Rentals rental)
 {
     if (rental.RentDate == null)
     {
         return(new ErrorResult("Araba teslim edilmemiş"));
     }
     _rentalDal.Add(rental);
     return(new SuccessResult());
 }
Exemplo n.º 29
0
 public IResult Add(Rentals rental)
 {
     if (rental.ReturnDate == null)
     {
         return(new ErrorResult());
     }
     _rentalDal.Add(rental);
     return(new SuccessResult());
 }
Exemplo n.º 30
0
 public IResult Add(Rentals rent)
 {
     if (rent.ReturnDate == null)
     {
         return(new ErrorResult(Messages.Rented));
     }
     _rentalsDal.Add(rent);
     return(new SuccessResult(Messages.RentOk));
 }