Example #1
0
        public async Task <IActionResult> Create([Bind("Id,Name,Description,Year,Director,PathImg")] Film film, IFormFile uploadedFile)
        {
            if (ModelState.IsValid)
            {
                if (uploadedFile != null)
                {
                    string path = "/img/" + uploadedFile.FileName;
                    using (var fileStream = new FileStream(_appEnvironment.WebRootPath + path, FileMode.Create))
                    {
                        await uploadedFile.CopyToAsync(fileStream);
                    }
                    film.PathImg = path;
                }

                film.UserId = Request.Form["UserID"];
                await _film.Add(film);

                return(RedirectToAction(nameof(Index)));
            }
            return(View(film));
        }