public MovieDetailModel AddMovieDirectors(string DirectorFirstName, string DirectorLastName)
        {
            //bool status = false;
            string conStr = ConfigurationManager.ConnectionStrings["ConnectToStopNShopDatabase"].ConnectionString;
            SqlConnection conn = new SqlConnection(conStr);
            MovieDetailModel DirObj = null;
            try
            {
                conn.Open();

                SqlCommand check = new SqlCommand("select count(*) from MovieDirectors where FirstName=@firstname and LastName=@lastname", conn);
                check.Parameters.AddWithValue("firstname", DirectorFirstName);
                check.Parameters.AddWithValue("lastname", DirectorLastName);

                int num =(int)check.ExecuteScalar();

                if (num == 0)
                {
                    SqlCommand cmd = new SqlCommand("insert into MovieDirectors values (@firstname,@lastname)", conn);
                    cmd.Parameters.AddWithValue("firstname", DirectorFirstName);
                    cmd.Parameters.AddWithValue("lastname", DirectorLastName);
                    int res = cmd.ExecuteNonQuery();
                    //status = true;
                    SqlCommand id = new SqlCommand("select Id,FirstName,LastName from MovieDirectors where FirstName=@firstname and LastName=@lastname", conn);
                    id.Parameters.AddWithValue("firstname", DirectorFirstName);
                    id.Parameters.AddWithValue("lastname", DirectorLastName);
                    var reader = id.ExecuteReader();
                    if (reader.HasRows)
                    {
                        reader.Read();
                        DirObj = new MovieDetailModel();
                        DirObj.DirectorGenerID = reader.GetInt32(reader.GetOrdinal("Id"));
                        DirObj.DirectorFirstName = reader.GetString(reader.GetOrdinal("FirstName"));
                        DirObj.DirectorLastName = reader.GetString(reader.GetOrdinal("LastName"));
                        DirObj.DataError = null;
                    }
                }
                else
                {
                    DirObj = new MovieDetailModel();
                    DirObj.DirectorGenerID=-1;
                }
            }
            catch (Exception exc)
            {
                HttpContext.Current.Session["ErrorMessage"] = exc.Message;
            }
            conn.Close();
            return DirObj;
        }
        public string AddMovie(string MovieName,string DirectorName,string GenreName,int Rating, int Duration,int DVDcopy,int Cost)
        {
            if (ModelState.IsValid)
            {
                MoviesDetails dalObj = new MoviesDetails();
                MovieDetailModel movieObject = new MovieDetailModel();
                movieObject = dalObj.AddMovie(MovieName,DirectorName,GenreName,Rating,Duration,DVDcopy,Cost);
                if (movieObject != null)
                {
                    ViewBag.Message = "MovieId" + movieObject.MovieID;
                    return movieObject.MovieID.ToString();
                }

            }
            return "false";
        }
        public string AddGenre(string GenreNameInput)
        {
            if (ModelState.IsValid)
            {
                MoviesDetails dalObj = new MoviesDetails();
                MovieDetailModel genreObject = new MovieDetailModel();
                genreObject = dalObj.AddMovieGenres(GenreNameInput);
                if (genreObject != null)
                {
                    ViewBag.Message = "GenreId" + genreObject.DirectorGenerID;
                    return genreObject.DirectorGenerID.ToString();
                }

            }
            return "false";
        }
        public string AddDirector(string DirectorFirstName, string DirectorLastName)
        {
            if (ModelState.IsValid)
            {
                MoviesDetails DalObj = new MoviesDetails();
                MovieDetailModel DirObject = new MovieDetailModel();
                DirObject=DalObj.AddMovieDirectors(DirectorFirstName, DirectorLastName);
                if (DirObject.DirectorGenerID != -1)
                {
                    ViewBag.Message = "DirectorId" + DirObject.DirectorGenerID;

                }
                else
                {
                    ViewBag.Messgae = "-1";
                }
                return DirObject.DirectorGenerID.ToString();

            }
            return "false";
        }
        public MovieDetailModel AddMovie(string MovieName, string DirectorName, string GenreName, int Rating, int Duration, int DVDcopy, int Cost)
        {
            string conStr = ConfigurationManager.ConnectionStrings["ConnectToStopNShopDatabase"].ConnectionString;
            SqlConnection conn = new SqlConnection(conStr);
            MovieDetailModel movieObj = null;
            try
            {
                conn.Open();

                SqlCommand cmd = new SqlCommand("insert into Movies values (@directorname,@genrename,@moviename,@rating,@duration,@dvdcopy,@cost)", conn);
                cmd.Parameters.AddWithValue("directorname", DirectorName);
                cmd.Parameters.AddWithValue("genrename", GenreName);
                cmd.Parameters.AddWithValue("moviename", MovieName);
                cmd.Parameters.AddWithValue("rating", Rating);
                cmd.Parameters.AddWithValue("duration", Duration);
                cmd.Parameters.AddWithValue("dvdcopy", DVDcopy);
                cmd.Parameters.AddWithValue("cost", Cost);
                int res = cmd.ExecuteNonQuery();
                //status = true;
                SqlCommand id = new SqlCommand("select Id,Name from Movies where Name=@moviename and MovieDirectorName=@directorname", conn);
                id.Parameters.AddWithValue("moviename", MovieName);
                id.Parameters.AddWithValue("directorname", DirectorName);
                var reader = id.ExecuteReader();
                if (reader.HasRows)
                {
                    reader.Read();
                    movieObj = new MovieDetailModel();
                    movieObj.MovieID = reader.GetInt32(reader.GetOrdinal("Id"));
                    movieObj.MovieName = reader.GetString(reader.GetOrdinal("Name"));

                }
            }
            catch (Exception exc)
            {
                HttpContext.Current.Session["ErrorMessage"] = exc.Message;
            }
            conn.Close();
            return movieObj;
        }
        public ActionResult Index(string DirectorFirstName, string DirectorLastName)
        {
            if (ModelState.IsValid)
            {
                MoviesDetails DalObj = new MoviesDetails();
                MovieDetailModel DirObject = new MovieDetailModel();
                DirObject=DalObj.AddMovieDirectors(DirectorFirstName, DirectorLastName);
                if (DirObject!=null)
                {
                    if (DirObject.DataError == null)
                    {
                        ViewBag.message = "Director ID " + DirObject.DirectorGenerID;
                    }
                    else
                    {
                        ViewBag.message ="-1";
                    }
                    return View();
                }

            }
            return View();
        }
        public MovieDetailModel AddMovieGenres(string GenreNameInput)
        {
            string conStr = ConfigurationManager.ConnectionStrings["ConnectToStopNShopDatabase"].ConnectionString;
            SqlConnection conn = new SqlConnection(conStr);
            MovieDetailModel genreObj = null;
            try
            {
                conn.Open();

                SqlCommand cmd = new SqlCommand("insert into MovieGenres values (@genrename)", conn);
                cmd.Parameters.AddWithValue("genrename", GenreNameInput);
                int res = cmd.ExecuteNonQuery();
                //status = true;
                SqlCommand id = new SqlCommand("select Id,GenreName from MovieGenres where GenreName=@genrename", conn);
                id.Parameters.AddWithValue("genrename", GenreNameInput);
                var reader = id.ExecuteReader();
                if (reader.HasRows)
                {
                    reader.Read();
                    genreObj = new MovieDetailModel();
                    genreObj.DirectorGenerID = reader.GetInt32(reader.GetOrdinal("Id"));
                    genreObj.GenreNameInput = reader.GetString(reader.GetOrdinal("GenreName"));
                }
            }
            catch (Exception exc)
            {
                HttpContext.Current.Session["ErrorMessage"] = exc.Message;
            }
            conn.Close();
            return genreObj;
        }