示例#1
0
        private void btnAdd_Click(object sender, EventArgs e)              /// btn made an event (click event). by click becomes raised.
        {
            MoviesRepository mr    = new MoviesRepository();               /// here we have instantiated this in order to have access to Movierepository class
            DateTime         dr    = Convert.ToDateTime(dtpRelease.Value); /// here a  method and variable datettime is created. its value is from dtpicker
            string           title = txtName.Text;                         /// a variable created and its value is form txtbox.
            string           genre = txtGenre.Text;                        /// the same

            mr.AddMovie(title, dr, genre);                                 /// here those three variables are given and by clicking gets movies
            txtName.Clear();
            txtGenre.Clear();
            dtpRelease.Value = DateTime.Now;
        }
示例#2
0
        public ActionResult Create([Bind(Include = "Id,Name,YearOfRelease,PosterUrl,Plot")] Movie movie)
        {
            movie.ProducerId = int.Parse(Request["producer"]);
            string[]   actorsIdString;
            List <int> selectedActorsList = new List <int>();

            if (!string.IsNullOrEmpty(Request["actor"]))
            {
                actorsIdString = Request["actor"].Split(',');
                foreach (string actorId in actorsIdString)
                {
                    selectedActorsList.Add(int.Parse(actorId));
                }
            }
            else
            {
                actorsIdString = null;
            }
            if (ModelState.IsValid)
            {
                //foreach (int currentId in selectedActorsList)
                //{
                //    if (currentId == selectedActorsList.ElementAt(0))
                //        AddNewMovieActor(movie, currentId);
                //    else
                //    {
                //        AddMovieActor(movie.Id, currentId);
                //    }
                //}
                foreach (string file in Request.Files)
                {
                    var postedFile = Request.Files[file];
                    if (!string.IsNullOrEmpty(postedFile.FileName))
                    {
                        postedFile.SaveAs(Server.MapPath("~/Images/") + movie.Id.ToString() + Path.GetFileName(postedFile.FileName));
                        movie.PosterFilePath = "~/Images/" + movie.Id.ToString() + Path.GetFileName(postedFile.FileName);
                    }
                    else
                    {
                        movie.PosterFilePath = "~/Images/no-image.png";
                    }
                }
                moviesRepository.AddMovie(movie, selectedActorsList);
                TempData["Notification"] = movie.Name + " has been added succesfully to the movies database!";
                return(RedirectToAction("Index"));
            }

            ViewBag.ProducerSelected = movie.ProducerId;
            ViewBag.ActorsSelected   = selectedActorsList;
            ViewBag.Producers        = producersRepository.GetAllProducers();
            ViewBag.Actors           = actorsRepository.GetAllActors();
            return(View(movie));
        }
示例#3
0
        public ActionResult Create(AddMovieViewModel viewmodel)
        {
            try
            {
                String s    = viewmodel.Name;
                String path = "C:\\users\\rajat\\source\\repos\\IMBD\\IMBD\\Content\\Posters\\";
                //String path = ConfigurationManager.AppSettings["Path"];
                //   viewmodel.File.SaveAs(path+viewmodel.Id);


                Image source = Image.FromStream(viewmodel.File.InputStream);

                var NewMovie = new Movies()
                {
                    Name        = viewmodel.Name,
                    ReleaseDate = viewmodel.ReleaseDate,
                    Plot        = viewmodel.Plot,
                    PosterId    = 123,
                    ProducerId  = viewmodel.producer
                };
                moviesRepository.AddMovie(NewMovie);


                viewmodel.File.SaveAs(Path.Combine(@path, "" + NewMovie.Id + ".jpg"));

                foreach (int i in viewmodel.ActorIds)
                {
                    var actor_mov = new Actor_Movies()
                    {
                        MovieId = NewMovie.Id,
                        ActorId = i
                    };
                    actor_MoviesRepository.Add(actor_mov);
                }

                return(RedirectToAction("Add"));
            }
            catch
            {
                return(View());
            }
        }