public bool SaveFilm(FilmActorCategoryViewModel filmActorCategoryViewModel) { bool isFilmExist = GetAllFilms().Any(f => f.Title == filmActorCategoryViewModel.Title); if (isFilmExist) { return(false); } return(filmGateway.SaveFilm(filmActorCategoryViewModel)); }
public ActionResult Create(FilmActorCategoryViewModel filmActorCategoryViewModel) { bool isSaved = filmManager.SaveFilm(filmActorCategoryViewModel); if (isSaved) { ViewBag.Error = false; return(RedirectToAction("Index")); } ViewBag.Rating = filmManager.GetAllRating(); ViewBag.Category = categoryManager.GetAllCategories(); ViewBag.Error = true; return(View()); }
public bool SaveFilm(FilmActorCategoryViewModel filmActorCategoryViewModel) { using (SqlConnection connection = new SqlConnection(connectionString)) { SqlCommand command = new SqlCommand("sp_CreateFilms", connection); command.CommandType = CommandType.StoredProcedure; command.Parameters.AddWithValue("@Title", filmActorCategoryViewModel.Title); command.Parameters.AddWithValue("@Description", filmActorCategoryViewModel.Description); command.Parameters.AddWithValue("@ReleaseYear", filmActorCategoryViewModel.ReleaseYear); command.Parameters.AddWithValue("@RentalDuration", filmActorCategoryViewModel.RentalDuration); command.Parameters.AddWithValue("@RentalRate", filmActorCategoryViewModel.RentalRate); command.Parameters.AddWithValue("@Rating", filmActorCategoryViewModel.Rating); command.Parameters.AddWithValue("@ActorFirstName", filmActorCategoryViewModel.FirstName); command.Parameters.AddWithValue("@ActorLastName", filmActorCategoryViewModel.LastName); command.Parameters.AddWithValue("@CategoryId", filmActorCategoryViewModel.CategoryId); SqlParameter filmId = new SqlParameter(); filmId.DbType = DbType.Int32; filmId.ParameterName = "@FilmId"; filmId.Direction = ParameterDirection.Output; command.Parameters.Add(filmId); SqlParameter actorId = new SqlParameter(); actorId.DbType = DbType.Int32; actorId.ParameterName = "@ActorId"; actorId.Direction = ParameterDirection.Output; command.Parameters.Add(actorId); connection.Open(); int rowAffected = command.ExecuteNonQuery(); /* int one = Convert.ToInt32(filmId); * int two = Convert.ToInt32(actorId);*/ connection.Close(); if (rowAffected > 0) { return(true); } return(false); } }