public async Task <IActionResult> Edit(int id, [Bind("RentedMovieId,CusId,TvShowId,RentalDate,ReturnDate")] RentedMovie rentedMovie) { if (id != rentedMovie.RentedMovieId) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(rentedMovie); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!RentedMovieExists(rentedMovie.RentedMovieId)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } ViewData["CusId"] = new SelectList(_context.Customers, "CustomersId", "FirstName", rentedMovie.CusId); ViewData["TvShowId"] = new SelectList(_context.TvShow, "TvId", "Title", rentedMovie.TvShowId); return(View(rentedMovie)); }
public async Task <IActionResult> PutRentedMovie(int id, RentedMovie rentedMovie) { if (id != rentedMovie.Id) { return(BadRequest()); } _context.Entry(rentedMovie).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!RentedMovieExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <ActionResult <RentedMovie> > PostRentedMovie(RentedMovie rentedMovie) { /* * rentedMovie.MovieId = Convert.ToInt32(rentedMovie.MovieId); * rentedMovie.StudioId = Convert.ToInt32(rentedMovie.StudioId); */ var movie = _context.Movies.Where(i => i.Id == rentedMovie.MovieId).First(); _context.RentedMovies.Add(rentedMovie); await _context.SaveChangesAsync(); List <RentedMovie> rentedMovies = await _context.RentedMovies.ToListAsync(); bool rentedExtended = rentingHandler.MovieRentingLimiter(rentedMovies, rentedMovie, movie); if (rentedExtended == false) { _context.RentedMovies.Remove(rentedMovie); await _context.SaveChangesAsync(); throw new Exception("DENIED!!!!"); } var rentReciept = _context.RentedMovies.Include(i => i.Movie).Include(i => i.Studio).OrderByDescending(i => i.Id).First(); string reciept = "Studio: " + rentReciept.Studio.Name + "\nCity: " + rentReciept.Studio.City + "\nRented movie: " + rentReciept.Movie.Title + "\nDate: " + DateTime.Now; Console.WriteLine(reciept); return(null); //CreatedAtAction("GetRentedMovie", new { id = rentedMovie.Id }, rentedMovie); }
public ActionResult DeleteConfirmed(int id) { RentedMovie rentedMovie = db.RentedMovies.Find(id); db.RentedMovies.Remove(rentedMovie); db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult Edit([Bind(Include = "RentedMovieID,ReceiptNumber,CostToRent,RentalDate,ExpirationDate,TimesRented")] RentedMovie rentedMovie) { if (ModelState.IsValid) { db.Entry(rentedMovie).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(rentedMovie)); }
public async Task <IActionResult> Create([Bind("RentedMovieId,CusId,TvShowId,RentalDate,ReturnDate")] RentedMovie rentedMovie) { if (ModelState.IsValid) { _context.Add(rentedMovie); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["CusId"] = new SelectList(_context.Customers, "CustomersId", "FirstName", rentedMovie.CusId); ViewData["TvShowId"] = new SelectList(_context.TvShow, "TvId", "Title", rentedMovie.TvShowId); return(View(rentedMovie)); }
// GET: RentedMovies/Delete/5 public ActionResult Delete(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } RentedMovie rentedMovie = db.RentedMovies.Find(id); if (rentedMovie == null) { return(HttpNotFound()); } return(View(rentedMovie)); }
public ActionResult Create([Bind(Include = "RentedMovieID,ReceiptNumber,CostToRent,RentalDate,ExpirationDate,TimesRented")] RentedMovie rentedMovie) { if (ModelState.IsValid) { rentedMovie.ReceiptNumber = rentedMovie.RentedMovieID + 100; rentedMovie.RentalDate = DateTime.Now; rentedMovie.ExpirationDate = rentedMovie.RentalDate.AddDays(1); db.RentedMovies.Add(rentedMovie); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(rentedMovie)); }
public static bool AddNewRentedMovie(RentedMovie newRentedMovie) { try { //addnewrentedmovie method must be here so that we use the same context, and thus save the changes.. _context.RentedMovies.Add(newRentedMovie); _context.Database.Log = Console.WriteLine; _context.SaveChanges(); return(true); } catch (Exception) { return(false); } }
public void AddRent() { using (var ctx = new MyMediaEntities()) { RentedMovie newRent = new RentedMovie(); Console.Write("Enter Customer ID: "); newRent.CustomerID = int.Parse(Console.ReadLine()); Console.Write("Enter Movie ID: "); newRent.MovieID = int.Parse(Console.ReadLine()); newRent.RentExpires = DateTime.Now.AddDays(7); ctx.RentedMovies1.Add(newRent); ctx.SaveChanges(); } }
// public async Task<IActionResult> Return(int TvShowId, int CusId) public void Return(int TvShowId, int CusId) { RentedMovie rentedMovie = _context.RentedMovie.FirstOrDefault(a => a.ReturnDate == default && a.TvShowId == TvShowId); rentedMovie.ReturnDate = DateTime.Now; _context.Update(rentedMovie); _context.SaveChanges(); // await _context.SaveChangesAsync(); TvShow TvShow = _context.TvShow.FirstOrDefault(a => a.TvId == TvShowId); TvShow.Available = false; _context.Update(TvShow); _context.SaveChanges(); // return RedirectToAction("Index", "TvShows"); }
private void AddRental(VideoStoreContext videoStore, Rental rental) { var rentedMovie = new RentedMovie { MovieId = rental.MovieId, UserId = rental.UserId, }; --rental.Movie.NumOfCopies; videoStore.Movies.Attach(rental.Movie); videoStore.Entry(rental.Movie).Property(m => m.NumOfCopies).IsModified = true; rental.Movie = null; rental.User = null; videoStore.Rentals.Add(rental); videoStore.RentedMovies.Add(rentedMovie); }
public void Rent(int TvShowId, int CusId) { RentedMovie rentedMovie = new RentedMovie(); rentedMovie.TvShowId = TvShowId; rentedMovie.CusId = CusId; rentedMovie.RentalDate = DateTime.Now; _context.Add(rentedMovie); _context.SaveChanges(); // await _context.SaveChangesAsync(); TvShow TvShow = _context.TvShow.FirstOrDefault(a => a.TvId == TvShowId); TvShow.Available = true; _context.Update(TvShow); _context.SaveChanges(); // await _context.SaveChangesAsync(); // return RedirectToAction("Index", "TvShows"); }