Example #1
0
 public Response()
 {
     Movie = new MovieInfo();
     Movies = new List<MovieInfo>();
     Actors = new List<Actor>();
     Rental = new RentalInfo();
     Rentals = new List<RentalInfo>();
 }
Example #2
0
        private RentalInfo PopulateBorrowerFromDataReader(SqlDataReader dr)
        {
            // to save info to the right fields and populate class with borrower

            RentalInfo borrower = new RentalInfo();
            borrower.Borrower.BorrowerID = (int)dr["BorrowerID"];
            borrower.Borrower.FirstName = dr["FirstName"].ToString();
            borrower.Borrower.LastName = dr["LastName"].ToString();

            return borrower;
        }
Example #3
0
        private RentalInfo PopulateRentalInfoFromDataReader(SqlDataReader dr)
        {
            var rental = new RentalInfo();

            rental.Borrower.BorrowerID = (int)dr["BorrowerID"];
            rental.Borrower.FirstName = dr["bFirstName"].ToString();
            rental.Borrower.LastName = dr["bLastName"].ToString();
            rental.Movie = PopulateMovieInfoFromDataReader(dr);

            if (dr["UserNotes"] != DBNull.Value)
                rental.UserNotes = dr["UserNotes"].ToString();

            if (dr["UserRating"] != DBNull.Value)
                rental.UserRating = (int)dr["UserRating"];

            if (dr["DateBorrowed"] != DBNull.Value)
                rental.RentalDate = DateTime.Parse(dr["DateBorrowed"].ToString());

            if (dr["DateReturned"] != DBNull.Value)
                rental.ReturnDate = DateTime.Parse(dr["DateReturned"].ToString());

            return rental;
        }
Example #4
0
        //public List<RentalInfo> GetAllBorrowersInfo()
        //{
        //    using (SqlConnection cn = new SqlConnection(Settings.ConnectionString))
        //    {
        //        SqlCommand cmd = new SqlCommand();
        //        cmd.CommandText = "select mb.DateBorrowed, mb.DateReturned, mb.UserNotes, mb.UserRating, b.FirstName as bFirstName, b.LastName as bLastName, m.MovieTitle , b.borrowerID, " + "m.movieID, mp.filmrating , d.directorID, d.FirstName as dFirstName, d.LastName as dLastName, m.studioID, s.studioname, m.releasedate " +
        //                          "from MovieBorrower mb " +
        //                          "inner join Borrowers b " +
        //                          "on b.BorrowerID = mb.BorrowerID " +
        //                          "join Movies m " +
        //                          "on m.MovieID = mb.MovieID " +
        //                          "join mpaaratings mp " +
        //                          "on m.mpaaratingid = mp.mpaaratingid " +
        //                          "join Directors d " +
        //                          "on m.directorid = d.directorid " +
        //                          "join studios s " +
        //                          "on m.studioid = s.studioid";
        //        cmd.Connection = cn;
        //        cn.Open();
        //        using (SqlDataReader dr = cmd.ExecuteReader())
        //        {
        //            while (dr.Read())
        //            {
        //                Rentals.Add(PopulateRentalInfoFromDataReader(dr));
        //            }
        //        }
        //    }
        //    return Rentals;
        //}
        public RentalInfo GetBorrowerByID(int borrowerID)
        {
            // processes and returns borrower with  number to identify specific borrower

            RentalInfo borrower = new RentalInfo();

            using (var cn = new SqlConnection(Settings.ConnectionString))
            {
                var cmd = new SqlCommand();
                cmd.CommandText = "select * " +
                                  " from Borrowers b " +
                                  "where b.BorrowerID = @BorrowerID";

                cmd.Connection = cn;
                cmd.Parameters.AddWithValue("@BorrowerID", borrowerID);

                cn.Open();

                using (SqlDataReader dr = cmd.ExecuteReader())
                {
                    while (dr.Read())
                    {
                        borrower = PopulateBorrowerFromDataReader(dr);
                    }
                }
            }

            return borrower;
        }