public async Task <IActionResult> Edit(int id, [Bind("Id,MovieId,DateEntered,SellerId,Price")] MoviePrice moviePrice) { if (id != moviePrice.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(moviePrice); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!MoviePriceExists(moviePrice.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(moviePrice)); }
public override MoviePrice GetPrice(MoviePrice moviePrice) { var twoDaysWithDiscount = moviePrice.TwoDays * (1 - Discount); var lifeLongWithDiscount = moviePrice.LifeLong * (1 - Discount); return(new MoviePrice(twoDaysWithDiscount, lifeLongWithDiscount)); }
private RegisterMoviePriceViewModel ConvertMoviePriceToViewModel(MoviePrice moviePrice) { return(new RegisterMoviePriceViewModel { MovieFormatId = moviePrice.MovieFormatId, Price = moviePrice.Price.ToString(), Name = moviePrice.Name }); }
public ActionResult DeleteConfirmed(int id, string name) { MoviePrice moviePrice = db.MoviePrice. FirstOrDefault(item => item.MovieFormatId == id && item.Name == name); db.MoviePrice.Remove(moviePrice); db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult Edit([Bind(Include = "MoviePriceID,decMatineePrice,decTuesdayPrice,decWeekendPrice,decWeekPrice")] MoviePrice moviePrice) { if (ModelState.IsValid) { db.Entry(moviePrice).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index", "Movies")); } return(View(moviePrice)); }
// GET: MoviePrices/Create //public ActionResult Create() //{ // return View(); //} // POST: MoviePrices/Create // To protect from overposting attacks, please enable the specific properties you want to bind to, for // more details see https://go.microsoft.com/fwlink/?LinkId=317598. //[HttpPost] //[ValidateAntiForgeryToken] //public ActionResult Create([Bind(Include = "MoviePriceID,decMatineePrice,decTuesdayPrice,decWeekendPrice,decWeekPrice")] MoviePrice moviePrice) //{ // if (ModelState.IsValid) // { // db.MoviePrices.Add(moviePrice); // db.SaveChanges(); // return RedirectToAction("Index"); // } // return View(moviePrice); //} // GET: MoviePrices/Edit/5 public ActionResult Edit() { MoviePrice moviePrice = db.MoviePrices.Find(2); if (moviePrice == null) { return(HttpNotFound()); } return(View(moviePrice)); }
public async Task <IActionResult> Create([Bind("Id,MovieId,DateEntered,SellerId,Price")] MoviePrice moviePrice) { if (ModelState.IsValid) { _context.Add(moviePrice); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(moviePrice)); }
// GET: MoviePrices/Delete/5 public ActionResult Delete(int id, string name) { MoviePrice moviePrice = db.MoviePrice. FirstOrDefault(item => item.MovieFormatId == id && item.Name == name); if (moviePrice == null) { return(HttpNotFound()); } return(View(moviePrice)); }
public void SeedMoviePrice(AppDbContext db) { MoviePrice mp1 = new MoviePrice(); mp1.decMatineePrice = 5; mp1.decTuesdayPrice = 8; mp1.decWeekendPrice = 12; mp1.decWeekPrice = 10; db.MoviePrices.AddOrUpdate(mp => mp.decMatineePrice, mp1); db.SaveChanges(); }
public ActionResult Edit([Bind(Include = "MovieFormatId,Price,Name")] RegisterMoviePriceViewModel moviePrice) { if (ModelState.IsValid) { MoviePrice moviePricedb = ConvertViewModelToMoviePrice(moviePrice); db.Entry(moviePricedb).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.MovieFormatId = new SelectList(db.MovieFormat, "MovieFormatId", "Name", moviePrice.MovieFormatId); return(View(moviePrice)); }
// GET: MoviePrices //public ActionResult Index() //{ // return View(db.MoviePrices.ToList()); //} // GET: MoviePrices/Details/5 public ActionResult Details(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } MoviePrice moviePrice = db.MoviePrices.Find(id); if (moviePrice == null) { return(HttpNotFound()); } return(View(moviePrice)); }
// GET: MoviePrices/Edit/5 public ActionResult Edit(int id, string name) { MoviePrice moviePrice = db.MoviePrice. FirstOrDefault(item => item.MovieFormatId == id && item.Name == name); if (moviePrice == null) { return(HttpNotFound()); } RegisterMoviePriceViewModel moviePriceViewModel = ConvertMoviePriceToViewModel(moviePrice); ViewBag.MovieFormatId = new SelectList(db.MovieFormat, "MovieFormatId", "Name", moviePrice.MovieFormatId); return(View(moviePriceViewModel)); }
/// <summary> /// Demonstrates how to insert into multiple tables in a single transaction with EF Core linq syntax /// </summary> /// <remarks>This is the preferable way over a stored proc, since it keeps the logic in the application and works naturally with Entity Framework</remarks> /// <param name="model"></param> /// <returns></returns> private async Task <int> CreateMSPWithEFEntities(MovieSellerPriceViewModel model) { //Create movie var newMovie = new Movie() { Title = model.Title, ReleaseDate = model.ReleaseDate, Genre = model.Genre, Price = model.MSRPPrice }; //Add seller and price if indicated if (!string.IsNullOrEmpty(model.SellerName)) { var newSeller = new Seller() { Address1 = model.Address1, City = model.City, Name = model.SellerName, Phone = model.Phone, State = model.State, URL = model.URL, Zip = model.Zip }; var newSellerPrice = new MoviePrice() { Price = model.SellerPrice, }; //Seller Price has a seller, so add seller to that collection newSellerPrice.Seller = newSeller; //Movies has a Prices collection. Add sellerprice to movie. This creates a graph of Movie->SellerPrice->Seller that //EF can traverse to figure out the relationships and populate the Foreign keys during creation newMovie.Prices = new List <MoviePrice>(); newMovie.Prices.Add(newSellerPrice); } _context.Movie.Add(newMovie); return(await _context.SaveChangesAsync()); }
private MoviePrice ConvertViewModelToMoviePrice(RegisterMoviePriceViewModel moviePriceViewModel) { MoviePrice moviePrice = db.MoviePrice. FirstOrDefault(item => item.MovieFormatId == moviePriceViewModel.MovieFormatId && item.Name == moviePriceViewModel.Name); decimal.TryParse(moviePriceViewModel.Price, out decimal price); if (moviePrice == null) { moviePrice = new MoviePrice { MovieFormatId = moviePriceViewModel.MovieFormatId, Name = moviePriceViewModel.Name, Price = price }; } else { moviePrice.Price = price; } return(moviePrice); }
public override MoviePrice GetPrice(MoviePrice moviePrice) { return(new MoviePrice(moviePrice.TwoDays, moviePrice.LifeLong)); }
public abstract MoviePrice GetPrice(MoviePrice moviePrice);
public static Decimal GetTicketPrice(DateTime ShowDate) { //we need a db context to connect to the database AppDbContext db = new AppDbContext(); //Create return value decimal decTicketPrice; ////Initiate bol values to figure out what day/time it is Boolean bolWeekend = false; //Variable to check whether the current day is a Weekday(M-F) Boolean bolMatinee = false; //Variable to check whether current time < 12:00pm Boolean bolFriday = false; //Variable to check whether current day is Friday, because half of friday is the weekend Boolean bolTuesday = false; //Variable to check whether it is a discount day or not Boolean bolBefore5 = false; //Variable to check whether it is = or < 5pm //Create movieprice object that references the most recent record of the MoviePriceID MoviePrice movieprice = db.MoviePrices.FirstOrDefault(x => x.MoviePriceID == 1); ////Get prices of different showings to be able to compare and populate booleans Decimal decMoviePriceMat = movieprice.decMatineePrice; Decimal decMoviePriceWeek = movieprice.decWeekPrice; Decimal decMoviePriceWeeknd = movieprice.decWeekendPrice; Decimal decMoviePriceTues = movieprice.decTuesdayPrice; //Convert showtime date into a comparable type String strday = ShowDate.DayOfWeek.ToString(); Int32 inthour = ShowDate.Hour; //Use Decisions statements to accurately populate booleans if (strday == "Friday") { bolFriday = true; } if ((strday == "Saturday") || (strday == "Sunday")) { bolWeekend = true; } if (strday == "Tuesday") { bolTuesday = true; } if (inthour < 12) { bolMatinee = true; } else if (inthour < 17) { bolBefore5 = true; } ////Filter and process through booleans, Call data from Ticket Price, and assign appropriate values to decTicketPrice if ((bolTuesday) && (bolBefore5)) // Check if discount rate applies (Tuesday and before 5pm) { decTicketPrice = decMoviePriceTues; } else if ((bolWeekend) || (bolFriday && !(bolMatinee))) //Check if it is a weekend (friday > 12pm through Sunday evening) { decTicketPrice = decMoviePriceWeeknd; } else if (bolMatinee) //Checks if time is before 12pm and through process of elimination falls on a weekday { decTicketPrice = decMoviePriceMat; } else //Handles all weekdays after 12pm { decTicketPrice = decMoviePriceWeek; } //return the value return(decTicketPrice); }