private void btnSave_Click(object sender, EventArgs e) { try { /*Helper Variable to Insert inside MovieCastRoleMapping*/ int movieId, castId, castRoleId; /* Find Movie*/ var _movie = _movieService.FindMovie(_Movie.movieLink); if (_movie == null) { /*To bring new Id from Movie Service*/ movieId = _movieService.GenerateMovieId(_Movie); } else { movieId = _movie.movieId; } foreach (var star in _Starts) { var _cast = _castService.FindCast(star.starLink); if (_cast == null) { /*To bring new Id from Cast Service*/ castId = _castService.CastGenerateCastId(star); } else { castId = _cast.castId; } var castRoleTest = _castRoleService.FindCastRole("Star"); if (castRoleTest == null) { /*To bring new Id from CastRole Service*/ castRoleId = _castRoleService.CastRoleGenerateCastRoleId("Star"); } else { castRoleId = castRoleTest.castRoleId; } /* Insert For mapping*/ bool insertState = false; insertState = _movieCastRoleMappingService.MovieCastRoleMappingGenareteId(castId, castRoleId, movieId); if (insertState == true) { continue; } } foreach (var writer in _Writers) { var _cast = _castService.FindCast(writer.writerLink); if (_cast == null) { /*To bring new Id from Cast Service*/ castId = _castService.CastGenerateCastId(writer); } else { castId = _cast.castId; } var castRoleTest = _castRoleService.FindCastRole("Writer"); if (castRoleTest == null) { /*To bring new Id from CastRole Service*/ castRoleId = _castRoleService.CastRoleGenerateCastRoleId("Writer"); } else { castRoleId = castRoleTest.castRoleId; } /* Insert For mapping*/ bool insertState = false; insertState = _movieCastRoleMappingService.MovieCastRoleMappingGenareteId(castId, castRoleId, movieId); if (insertState == true) { continue; } } foreach (var director in _Directors) { var _cast = _castService.FindCast(director.directorLink); if (_cast == null) { /*To bring new Id from Cast Service*/ castId = _castService.CastGenerateCastId(director); } else { castId = _cast.castId; } var castRoleTest = _castRoleService.FindCastRole("Director"); if (castRoleTest == null) { /*To bring new Id from CastRole Service*/ castRoleId = _castRoleService.CastRoleGenerateCastRoleId("Director"); } else { castRoleId = castRoleTest.castRoleId; } /* Insert For mapping*/ bool insertState = false; insertState = _movieCastRoleMappingService.MovieCastRoleMappingGenareteId(castId, castRoleId, movieId); if (insertState == true) { continue; } } MessageBox.Show("Movie saved to Database"); } catch { MessageBox.Show("Something went wrong!"); } }