Example #1
0
        public MovieModel GetMovieById(int id)
        {
            _genreServices = new GenreServices();
            var model = new MovieModel();

            using (SqlConnection con = new SqlConnection(connect))
            {
                con.Open();
                SqlCommand cmd = new SqlCommand("GetMovieById", con);
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.AddWithValue("@id", id);
                _adapter = new SqlDataAdapter(cmd);
                _ds      = new DataSet();
                _adapter.Fill(_ds);
                if (_ds.Tables.Count > 0 && _ds.Tables[0].Rows.Count > 0)
                {
                    model.Id         = Convert.ToInt32(_ds.Tables[0].Rows[0]["Id"]);
                    model.Title      = Convert.ToString(_ds.Tables[0].Rows[0]["Title"]);
                    model.AgeBracket = Convert.ToString(_ds.Tables[0].Rows[0]["Age_bracket"]);
                    model.Duration   = Convert.ToInt32(_ds.Tables[0].Rows[0]["Duration"]);
                    model.FirstDay   = Convert.ToDateTime(_ds.Tables[0].Rows[0]["First_day_of_rental"]);
                    model.LastDay    = Convert.ToDateTime(_ds.Tables[0].Rows[0]["Last_day_of_rental"]);
                    model.Genres     = _genreServices.ListGenreByMovieId(model.Id);
                }
            }
            return(model);
        }
Example #2
0
        public IList <MovieModel> GetMovieList()
        {
            _genreServices = new GenreServices();
            IList <MovieModel> movieList = new List <MovieModel>();

            _ds = new DataSet();

            using (SqlConnection con = new SqlConnection(connect))
            {
                con.Open();
                SqlCommand cmd = new SqlCommand("GetAllMovies", con);
                cmd.CommandType = CommandType.StoredProcedure;
                _adapter        = new SqlDataAdapter(cmd);
                _adapter.Fill(_ds);
                if (_ds.Tables.Count > 0)
                {
                    for (int i = 0; i < _ds.Tables[0].Rows.Count; i++)
                    {
                        MovieModel obj = new MovieModel();
                        obj.Id         = Convert.ToInt32(_ds.Tables[0].Rows[i]["Id"]);
                        obj.Title      = Convert.ToString(_ds.Tables[0].Rows[i]["Title"]);
                        obj.AgeBracket = Convert.ToString(_ds.Tables[0].Rows[i]["Age_bracket"]);
                        obj.Duration   = Convert.ToInt32(_ds.Tables[0].Rows[i]["Duration"]);
                        obj.FirstDay   = Convert.ToDateTime(_ds.Tables[0].Rows[i]["First_day_of_rental"]);
                        obj.LastDay    = Convert.ToDateTime(_ds.Tables[0].Rows[i]["Last_day_of_rental"]);
                        obj.Genres     = _genreServices.ListGenreByMovieId(obj.Id);
                        movieList.Add(obj);
                    }
                }
            }

            return(movieList);
        }