Esempio n. 1
0
        public async Task <IActionResult> FilmManage(int?id)
        {
            Film film = null;

            if (!(id is null))
            {
                film = await DB.Films.FindAsync(id);

                if (film is null)
                {
                    return(View("Error"));
                }
            }

            SelectList genresList = new SelectList(DB.Genres.ToList(), "LINK", "Name");

            ViewBag.Genres = genresList;
            SelectList directorsList = new SelectList(DB.Directors.ToList(), "LINK", "Name");

            ViewBag.Directors = directorsList;
            SelectList countriesList = new SelectList(DB.Countries.ToList(), "LINK", "Name");

            ViewBag.Countries = countriesList;
            SelectList ageLimitsList = new SelectList(DB.AgeLimits.ToList(), "LINK", "Value");

            ViewBag.AgeLimits = ageLimitsList;

            FilmManageViewModel model = new FilmManageViewModel();

            model.Film = film;
            return(View(model));
        }
Esempio n. 2
0
        public async Task <IActionResult> FilmManage(FilmManageViewModel model)
        {
            if (ModelState.IsValid)
            {
                if (!model.Film.Poster.EndsWith(".jpg"))
                {
                    model.Film.Poster = model.Film.Poster + ".jpg";
                }

                var film = await DB.Films.FindAsync(model.Film.LINK);

                if (film != null)
                {
                    foreach (var prop in film.GetType().GetProperties())
                    {
                        prop.SetValue(film, model.Film.GetType().GetProperty(prop.Name).GetValue(model.Film));
                    }
                    DB.Entry(film).State = EntityState.Modified;
                }
                else
                {
                    DB.Entry(model.Film).State = EntityState.Added;
                }
            }
            else
            {
                SelectList genresList = new SelectList(DB.Genres.ToList(), "LINK", "Name");
                ViewBag.Genres = genresList;
                SelectList directorsList = new SelectList(DB.Directors.ToList(), "LINK", "Name");
                ViewBag.Directors = directorsList;
                SelectList countriesList = new SelectList(DB.Countries.ToList(), "LINK", "Name");
                ViewBag.Countries = countriesList;
                SelectList ageLimitsList = new SelectList(DB.AgeLimits.ToList(), "LINK", "Value");
                ViewBag.AgeLimits = ageLimitsList;
                return(View(model));
            }

            if (model.UploadedFile != null &&
                (model.UploadedFile.FileName.EndsWith(".jpg")))
            //model.UploadedFile.SaveAs(Server.MapPath("~/Content/Images/Posters/" + model.Film.Poster));
            {
                using (var fileStream = new FileStream(Url.Content("~/images/Posters/" + model.UploadedFile.FileName), FileMode.Create))
                {
                    await model.UploadedFile.CopyToAsync(fileStream);
                }
            }

            await DB.SaveChangesAsync();

            return(RedirectToAction("Affiche", "Home"));
        }
Esempio n. 3
0
        public async Task <IActionResult> FilmManage()
        {
            Film film = null;
            var  link = Request.Query["id"].ToString();

            if (!(link is null) && link != String.Empty)
            {
                if (!Int32.TryParse(link.ToString(), out int l))
                {
                    return(View("Error"));
                }
                film = await DB.Films.FindAsync(l);

                if (film == null)
                {
                    return(View("Error"));
                }
                if (film.Archived == true)
                {
                    return(View("Error"));
                }
            }

            SelectList genresList = new SelectList(DB.Genres.ToList(), "LINK", "Name");

            ViewBag.Genres = genresList;
            SelectList directorsList = new SelectList(DB.Directors.ToList(), "LINK", "Name");

            ViewBag.Directors = directorsList;
            SelectList countriesList = new SelectList(DB.Countries.ToList(), "LINK", "Name");

            ViewBag.Countries = countriesList;
            SelectList ageLimitsList = new SelectList(DB.AgeLimits.ToList(), "LINK", "Value");

            ViewBag.AgeLimits = ageLimitsList;

            FilmManageViewModel model = new FilmManageViewModel();

            model.Film = film;
            return(View(model));
        }