public ActionResult DeleteConfirmed(int id) { MoviesTV moviesTV = db.MoviesTVs.Find(id); //Delete the image file of the record that is being removed if (moviesTV.TitleImage != null && moviesTV.TitleImage != "NoImage.png") { string path = Server.MapPath("~/Content/img/MoviesTV/"); ImageUploadUtility.Delete(path, moviesTV.TitleImage); } db.MoviesTVs.Remove(moviesTV); db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult Delete(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } MoviesTV moviesTV = db.MoviesTVs.Find(id); if (moviesTV == null) { return(HttpNotFound()); } return(View(moviesTV)); }
public ActionResult Edit([Bind(Include = "MovieTVID,DiscTypeID,RegionCodeID,UPC,TitleTypeID,Title,Description,GenreID,Runtime,MPAARatingID,Price,UnitsSold,ReleaseDate,StudioID,TitleImage,IsSiteFeature,IsOnSaleFeature,TitleStatusID")] MoviesTV moviesTV, HttpPostedFileBase titleCover) { if (ModelState.IsValid) { #region File Upload if (titleCover != null) { string file = titleCover.FileName; string ext = file.Substring(file.LastIndexOf('.')); string[] goodExts = { ".jpeg", ".jpg", ".png", ".gif" }; //check that the uploaded file ext is in our list of good file extensions if (goodExts.Contains(ext)) { //if valid ext, check file size <= 4mb (max by default from ASP.NET) if (titleCover.ContentLength <= 4194304) { //create a new file name using a guid //file = Guid.NewGuid() + ext; #region Resize Image string savePath = Server.MapPath("~/Content/img/MoviesTV/"); Image convertedImage = Image.FromStream(titleCover.InputStream); int maxImageSize = 650; int maxThumbSize = 250; ImageUploadUtility.ResizeImage(savePath, file, convertedImage, maxImageSize, maxThumbSize); #endregion if (moviesTV.TitleImage != null && moviesTV.TitleImage != "NoImage.png") { string path = Server.MapPath("~/Content/img/MoviesTV/"); ImageUploadUtility.Delete(path, moviesTV.TitleImage); } } } moviesTV.TitleImage = file; } #endregion db.Entry(moviesTV).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.GenreID = new SelectList(db.Genres, "GenreID", "GenreName", moviesTV.GenreID); ViewBag.StudioID = new SelectList(db.Studios, "StudioID", "StudioName", moviesTV.StudioID); ViewBag.TitleStatusID = new SelectList(db.TitleStatuses, "TitleStatusID", "TitleStatusName", moviesTV.TitleStatusID); ViewBag.DiscTypeID = new SelectList(db.DiscTypes, "DiscTypeID", "DiscTypeName", moviesTV.DiscTypeID); ViewBag.TitleTypeID = new SelectList(db.TitleTypes, "TitleTypeID", "TitleTypeName", moviesTV.TitleTypeID); ViewBag.RegionCodeID = new SelectList(db.RegionCodes, "RegionCodeID", "RegionCodeID", moviesTV.RegionCodeID); ViewBag.MPAARatingID = new SelectList(db.MPAARatings, "MPAARatingID", "Rating", moviesTV.MPAARatingID); return(View(moviesTV)); }
public ActionResult AddToCart(int qty, int movieTVID) { //We will use a Dictionary collection type to store items into the cart //Dictionaries store info as Key, Value pairs Dictionary <int, CartItemViewModel> shoppingCart = null; //check if the session variable called cart already exists - if it does we will use it to populate the local collection of shopping cart items we called shoppingCart if (Session["cart"] != null) { //session variable already exists and we will put items from it into our Dictionary called shoppingCart (local list of shopping cart items) shoppingCart = (Dictionary <int, CartItemViewModel>)Session["cart"]; //when we UNBOX an object stored in Session to it's smaller more specific type we are using explicit casting } else { //if session cart doesn't exist yet, we need to instantiate it (aka NEW IT UP) shoppingCart = new Dictionary <int, CartItemViewModel>(); } //after the if/else above we have a local version of the shopping cart list that is ready to have items added to it //find the product referenced by the ID that was passed to this method MoviesTV product = db.MoviesTVs.Where(m => m.MovieTVID == movieTVID).FirstOrDefault(); if (product == null) { //if bad ID, kick them back to the same page to try again or you could throw an error return(RedirectToAction("Index")); } else { //if the book IS valid, add the line-item to the cart CartItemViewModel item = new CartItemViewModel(qty, product); //put item in the local cart BUT if we already have that product as a cart item, then we will just update the quantity //THIS is why Dictionary is a great choice for the shopping cart collection if (shoppingCart.ContainsKey(product.MovieTVID)) { shoppingCart[product.MovieTVID].Qty += qty; } else { shoppingCart.Add(product.MovieTVID, item); } //now update the Session version of Shopping Cart so we can maintain the info between request/response cycles Session["cart"] = shoppingCart; //implicit casting or boxing Session["confirm"] = $"'{product.Title}' (Quantity: {qty}) added to cart"; } //send the user to a view that shows their cart items return(RedirectToAction("Index", "ShoppingCart")); }
public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } MoviesTV moviesTV = db.MoviesTVs.Find(id); if (moviesTV == null) { return(HttpNotFound()); } ViewBag.GenreID = new SelectList(db.Genres, "GenreID", "GenreName", moviesTV.GenreID); ViewBag.StudioID = new SelectList(db.Studios, "StudioID", "StudioName", moviesTV.StudioID); ViewBag.TitleStatusID = new SelectList(db.TitleStatuses, "TitleStatusID", "TitleStatusName", moviesTV.TitleStatusID); ViewBag.DiscTypeID = new SelectList(db.DiscTypes, "DiscTypeID", "DiscTypeName", moviesTV.DiscTypeID); ViewBag.TitleTypeID = new SelectList(db.TitleTypes, "TitleTypeID", "TitleTypeName", moviesTV.TitleTypeID); ViewBag.RegionCodeID = new SelectList(db.RegionCodes, "RegionCodeID", "RegionCodeID", moviesTV.RegionCodeID); ViewBag.MPAARatingID = new SelectList(db.MPAARatings, "MPAARatingID", "Rating", moviesTV.MPAARatingID); return(View(moviesTV)); }
//FQCTOR public CartItemViewModel(int qty, MoviesTV product) { Qty = qty; Product = product; }
// GET: MoviesTV/Details/5 public ActionResult Details(int?id, int?formatId) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } MoviesTV moviesTV = db.MoviesTVs.Find(id); if (moviesTV == null) { return(HttpNotFound()); } #region Actors var movieActors = db.MovieTVActors.Where(m => m.MovieTVID == id).ToList(); var actors = db.Actors.ToList(); List <Actor> cast = new List <Actor>(); foreach (var a in actors) { foreach (var ma in movieActors) { if (a.ActorID == ma.ActorID) { a.ActorOrder = ma.ActorOrder; a.Character = ma.Character; cast.Add(a); } } } ViewBag.Cast = cast; #endregion #region Directors var movieDirectors = db.MovieTVDirectors.Where(m => m.MovieTVID == id).ToList(); var directors = db.Directors.ToList(); List <Director> directedBy = new List <Director>(); foreach (var d in directors) { foreach (var md in movieDirectors) { if (d.DirectorID == md.DirectorID) { d.DirectorOrder = md.DirectorOrder; directedBy.Add(d); } } } ViewBag.DirectedBy = directedBy; #endregion #region Writers var movieWriters = db.MovieTVWriters.Where(m => m.MovieTVID == id).ToList(); var writers = db.Writers.ToList(); List <Writer> writtenBy = new List <Writer>(); foreach (var w in writers) { foreach (var mw in movieWriters) { if (w.WriterID == mw.WriterID) { w.WriterOrder = mw.WriterOrder; writtenBy.Add(w); } } } ViewBag.WrittenBy = writtenBy; #endregion #region Related Products ViewBag.RelatedMoviesTVs = db.MoviesTVs.ToList(); #endregion return(View(moviesTV)); }