//Special Info private void button1ShowData_Click(object sender, EventArgs e) { try { //Customer Who Borrows Most Movies if (radioButton1.Checked) { TabControl.SelectedTab = TabControl.TabPages["RentedMovies"]; DataTable dt = new RentalMovie().BorrowMostMovies(); gvRental.DataSource = dt; gvRental.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.AllCells); } else if (radioButton2.Checked) //Most Popular Movies { TabControl.SelectedTab = TabControl.TabPages["RentedMovies"]; DataTable dt = new RentalMovie().PopularMovies(); gvRental.DataSource = dt; gvRental.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.AllCells); } else if (radioButton3.Checked) //Show All Rented Movies { TabControl.SelectedTab = TabControl.TabPages["RentedMovies"]; BindGridRentedMovies(); } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
// Bind rented movies grid private void BindGridRentedMovies() { DataTable ds = new RentalMovie().GetAllRentedData(); gvRental.DataSource = ds; gvRental.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.AllCells); }
// This should be fairly safe action since handling a known object that is retreived from a click.. public ActionResult ReturnRentalMovie(int id) { RentalMovie rm = db.RentalMovies.Find(id); db.Entry(rm).State = EntityState.Modified; rm.RentEnd = DateTime.Now; db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult Rent(string movieid, string customerid) { if (ModelState.IsValid && !string.IsNullOrEmpty(customerid)) { // RentEnd cannot be null so we say "if RentStart is the same as RentEnd then the movie is rented" RentalMovie movie = new RentalMovie() { MovieId = Int32.Parse(movieid), CustomerId = Int32.Parse(customerid), RentStart = DateTime.Now, RentEnd = DateTime.Now }; db.RentalMovies.Add(movie); db.SaveChanges(); return(RedirectToAction("Index")); } return(RedirectToAction("Index", "Movie", null)); }
private async Task <bool> HasPenalty(RentalMovie entity, CancellationToken cancellationToken) { bool penalty = false; if (entity.ReturnDate < DateTime.Now) { penalty = true; entity.PenaltyMoney = PENALTY_VALUE; entity.IsPenaltySolved = false; } else { var stock = await _context.Stocks.FindAsync(entity.StockId); stock.IsAvailable = true; } await _context.SaveChangesAsync(cancellationToken); return(penalty); }
public async Task <Unit> Handle(RentalMovieCommand request, CancellationToken cancellationToken) { _logger.LogInformation($"Rental Movie Info: UserId {request.RentalMovies.Select(rm => rm.UserId).First()}, Date: {DateTime.Now}, Quantity: {request.RentalMovies.Count()}"); foreach (var req in request.RentalMovies) { var entity = new RentalMovie() { UserId = req.UserId, RentalDate = DateTime.Now, StatusMovie = req.StatusMovie, ReturnDate = CheckRentedMovie(req.StatusMovie, req.Days), StockId = req.StockId }; _context.RentalMovies.Add(entity); await _context.SaveChangesAsync(cancellationToken); await UpdateStock(req.StockId, cancellationToken, req.StatusMovie); } return(Unit.Value); }