public async Task <IActionResult> Create(MovieCreateVM viewModel) { var genres = context.GetAllGenres(); viewModel.Genres = context.GetSelectedListItem(genres); if (!ModelState.IsValid) { return(View(viewModel)); } int id = context.AddMovie(viewModel); var uploads = Path.Combine(hostingEnvironment.WebRootPath, "img"); var file = viewModel.Image; if (file.Length > 0) { var filePath = Path.Combine(uploads, $"{id}{Path.GetExtension(file.FileName)}"); using (var fileStream = new FileStream(filePath, FileMode.Create)) { await file.CopyToAsync(fileStream); } } return(RedirectToAction(nameof(MoviesController.Display))); }
public IActionResult Create(MovieCreateVM viewModel) { if (!ModelState.IsValid) { return(View(viewModel)); } context.AddMovie(viewModel); return(RedirectToAction(nameof(MoviesController.Index))); }
public IActionResult Create(MovieCreateVM viewModel) { var genres = context.GetAllGenres(); viewModel.Genres = context.GetSelectedListItem(genres); if (!ModelState.IsValid) { return(View(viewModel)); } context.AddMovie(viewModel); return(RedirectToAction(nameof(MoviesController.Index))); }