Exemplo n.º 1
0
        public ActionResult Create(MovieGenresDirectorsRatingsFormats mgdrf)
        {
            try
            {
                if (mgdrf.File != null)
                {
                    mgdrf.Movie.ImagePath = mgdrf.File.FileName;
                    string target = Path.Combine(Server.MapPath("~/images"), Path.GetFileName(mgdrf.File.FileName));

                    if (!System.IO.File.Exists(target))
                    {
                        mgdrf.File.SaveAs(target);
                        ViewBag.Message = "File Uploaded Successfullly...";
                    }
                    else
                    {
                        ViewBag.Message = "File already exists...";
                    }
                }

                MovieManager.Insert(mgdrf.Movie);
                mgdrf.GenreIds.ToList().ForEach(a => MovieGenreManager.Add(mgdrf.Movie.Id, a));
                return(RedirectToAction("Index"));
            }
            catch (Exception ex)
            {
                ViewBag.Message = ex.Message;
                return(View(mgdrf));
            }
        }
Exemplo n.º 2
0
        public ActionResult Edit(int id, MovieGenresDirectorsRatingsFormats mgdrf)
        {
            try
            {
                if (mgdrf.File != null)
                {
                    mgdrf.Movie.ImagePath = mgdrf.File.FileName;
                    string target = Path.Combine(Server.MapPath("~/images"), Path.GetFileName(mgdrf.File.FileName));

                    if (!System.IO.File.Exists(target))
                    {
                        mgdrf.File.SaveAs(target);
                        ViewBag.Message = "File Uploaded Successfullly...";
                    }
                    else
                    {
                        ViewBag.Message = "File already exists...";
                    }
                }

                // Deal with the Genres
                IEnumerable <int> oldgenreids = new List <int>();
                if (Session["genreids"] != null)
                {
                    oldgenreids = (IEnumerable <int>)Session["genreids"];
                }

                IEnumerable <int> newgenreids = new List <int>();
                if (mgdrf.GenreIds != null)
                {
                    newgenreids = mgdrf.GenreIds;
                }

                // Identify the deletes
                IEnumerable <int> deletes = oldgenreids.Except(newgenreids);    // Get the old ones that arent in the new ones

                // Identify the adds
                IEnumerable <int> adds = newgenreids.Except(oldgenreids);

                deletes.ToList().ForEach(d => MovieGenreManager.Delete(id, d));
                adds.ToList().ForEach(a => MovieGenreManager.Add(id, a));

                // TODO: Add update logic here
                MovieManager.Update(mgdrf.Movie);
                return(RedirectToAction("Index"));
            }
            catch (Exception ex)
            {
                ViewBag.Message = ex.Message;
                return(View());
            }
        }
Exemplo n.º 3
0
 public ActionResult Delete(int id, Movie movie)
 {
     try
     {
         // TODO: Add delete logic here
         movie.Genres = MovieManager.LoadGenres(id);
         movie.Genres.ForEach(g => MovieGenreManager.Delete(id, g.Id));
         MovieManager.Delete(id);
         return(RedirectToAction("Index"));
     }
     catch
     {
         return(View());
     }
 }