//Action from Building Form section //GET: Medias/New public ActionResult New() { var viewModel = new MediaFormModelView() { Media = new Media(), MediaTypeList = _context.MediaTypes.ToList(), GenreList = _context.Genres.ToList() }; return(View("MediaForm", viewModel)); }
public ActionResult Save(Media media) { //server side validation -start if (!ModelState.IsValid) { var viewModel = new MediaFormModelView() { Media = media, MediaTypeList = _context.MediaTypes.ToList(), GenreList = _context.Genres.ToList() }; return(View("MediaForm", viewModel)); } //Server side validation -end if (media.ID == 0) { _context.Medias.Add(media); } else { var selectedMedia = _context.Medias.Single(c => c.ID == media.ID); /* * TryUpdateModel(selectedcustomer) * this the default to update used by Ms but has security problem * work around used mapper */ selectedMedia.Name = media.Name; selectedMedia.MediaTypeID = media.MediaTypeID; selectedMedia.ReleaseDate = media.ReleaseDate; selectedMedia.GenreID = media.GenreID; selectedMedia.NumberInStock = media.NumberInStock; selectedMedia.DateAdded = media.DateAdded; } _context.SaveChanges(); return(RedirectToAction("Index", "Medias")); }