예제 #1
0
        public async Task <IActionResult> Create([Bind("Id,Name,Birthdate,Biography,Photo")] Person person)
        {
            if (ModelState.IsValid)
            {
                var file = HttpContext.Request.Form.Files;
                if (file != null && file.Count > 0)
                {
                    var filePhoto   = file[0];
                    var pathDestine = Path.Combine(env.WebRootPath, "Image\\People");

                    if (filePhoto.Length > 0)
                    {
                        var fileDestine = Guid.NewGuid().ToString().Replace("-", "") + Path.GetExtension(filePhoto.FileName);

                        using (var filestrem = new FileStream(Path.Combine(pathDestine, fileDestine), FileMode.Create))
                        {
                            filePhoto.CopyTo(filestrem);
                            person.Photo = fileDestine;
                        };
                    }
                }

                _context.Add(person);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(person));
        }
예제 #2
0
        public async Task <IActionResult> Create([Bind("Id,Title,ReleaseDate,Photo,Trailer,Summary,GenderId,billboard")] Film film)
        {
            if (ModelState.IsValid)
            {
                var file = HttpContext.Request.Form.Files;
                if (file != null && file.Count > 0)
                {
                    var filePhoto   = file[0];
                    var pathDestine = Path.Combine(env.WebRootPath, "Image\\Movies");

                    if (filePhoto.Length > 0)
                    {
                        var fileDestine = Guid.NewGuid().ToString().Replace("-", "") + Path.GetExtension(filePhoto.FileName);

                        using (var filestrem = new FileStream(Path.Combine(pathDestine, fileDestine), FileMode.Create))
                        {
                            filePhoto.CopyTo(filestrem);
                            film.Photo = fileDestine;
                        };
                    }
                }

                _context.Add(film);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["GenderId"] = new SelectList(_context.Gender, "Id", "Description", film.GenderId);
            return(View(film));
        }
예제 #3
0
        public async Task <IActionResult> Create([Bind("Id,Description")] Gender gender)
        {
            if (ModelState.IsValid)
            {
                _context.Add(gender);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(gender));
        }
예제 #4
0
        public async Task <IActionResult> Create([Bind("FilmId,PersonId")] MovieActor movieActor)
        {
            if (ModelState.IsValid)
            {
                _context.Add(movieActor);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["FilmId"]   = new SelectList(_context.Film, "Id", "ReleaseDate", movieActor.FilmId);
            ViewData["PersonId"] = new SelectList(_context.Actor, "Id", "Biography", movieActor.PersonId);
            return(View(movieActor));
        }