public ActionResult CheckIn(DVDInfo id)
        {
            var manager = new DVDManager();

            var response = manager.ReturnDVD(id);

            return View("CheckIn", response.Data);
        }
        public ActionResult CheckOut(DVDInfo id)
        {
            var manager = new DVDManager();

            var response = manager.AddBorrower(id);

            var dvd = manager.GetDVDInfo(id.dvdID);

            return View("CheckOut", response.Data);
        }
        public ActionResult CreateDVD(DVDInfo dvd)
        {
            if (ModelState.IsValid)
            {
                var manager = new DVDManager();
                var response = manager.CreateDVD(dvd);

                return View("CreateDVD", response.Data);
            }
            return View("Create");
        }
        public void AddBorrower(DVDInfo borrowerInfo)
        {
            using (SqlConnection cn = new SqlConnection(ConfigurationManager.ConnectionStrings["DVDLibrary"].ConnectionString))
            {
                SqlCommand cmd = new SqlCommand();
                cmd.CommandText = "AddBorrower";
                cmd.CommandType = CommandType.StoredProcedure;

                cmd.Parameters.AddWithValue("@dvdID", borrowerInfo.dvdID);
                cmd.Parameters.AddWithValue("@BorrowerName", borrowerInfo.BorrowerInfo.Borrower);
                cmd.Parameters.AddWithValue("@DateBorrowed", borrowerInfo.BorrowerInfo.DateBorrowed);
                cmd.Connection = cn;

                cn.Open();
                cmd.ExecuteNonQuery();
            }
        }
        public void CreateDVD(DVDInfo DVD)
        {
            using (SqlConnection cn = new SqlConnection(ConfigurationManager.ConnectionStrings["DVDLibrary"].ConnectionString))
            {
                SqlCommand cmd = new SqlCommand();
                cmd.CommandText = "CreateDVD";
                cmd.CommandType = CommandType.StoredProcedure;

                cmd.Connection = cn;

                cmd.Parameters.AddWithValue("@Title", DVD.Title);
                cmd.Parameters.AddWithValue("@ReleaseDate", DVD.ReleaseDate);
                cmd.Parameters.AddWithValue("@MPAARating", DVD.MPAARating);
                cmd.Parameters.AddWithValue("@DirectorsName", DVD.DirectorsName);
                cmd.Parameters.AddWithValue("@Studio", DVD.Studio);
                cmd.Parameters.AddWithValue("@UserRating", DVD.UserRating);
                cmd.Parameters.AddWithValue("@UserNotes", DVD.UserNotes);
                cmd.Parameters.AddWithValue("@ActorsInMovie", DVD.ActorsInMovies);

                cn.Open();
                cmd.ExecuteNonQuery();
            }
        }
        public DVDInfo LoadDVD(int dvdID)
        {
            List<DVDInfo> dvds = GetAllDVDs();
            using (SqlConnection cn = new SqlConnection(ConfigurationManager.ConnectionStrings["DVDLibrary"].ConnectionString))
            {
                SqlCommand cmd = new SqlCommand();
                cmd.CommandText = "LatestBorrower";
                cmd.CommandType = CommandType.StoredProcedure;

                cmd.Connection = cn;

                cmd.Parameters.AddWithValue("@dvdID", dvdID);

                cn.Open();
                DVDInfo dvd = new DVDInfo()
                {
                    BorrowerInfo = new BorrowerInformation()
                };
                using (SqlDataReader dr = cmd.ExecuteReader())
                {
                    while (dr.Read())
                    {
                         dvd = PopulateFromDataReaderBorrowerInfo(dr);
                    }

                }
                return dvd;
               }
        }
        private DVDInfo PopulateFromDataReaderBorrowerInfo(SqlDataReader dr)
        {
            DVDInfo dvd = new DVDInfo()
            {
                BorrowerInfo = new BorrowerInformation()
            };

            dvd.dvdID = (int)dr["dvdID"];
            dvd.Title = dr["Title"].ToString();
            dvd.ReleaseDate = dr["ReleaseDate"].ToString();
            dvd.MPAARating = dr["MPAARating"].ToString();
            dvd.DirectorsName = dr["DirectorsName"].ToString();
            dvd.Studio = dr["Studio"].ToString();
            dvd.UserRating = dr["UserRating"].ToString();
            dvd.ActorsInMovies = dr["ActorsInMovie"].ToString();

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

            if (dr["DateReturned"] == DBNull.Value)
            {
                dvd.BorrowerInfo.dvdID = dvd.dvdID;

                if (dr["BorrowerName"] != DBNull.Value)
                    dvd.BorrowerInfo.Borrower = dr["BorrowerName"].ToString();

                if (dr["DateBorrowed"] != DBNull.Value)
                    dvd.BorrowerInfo.DateBorrowed = (DateTime)dr["DateBorrowed"];
            }

            return dvd;
        }
        private DVDInfo PopulateFromDataReader(SqlDataReader dr)
        {
            DVDInfo dvd = new DVDInfo();

            dvd.dvdID = (int) dr["dvdID"];
            dvd.Title = dr["Title"].ToString();
            dvd.ReleaseDate = dr["ReleaseDate"].ToString();
            dvd.MPAARating = dr["MPAARating"].ToString();
            dvd.DirectorsName = dr["DirectorsName"].ToString();
            dvd.Studio = dr["Studio"].ToString();
            dvd.UserRating = dr["UserRating"].ToString();
            dvd.ActorsInMovies = dr["ActorsInMovie"].ToString();

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

            return dvd;
        }
 public ActionResult Create()
 {
     var models = new DVDInfo();
     return View(models);
 }