示例#1
0
 public ActionResult Edit(ProducerViewModel producerViewModel, HttpPostedFileBase image)
 {
     if (ModelState.IsValid)
     {
         Producer oldProducer = _producerService.Find(producerViewModel.Id);
         if (oldProducer == null)
         {
             return(HttpNotFound());
         }
         Producer producer = Mapper.Map <Producer>(producerViewModel);
         if (image != null)
         {
             if (CheckImageUploadExtension.CheckImagePath(image.FileName) == true)
             {
                 var path = Path.Combine(Server.MapPath("~/Images/Upload"), image.FileName);
                 image.SaveAs(path);
                 producer.Thumbnail = VariableUtils.UrlUpLoadImage + image.FileName;
             }
         }
         else
         {
             if (oldProducer.Thumbnail != null)
             {
                 producer.Thumbnail = oldProducer.Thumbnail;
             }
         }
         _producerService.Update(producer, producer.Id);
         return(RedirectToAction("Index"));
     }
     return(View(producerViewModel));
 }
 public ActionResult Edit(CategorysViewModel categorysViewModel, HttpPostedFileBase image)
 {
     if (ModelState.IsValid)
     {
         Category oldCategory = _categorysService.Find(categorysViewModel.Id);
         if (oldCategory == null)
         {
             return(HttpNotFound());
         }
         Category category = Mapper.Map <Category>(categorysViewModel);
         if (image != null)
         {
             if (CheckImageUploadExtension.CheckImagePath(image.FileName) == true)
             {
                 var path = Path.Combine(Server.MapPath("~/Images/Upload"), image.FileName);
                 image.SaveAs(path);
                 category.Thumbnail = VariableUtils.UrlUpLoadImage + image.FileName;
             }
         }
         else
         {
             if (oldCategory.Thumbnail != null)
             {
                 category.Thumbnail = oldCategory.Thumbnail;
             }
         }
         _categorysService.Update(category, category.Id);
         return(RedirectToAction("Index"));
     }
     return(View(categorysViewModel));
 }
        public ActionResult Edit(NewsViewModel newsViewModel, HttpPostedFileBase image)
        {
            if (ModelState.IsValid)
            {
                var oldNews = _newsService.Find(newsViewModel.Id);
                var news    = Mapper.Map <News>(newsViewModel);
                if (image != null &&
                    image.FileName != null &&
                    CheckImageUploadExtension.CheckImagePath(image.FileName) == true)
                {
                    var path = Path.Combine(Server.MapPath("~/Images/Upload"), image.FileName);
                    image.SaveAs(path);
                    news.Thumbnail = VariableUtils.UrlUpLoadImage + image.FileName;
                }
                else if (image == null && oldNews.Thumbnail != null)
                {
                    news.Thumbnail = oldNews.Thumbnail;
                }
                _newsService.Update(news, news.Id);
                return(RedirectToAction("Index"));
            }
            var listMovie  = _moviesService.GetAll();
            var listSelect = new List <SelectListItem>();

            if (listMovie != null)
            {
                foreach (var item in listMovie)
                {
                    if (item.Id == newsViewModel.MovieId)
                    {
                        listSelect.Add(new SelectListItem()
                        {
                            Value    = item.Id.ToString(),
                            Text     = item.Name,
                            Selected = true
                        });
                    }
                    else
                    {
                        listSelect.Add(new SelectListItem()
                        {
                            Value    = item.Id.ToString(),
                            Text     = item.Name,
                            Selected = false
                        });
                    }
                }
            }

            ViewBag.ListMovie = listSelect;

            return(View(newsViewModel));
        }
        public ActionResult Edit(TrailerViewModel trailerViewModel, HttpPostedFileBase image)
        {
            if (image != null &&
                image.FileName != null &&
                CheckImageUploadExtension.CheckImagePath(image.FileName) == true)
            {
                var path = Path.Combine(Server.MapPath("~/Images/Upload"), image.FileName);
                image.SaveAs(path);
                trailerViewModel.Thumbnail = VariableUtils.UrlUpLoadImage + image.FileName;
            }

            Trailer trailer = Mapper.Map <Trailer>(trailerViewModel);

            _trailerService.Update(trailer, trailer.Id);
            return(RedirectToAction("Index"));
        }
示例#5
0
        public ActionResult ChangeAvatar(UpdateUserViewModel model, HttpPostedFileBase image)
        {
            ApplicationUser currentUser = _userService.Find(model.Id);

            if (currentUser != null && image != null)
            {
                if (CheckImageUploadExtension.CheckImagePath(image.FileName) == true)
                {
                    var path = Path.Combine(Server.MapPath("~/Images/Upload"), image.FileName);
                    image.SaveAs(path);
                    currentUser.Avatar = VariableUtils.UrlUpLoadImage + image.FileName;
                }
                _userService.Update(currentUser, model.Id);
            }

            return(RedirectToAction("Index"));
        }
 public ActionResult Edit(ActorViewModel actorViewModel, HttpPostedFileBase image)
 {
     if (ModelState.IsValid)
     {
         Actor actor = Mapper.Map <Actor>(actorViewModel);
         if (image != null &&
             image.FileName != null &&
             CheckImageUploadExtension.CheckImagePath(image.FileName) == true)
         {
             var path = Path.Combine(Server.MapPath("~/Images/Upload"), image.FileName);
             image.SaveAs(path);
             actor.Thumbnail = VariableUtils.UrlUpLoadImage + image.FileName;
         }
         _actorsService.Update(actor, actor.Id);
         return(RedirectToAction("Index"));
     }
     return(View(actorViewModel));
 }
 public ActionResult Create(CategorysViewModel categorysViewModel, HttpPostedFileBase image)
 {
     if (ModelState.IsValid)
     {
         categorysViewModel.Id = Guid.NewGuid();
         Category category = Mapper.Map <Category>(categorysViewModel);
         if (image != null)
         {
             if (CheckImageUploadExtension.CheckImagePath(image.FileName) == true)
             {
                 var path = Path.Combine(Server.MapPath("~/Images/Upload"), image.FileName);
                 image.SaveAs(path);
                 category.Thumbnail = VariableUtils.UrlUpLoadImage + image.FileName;
             }
         }
         _categorysService.Create(category);
         return(RedirectToAction("Index"));
     }
     return(PartialView("_CreateCategorys", categorysViewModel));
 }
        public ActionResult Create(TrailerViewModel trailerViewModel, HttpPostedFileBase image)
        {
            if (ModelState.IsValid)
            {
                if (image != null &&
                    image.FileName != null &&
                    CheckImageUploadExtension.CheckImagePath(image.FileName) == true)
                {
                    var path = Path.Combine(Server.MapPath("~/Images/Upload"), image.FileName);
                    image.SaveAs(path);
                    trailerViewModel.Thumbnail = VariableUtils.UrlUpLoadImage + image.FileName;
                }


                trailerViewModel.Id = Guid.NewGuid();
                Trailer trailer = Mapper.Map <Trailer>(trailerViewModel);
                _trailerService.Create(trailer);
                return(RedirectToAction("Index"));
            }
            return(PartialView("_CreateTrailer", trailerViewModel));
        }
        public ActionResult Create(NewsViewModel newsViewModel, HttpPostedFileBase image)
        {
            if (ModelState.IsValid)
            {
                newsViewModel.Id = Guid.NewGuid();

                var news = Mapper.Map <News>(newsViewModel);
                if (image != null)
                {
                    if (CheckImageUploadExtension.CheckImagePath(image.FileName) == true)
                    {
                        var path = Path.Combine(Server.MapPath("~/Images/Upload"), image.FileName);
                        image.SaveAs(path);
                        news.Thumbnail = VariableUtils.UrlUpLoadImage + image.FileName;
                    }
                }
                _newsService.Create(news);

                return(RedirectToAction("Index"));
            }
            var listMovie  = _moviesService.GetAll();
            var listSelect = new List <SelectListItem>();

            if (listMovie != null)
            {
                foreach (var item in listMovie)
                {
                    listSelect.Add(new SelectListItem()
                    {
                        Value = item.Id.ToString(),
                        Text  = item.Name
                    });
                }
            }

            ViewBag.ListMovie = listSelect;
            return(PartialView("_Create", newsViewModel));
        }
        public ActionResult Create(ActorViewModel actorViewModel, HttpPostedFileBase image)
        {
            if (ModelState.IsValid)
            {
                actorViewModel.Id = Guid.NewGuid();

                Actor actor = Mapper.Map <Actor>(actorViewModel);
                if (image != null)
                {
                    if (CheckImageUploadExtension.CheckImagePath(image.FileName) == true)
                    {
                        var path = Path.Combine(Server.MapPath("~/Images/Upload"), image.FileName);
                        image.SaveAs(path);
                        actor.Thumbnail = VariableUtils.UrlUpLoadImage + image.FileName;
                    }
                }
                _actorsService.Create(actor);

                return(RedirectToAction("Index"));
            }

            return(PartialView("_Create", actorViewModel));
        }
示例#11
0
        public ActionResult Edit(FeatureFilmViewModel viewModel, HttpPostedFileBase image,
                                 IList <string> actor, IList <string> director,
                                 IList <string> category, IList <string> producer,
                                 IList <string> resolution, IList <string> tag)
        {
            Movie oldMovie = _movieService.Find(viewModel.MoviesViewModel.Id);

            var movie = AutoMapper.Mapper.Map <Movie>(viewModel.MoviesViewModel);
            var film  = AutoMapper.Mapper.Map <Film>(viewModel.FilmViewModel);

            if (image != null &&
                image.FileName != null &&
                CheckImageUploadExtension.CheckImagePath(image.FileName) == true)
            {
                var path = Path.Combine(Server.MapPath("~/Images/Upload"), image.FileName);
                image.SaveAs(path);
                movie.Thumbnail = VariableUtils.UrlUpLoadImage + image.FileName;
            }
            else
            {
                if (oldMovie.Thumbnail != null)
                {
                    movie.Thumbnail = oldMovie.Thumbnail;
                }
            }
            film.MovieId = movie.Id;
            _movieService.Update(movie, movie.Id);
            _filmService.Update(film, film.Id);

            IList <string> _actor = new List <string>();

            if (actor != null)
            {
                foreach (var item in actor)
                {
                    _actor.Add(item);
                }
            }
            var listActorMovie = _actorMovieService.GetIdActorByMovieId(movie.Id);

            foreach (var item in listActorMovie)
            {
                if (!_actor.Contains(item.ToString()))
                {
                    var model = _actorMovieService.FindBy2Id(movie.Id, item);
                    if (model != null)
                    {
                        _actorMovieService.Delete(model);
                    }
                }
                else
                {
                    _actor.Remove(item.ToString());
                }
            }

            IList <string> _director = new List <string>();

            if (director != null)
            {
                foreach (var item in director)
                {
                    _director.Add(item);
                }
            }
            var listDirectorMovie = _directorMovieService.GetIdDirectorByMovieId(movie.Id);

            foreach (var item in listDirectorMovie)
            {
                if (!_director.Contains(item.ToString()))
                {
                    var model = _directorMovieService.FindBy2Id(movie.Id, item);
                    if (model != null)
                    {
                        _directorMovieService.Delete(model);
                    }
                }
                else
                {
                    _director.Remove(item.ToString());
                }
            }

            IList <string> _category = new List <string>();

            if (category != null)
            {
                foreach (var item in category)
                {
                    _category.Add(item);
                }
            }
            var listCategoryMovie = _categoryMovieService.GetIdCategoryByMovieId(movie.Id);

            foreach (var item in listCategoryMovie)
            {
                if (!_category.Contains(item.ToString()))
                {
                    var model = _categoryMovieService.FindBy2Id(movie.Id, item);
                    if (model != null)
                    {
                        _categoryMovieService.Delete(model);
                    }
                }
                else
                {
                    _category.Remove(item.ToString());
                }
            }

            IList <string> _producer = new List <string>();

            if (producer != null)
            {
                foreach (var item in producer)
                {
                    _producer.Add(item);
                }
            }
            var listProducerMovie = _producerMovieService.GetIdProducerByMovieId(movie.Id);

            foreach (var item in listProducerMovie)
            {
                if (!_producer.Contains(item.ToString()))
                {
                    var model = _producerMovieService.FindBy2Id(movie.Id, item);
                    if (model != null)
                    {
                        _producerMovieService.Delete(model);
                    }
                }
                else
                {
                    _producer.Remove(item.ToString());
                }
            }

            IList <string> _resolution = new List <string>();

            if (resolution != null)
            {
                foreach (var item in resolution)
                {
                    _resolution.Add(item);
                }
            }
            var listResolutionMovie = _resolutionMovieService.GetIdResolutionByMovieId(movie.Id);

            foreach (var item in listResolutionMovie)
            {
                if (!_resolution.Contains(item.ToString()))
                {
                    var model = _resolutionMovieService.FindBy2Id(movie.Id, item);
                    if (model != null)
                    {
                        _resolutionMovieService.Delete(model);
                    }
                }
                else
                {
                    _resolution.Remove(item.ToString());
                }
            }

            IList <string> _tag = new List <string>();

            if (tag != null)
            {
                foreach (var item in tag)
                {
                    _tag.Add(item);
                }
            }
            var listTagMovie = _tagMovieService.GetIdTagByMovieId(movie.Id);

            foreach (var item in listTagMovie)
            {
                if (!_tag.Contains(item.ToString()))
                {
                    var model = _tagMovieService.FindBy2Id(movie.Id, item);
                    if (model != null)
                    {
                        _tagMovieService.Delete(model);
                    }
                }
                else
                {
                    _tag.Remove(item.ToString());
                }
            }


            if (_actor != null)
            {
                foreach (var item in _actor)
                {
                    _actorMovieService.Create(new ActorMovie()
                    {
                        ActorId = Guid.Parse(item),
                        MovieId = movie.Id
                    });
                }
            }
            if (_director != null)
            {
                foreach (var item in _director)
                {
                    _directorMovieService.Create(new DirectorMovie()
                    {
                        DirectorId = Guid.Parse(item),
                        MovieId    = movie.Id
                    });
                }
            }
            if (_category != null)
            {
                foreach (var item in _category)
                {
                    _categoryMovieService.Create(new CategoryMovie()
                    {
                        CategoryId = Guid.Parse(item),
                        MovieId    = movie.Id
                    });
                }
            }
            if (_producer != null)
            {
                foreach (var item in _producer)
                {
                    _producerMovieService.Create(new ProducerMovie()
                    {
                        ProducerId = Guid.Parse(item),
                        MovieId    = movie.Id
                    });
                }
            }
            if (_resolution != null)
            {
                foreach (var item in _resolution)
                {
                    _resolutionMovieService.Create(new MovieResolution()
                    {
                        ResolutionId = Guid.Parse(item),
                        MovieId      = movie.Id
                    });
                }
            }
            if (_tag != null)
            {
                foreach (var item in _tag)
                {
                    _tagMovieService.Create(new TagMovie()
                    {
                        TagId   = Guid.Parse(item),
                        MovieId = movie.Id
                    });
                }
            }
            return(RedirectToAction("Index"));
        }
示例#12
0
        public ActionResult Create(FeatureFilmViewModel viewModel, HttpPostedFileBase image,
                                   IEnumerable <string> actor, IEnumerable <string> director,
                                   IEnumerable <string> category, IEnumerable <string> producer,
                                   IEnumerable <string> resolution, IEnumerable <string> tag)
        {
            var filmViewModel  = viewModel.FilmViewModel;
            var movieViewModel = viewModel.MoviesViewModel;

            var film  = AutoMapper.Mapper.Map <Film>(filmViewModel);
            var movie = AutoMapper.Mapper.Map <Movie>(movieViewModel);

            movie.IsSeriesMovie = false;
            film.MovieId        = movie.Id;

            if (image != null &&
                image.FileName != null &&
                CheckImageUploadExtension.CheckImagePath(image.FileName) == true)
            {
                var path = Path.Combine(Server.MapPath("~/Images/Upload"), image.FileName);
                image.SaveAs(path);
                movie.Thumbnail = VariableUtils.UrlUpLoadImage + image.FileName;
            }

            _movieService.Create(movie);
            _filmService.Create(film);

            if (actor != null)
            {
                foreach (var item in actor)
                {
                    _actorMovieService.Create(new ActorMovie()
                    {
                        ActorId = Guid.Parse(item),
                        MovieId = movie.Id
                    });
                }
            }
            if (director != null)
            {
                foreach (var item in director)
                {
                    _directorMovieService.Create(new DirectorMovie()
                    {
                        DirectorId = Guid.Parse(item),
                        MovieId    = movie.Id
                    });
                }
            }
            if (category != null)
            {
                foreach (var item in category)
                {
                    _categoryMovieService.Create(new CategoryMovie()
                    {
                        CategoryId = Guid.Parse(item),
                        MovieId    = movie.Id
                    });
                }
            }
            if (producer != null)
            {
                foreach (var item in producer)
                {
                    _producerMovieService.Create(new ProducerMovie()
                    {
                        ProducerId = Guid.Parse(item),
                        MovieId    = movie.Id
                    });
                }
            }
            if (resolution != null)
            {
                foreach (var item in resolution)
                {
                    _resolutionMovieService.Create(new MovieResolution()
                    {
                        ResolutionId = Guid.Parse(item),
                        MovieId      = movie.Id
                    });
                }
            }
            if (tag != null)
            {
                foreach (var item in tag)
                {
                    _tagMovieService.Create(new TagMovie()
                    {
                        TagId   = Guid.Parse(item),
                        MovieId = movie.Id
                    });
                }
            }
            return(RedirectToAction("Index"));
        }