public async Task <ActionResult> Create() { // Ein leeres Model erstellt und an View übergeben // Oder wir legen eine Movie-Objekt mit Defaultwerten an Movie movie = new Movie { MovieId = Guid.NewGuid(), GenreId = new Guid("86dfdd65-ebda-489e-945f-3becc5b28783"), MediumTypeId = new Guid("6592fcbb-2adb-43fb-9a1f-c90b968950a8"), ReleaseDate = DateTime.Now }; HzgWebService svc = new HzgWebService(); NewEditMovieModel model = new NewEditMovieModel(); model.Movie = movie; /* Genre und Mediumtype Listen initialisieren */ await InitGenreMediumtypes(model, svc); // Model an View übergeben. return(View(model)); }
public async Task <ActionResult> Edit(NewEditMovieModel model) { if (!ModelState.IsValid) { return(View(model)); } // damit wir wieder zu dem Formular zurück springen woher wir her gekommen sind. string returnUri = null; if (Request.Params.AllKeys.Contains("ReturnUri")) { returnUri = Request.Params["ReturnUri"]; } try { HzgWebService svc = new HzgWebService(); await svc.UpdateMovie(model.Movie); if (returnUri == null) { return(Redirect("Movie/Index")); } return(Redirect(returnUri)); } catch (Exception ex) { // Logger (Log4Net) - um Exception zu loggen. throw ex; } }
public async Task <ActionResult> Edit(string id) { HzgWebService svc = new HzgWebService(); NewEditMovieModel model = new NewEditMovieModel(); // damit wir wieder auf die richtige Seite zurück finden if (Request.Params.AllKeys.Contains("ReturnUri")) { ViewBag.ReturnUri = Request.Params["ReturnUri"]; } else { ViewBag.ReturnUri = "/Movie/Index"; } var movie = await svc.GetMovieById(id); if (movie == null) { return(RedirectToAction("Index")); } model.Movie = movie; model.Mode = Mode.Edit; /* Genre und Mediumtype Listen initialisieren */ await InitGenreMediumtypes(model, svc); return(View(model)); }
public async Task <ActionResult> Create(NewEditMovieModel model) { try { HzgWebService svc = new HzgWebService(); await svc.CreateMovie(model.Movie); return(RedirectToAction("Index")); } catch { return(View()); } }
private async Task InitGenreMediumtypes(NewEditMovieModel model, HzgWebService svc) { /* Genre und Mediumtype Listen initialisieren */ var genres = await svc.GetAllGenres(); model.Genres.AddRange(genres.Select(g => new SelectListItem { Value = g.GenreId.ToString(), Text = g.GenreCd })); var mediumTypes = await svc.GetAllMediumTypes(); model.MediumTypes.AddRange(mediumTypes.Select(m => new SelectListItem { Value = m.MediumTypeId.ToString(), Text = m.Bezeichnung })); }