public async Task <IActionResult> Edit(VideoEditViewModel model) { if (!ModelState.IsValid) { return(View(model)); } var dbItem = await InitParam.Db.Video.FirstOrDefaultAsync(h => h.Id == model.Id); if (dbItem == null) { return(NotFound()); } dbItem.FkNgonNgu = model.NgonNguId; dbItem.TieuDe = model.TieuDe; dbItem.GioiThieu = model.GioiThieu; dbItem.HinhAnh = model.HinhAnh; dbItem.DuongDanFile = model.DuongDanFile; dbItem.NgaySua = DateTime.Now; dbItem.UserNguoiSua = "admin"; await InitParam.Db.SaveChangesAsync(); return(RedirectToAction(nameof(Edit), new { id = model.Id })); }
public IActionResult Create(VideoEditViewModel model) { var video = new Video { Title = model.Title, Genre = model.Genre }; _videos.Add(video); return(RedirectToAction("Details", new { id = video.Id })); }
public IActionResult Edit(int id, VideoEditViewModel model) { var video = _videos.Get(id); if (video == null && !ModelState.IsValid) { return(View(model)); } video.Title = model.Title; video.Genre = model.Genre; _videos.Commit(); return(RedirectToAction("Details", new { id = video.Id })); }
[HttpPost] // The HTTP POST takes place after the video has been edited/after pressing edit. public IActionResult Edit(int id, VideoEditViewModel model) { var video = _videos.Get(id); // Get the id of the video that is being edited. if (video == null || !ModelState.IsValid) // If the video doesn't exist or is invalid, simply show the old details of the video. { return(View(model)); } video.Title = model.Title; // Assign the input title from the ViewModel to the video. video.Genre = model.Genre; // Assign the input genre from the ViewModel to the video. _videos.Commit(); return(RedirectToAction("Details", new { id = video.Id })); }
public IActionResult Create(VideoEditViewModel model) { if (ModelState.IsValid) { var video = new Video { Title = model.Title, Genre = model.Genre }; service.Add(video); service.Commit(); return(RedirectToAction("Details", new { id = video.Id })); } return(View()); }
public IActionResult Create(VideoEditViewModel model) { if (ModelState.IsValid) { var video = new Video { Genre = model.Genre, Id = model.Id, Title = model.Title }; _videos.Add(video); return(RedirectToAction("Details", new { id = video.Id })); } return(View()); }
public IActionResult Create(VideoEditViewModel model) { if (ModelState.IsValid) { var video = new Video() { Title = model.Title, Genre = model.Genre }; _videoDataRepository.AddNewVideo(video); return(RedirectToAction("Details", new { id = video.Id })); } return(View()); }
public IActionResult Create(VideoEditViewModel model) // using VideoEditViewModel as the model to base the fields for the form on { if (ModelState.IsValid) { var video = new Video // Here we match the form inputs to the respective properties in the ViewModel { Title = model.Title, Genre = model.Genre }; _videos.Add(video); _videos.Commit(); return(RedirectToAction("Details", new { id = video.Id })); } return(View()); }
public IActionResult Create(VideoEditViewModel model) { if (ModelState.IsValid) { var video = new Video { Title = model.Title, Genre = model.Genre }; _videos.Add(video); // Add is the method from IVideoData --- void Add(Video newVideo); _videos.Commit(); // ??? return(RedirectToAction("Details", new { id = video.Id })); } return(View()); }
public IActionResult Edit(int id, VideoEditViewModel videoEditViewModel) { var video = _videoDataRepository.GetVideoById(id); if (video != null) { if (ModelState.IsValid) { video.Title = videoEditViewModel.Title; video.Genre = videoEditViewModel.Genre; _videoDataRepository.Commit(); return(RedirectToAction("Details", new { id = video.Id })); } else { return(View()); } } else { return(RedirectToAction("Index")); } }