//Lägger till en film med en roll public void MovieFormView_InsertItem(Movie movie, Role role) { if (Page.ModelState.IsValid) { try { Service.InsertMovie(movie, role); MessageStatus = "The movie was added successfully."; Response.RedirectToRoute("Movies"); Context.ApplicationInstance.CompleteRequest(); } catch (Exception) { ModelState.AddModelError(String.Empty, "An error occured when trying to add a movie."); } } }
//Skapar en ny roll i databasen eller uppdaterar en befintlig public void SaveRole(Role role) { ICollection<ValidationResult> validationResults; if (!role.Validate(out validationResults)) { var ex = new ValidationException("The object did not pass the validation."); ex.Data.Add("ValidationResults", validationResults); throw ex; } if (role.RoleID == 0) { RoleDAL.InsertRole(role); } else { RoleDAL.UpdateRole(role); } }
//Skapar en ny film i databasen public void InsertMovie(Movie movie, Role role) { ICollection<ValidationResult> validationResults; if (!movie.Validate(out validationResults) && !role.Validate(out validationResults)) { var ex = new ValidationException("The object did not pass the validation."); ex.Data.Add("ValidationResult", validationResults); throw ex; } MovieDAL.InsertMovie(movie, role); }
//Lägger till en ny roll public void RoleListView_InsertItem(Role role) { if (Page.ModelState.IsValid) { try { role.MovieID = GetMovieID; Service.SaveRole(role); //Rättmeddelande MessageStatus = "The role was added successfully."; Response.RedirectToRoute("MovieEdit", new { id = GetMovieID }); Context.ApplicationInstance.CompleteRequest(); } catch (Exception) { ModelState.AddModelError(String.Empty, "An error occured when trying to add a role."); } } }