示例#1
0
        public async Task <IActionResult> AddWatched(string name, int movieid)
        {
            var movie = await _context.Movie.FindAsync(movieid);

            var userExists = _context.UserMovies.Any(e => e.UserName == name);

            if (!userExists)
            {
                _context.UserMovies.Add(new UserMovies {
                    UserName = name
                });
                _context.SaveChanges();
            }
            var rrr = _context.UserMovies.Include(x => x.Watched).SingleOrDefault(user => user.UserName == name);

            rrr.Watched.Add(movie);
            _context.SaveChanges();

            ViewBag.Chan = "watched";
            var ll = new MovieVm {
                Movie = movie, UserId = User.Identity
            };

            return(View($"Details", ll));
        }
示例#2
0
        // GET: Movies/Cart/5
        public ActionResult Cart(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Movies movies = db.Movies.Find(id);

            if (movies == null)
            {
                return(HttpNotFound());
            }
            ////ViewBag.Tax = moviesTable.Price * 0.08;  //Replace with call to .Business project

            //TaxCalculate cl = new TaxCalculate();
            //ViewBag.Tax = cl.GetTaxCalc(movies.Price);
            //ViewBag.TotalPrice = cl.TotPrice(movies.Price);

            //return View("~/Views/Movies/Cart.cshtml", movies);  OR
            MovieVm vm = new MovieVm();

            vm.ID    = movies.ID;
            vm.Title = movies.Title;
            vm.Year  = movies.Year;
            vm.Price = movies.Price;
            TaxCalculate cl = new TaxCalculate();

            vm.Tax   = cl.GetTaxCalc(movies.Price);
            vm.Total = cl.TotPrice(movies.Price);
            return(View(vm));
        }
示例#3
0
        public IActionResult Upsert(int?id)
        {
            MovieVm movieVm = new MovieVm()
            {
                Movie     = new Movie(),
                GenreList = _unitOfWork.Genre.GetAll().Select(i => new SelectListItem
                {
                    Text  = i.Name,
                    Value = i.Id.ToString()
                }),
                AgeGroupList = _unitOfWork.AgeGroup.GetAll().Select(i => new SelectListItem
                {
                    Text  = i.Name,
                    Value = i.Id.ToString()
                })
            };

            if (id == null)
            {
                return(View(movieVm));
            }

            movieVm.Movie = _unitOfWork.Movie.Get(id.GetValueOrDefault());
            if (movieVm.Movie == null)
            {
                return(NotFound());
            }
            return(View(movieVm));
        }
 public ActionResult Edit([Bind(Include = "Id,Title,Year,Genre,Price")] MovieVm vm)
 {
     if (ModelState.IsValid)
     {
         var command = new ChangeMovieTitle(vm.Id, vm.Title);
         _commandSender.Send(command);
         return(RedirectToAction("Index"));
     }
     return(View(vm));
 }
        public ActionResult Create([Bind(Include = "Id,Title,Year,Genre,Price")] MovieVm vm)
        {
            if (ModelState.IsValid)
            {
                var command = new CreateMovie(Guid.NewGuid(), vm.Title, new DateTime(vm.Year, 1, 1), vm.Genre, vm.Price);
                _commandSender.Send(command);
                return(RedirectToAction("Index"));
            }

            return(View(vm));
        }
 public void OnGet(string searchstring, int pageIndex = 1)
 {
     movievm = _servicevm.GetMovieListVm(searchstring, pageIndex);
 }
 public void OnGet(string searchstring, int pageIndex = 1)
 {
     MovieVM           = _movieService.GetMovieIndexVm();
     MovieTrailerTopVM = _movieService.GetTrailerTopListVm();
 }
示例#8
0
        public IActionResult Upsert(MovieVm movieVm)
        {
            if (ModelState.IsValid)
            {
                string webRootPath = _hostEnvironment.WebRootPath;
                var    files       = HttpContext.Request.Form.Files;
                if (files.Count > 0)
                {
                    string fileName  = Guid.NewGuid().ToString();
                    var    uploads   = Path.Combine(webRootPath, @"images/products");
                    var    extention = Path.GetExtension(files[0].FileName);
                    if (movieVm.Movie.ImageUrl != null)
                    {
                        var imagePath = Path.Combine(webRootPath, movieVm.Movie.ImageUrl.TrimStart('\\'));
                        if (System.IO.File.Exists(imagePath))
                        {
                            System.IO.File.Delete(imagePath);
                        }
                    }

                    using (var fileStreams =
                               new FileStream(Path.Combine(uploads, fileName + extention), FileMode.Create))
                    {
                        files[0].CopyTo(fileStreams);
                    }

                    movieVm.Movie.ImageUrl = @"\images/products/" + fileName + extention;
                }
                else
                {
                    ///update when they do nog change the image
                    if (movieVm.Movie.Id != 0)
                    {
                        Movie objFromDb = _unitOfWork.Movie.Get(movieVm.Movie.Id);
                        movieVm.Movie.ImageUrl = objFromDb.ImageUrl;
                    }
                }
                if (movieVm.Movie.Id == 0)
                {
                    _unitOfWork.Movie.Add(movieVm.Movie);
                }
                else
                {
                    _unitOfWork.Movie.Update(movieVm.Movie);
                }
                _unitOfWork.Save();
                return(RedirectToAction(nameof(Index)));
            }
            else
            {
                movieVm.GenreList = _unitOfWork.Genre.GetAll().Select(i => new SelectListItem
                {
                    Text  = i.Name,
                    Value = i.Id.ToString()
                });

                movieVm.AgeGroupList = _unitOfWork.AgeGroup.GetAll().Select(i => new SelectListItem
                {
                    Text  = i.Name,
                    Value = i.Id.ToString()
                });
                if (movieVm.Movie.Id != 0)
                {
                    movieVm.Movie = _unitOfWork.Movie.Get(movieVm.Movie.Id);
                }
            }
            return(View(movieVm));
        }