예제 #1
0
        public ActionResult Index()
        {
            Repo repo = new Repo();
            //string result = "";
            var list = repo.GetList();
            DVD dvd_listDetails = list.FirstOrDefault();

            //result += dvd_listDetails.Title + Environment.NewLine;
            //result += dvd_listDetails.Available;
            //result += dvd_listDetails.AverageRating;

            //DVD dvd_detailed = repo.FillInDetails(dvd_listDetails.dvdID);

            //result += dvd_detailed.MPAA;
            //result += dvd_detailed.Studio;

            //foreach (var Z in dvd_detailed.CastMembers)
            //{
            //    result += Z.CastRoleName + ": " + Z.CastFirstName + " " + Z.CastLastName + Environment.NewLine;
            //}

            //foreach (var rE in dvd_detailed.History)
            //{
            //    result += "***Records*** " + rE.Username
            //              + " " + rE.BorrowedDate
            //              + " " + rE.ReturnedDate
            //              + " " + rE.DVDNote
            //              + " " + rE.DVDRating;
            //}

            return View(list);
        }
예제 #2
0
        public ActionResult Delete(int id)
        {
            var repo = new Repo();
            DVD dvd = repo.FillInDetails(id);

            return View(dvd);
        }
예제 #3
0
        public ActionResult BorrowIt(int id)
        {
            var repo = new Repo();
            repo.DVD_Borrow(_adminUserId,id);

            return RedirectToAction("Index","Home");
        }
예제 #4
0
        public ActionResult Search(string ipValue)
        {
            var repo = new Repo();

            List<DVD> results = repo.SearchForDVDTitle(ipValue);

            return View(results);
        }
예제 #5
0
        public ActionResult DeleteIt(int id)
        {
            var repo = new Repo();

            repo.DeleteDVD(id);

            return RedirectToAction("Index", "Home");
        }
예제 #6
0
 public ActionResult Add(DVD dvd)
 {
     if (ModelState.IsValid)
     {
         var repo  = new Repo();
         repo.AddDVD(dvd);
         return RedirectToAction("Index", "Home");
     }
     else
     {
         return View(dvd);
     }
 }
예제 #7
0
파일: DALTests.cs 프로젝트: Turrino/DVDLib
        public void AddDVD_AddSucceeds_Test(string test_title)
        {
            DVD expected = new DVD()
            {
                Title = test_title,
                CastMembers = new List<Cast>()
                {
                    new Cast() {CastFirstName = "Dolan", CastLastName = "Dcuk", CastRoleName = "actor" },
                    new Cast() {CastFirstName = "Uncel", CastLastName = "Scroge", CastRoleName = "actor" },
                    new Cast() {CastFirstName = "Blue", CastLastName = "Meanie", CastRoleName = "actor" }
                },
                ReleaseDate = new DateTime(2001, 1, 1),
                MPAA = "PG",
                Studio = "Balooney Pictures",
            };

            Settings set = new Settings(connectionString);
            Repo repo = new Repo();

            int newID = repo.AddDVD(expected);

            string title = "";

            using (SqlConnection cn = new SqlConnection(connectionString))
            {
                SqlCommand cmd = new SqlCommand();
                cmd.CommandText = $"SELECT TOP 1 * FROM DVDs WHERE Title = '{test_title}' AND dvdID = {newID}";
                cmd.Connection = cn;

                cn.Open();

                using (SqlDataReader dr = cmd.ExecuteReader())
                {
                    while (dr.Read())
                    {
                        title = dr["Title"].ToString();
                    }
                }

                Assert.AreEqual(expected.Title, title);

                DynamicParameters p = new DynamicParameters();
                p.Add("dvdID", newID);

                cn.Query("EraseDVDRecord", p, commandType: CommandType.StoredProcedure);
            }
        }
예제 #8
0
파일: DALTests.cs 프로젝트: Turrino/DVDLib
        public void AddRating_NotBoundToBorrowHistory(int userID, int rating, string note)
        {
            DVD toRate = new DVD()
            {
                Title = "RateThis",
                CastMembers = new List<Cast>()
            };

            Settings set = new Settings(connectionString);
            Repo repo = new Repo();

            int newID = repo.AddDVD(toRate);

            repo.AddRating(newID, userID, rating, note);

            DVD result = repo.FillInDetails(newID);

            Assert.AreEqual(rating, result.History[0].DVDRating);
            Assert.AreEqual(note, result.History[0].DVDNote);

            using (SqlConnection cn = new SqlConnection(connectionString))
            {
                DynamicParameters p = new DynamicParameters();
                p.Add("dvdID", newID);

                cn.Query("EraseDVDRecord", p, commandType: CommandType.StoredProcedure);
            }
        }
예제 #9
0
파일: DALTests.cs 프로젝트: Turrino/DVDLib
        public void SearchByTitle_FullMatch(string fakeTitle)
        {
            DVD searchMe = new DVD()
            {
                Title = fakeTitle,
                CastMembers = new List<Cast>(),
            };

            Settings set = new Settings(connectionString);
            Repo repo = new Repo();

            int newID = repo.AddDVD(searchMe);
            int wantedID = 0;

            using (SqlConnection cn = new SqlConnection(connectionString))
            {
                SqlCommand cmd = new SqlCommand();
                cmd.CommandText = $"SELECT TOP 1 * FROM DVDs WHERE Title = '{fakeTitle}' AND dvdID = {newID}";
                cmd.Connection = cn;

                cn.Open();

                using (SqlDataReader dr = cmd.ExecuteReader())
                {
                    while (dr.Read())
                    {
                        wantedID = (int)dr["dvdID"];
                    }
                }

                List<DVD> results = repo.SearchForDVDTitle(fakeTitle);

                Assert.AreEqual(wantedID, results.FirstOrDefault().dvdID);

                DynamicParameters p = new DynamicParameters();
                p.Add("dvdID", newID);

                cn.Query("EraseDVDRecord", p, commandType: CommandType.StoredProcedure);
            }
        }
예제 #10
0
파일: DALTests.cs 프로젝트: Turrino/DVDLib
        public void GetList_IDMatch_Test()
        {
            Settings set = new Settings(connectionString);
            Repo repo = new Repo();
            List<DVD> dvds = repo.GetList();
            List<int> expectedIDs = new List<int>();

            using (SqlConnection cn = new SqlConnection(connectionString))
            {
                SqlCommand cmd = new SqlCommand();
                cmd.CommandText = "SELECT * FROM DVDs WHERE Deleted IS NULL OR Deleted <> 1";
                cmd.Connection = cn;

                cn.Open();

                using (SqlDataReader dr = cmd.ExecuteReader())
                {
                    while (dr.Read())
                    {
                        expectedIDs.Add((int)dr["dvdID"]);
                    }
                }
            }

            List<int> results = dvds.Select(d => d.dvdID).ToList();
            results.Sort();
            expectedIDs.Sort();

            Assert.AreEqual(expectedIDs, results);
        }
예제 #11
0
파일: DALTests.cs 프로젝트: Turrino/DVDLib
        public void FillInDetails_DetailMatch_Top1_Test()
        {
            Settings set = new Settings(connectionString);
            Repo repo = new Repo();
            DVD expectedDetails = new DVD();

            using (SqlConnection cn = new SqlConnection(connectionString))
            {
                SqlCommand cmd = new SqlCommand();
                cmd.CommandText = "SELECT TOP 1 d.*, ar.AverageRating FROM DVDs d FULL JOIN(SELECT AVG(r.DVDRating) AS AverageRating, r.dvdID FROM Ratings r GROUP BY r.dvdID) AS ar on ar.dvdID = d.dvdID WHERE Deleted IS NULL OR Deleted <> 1";
                cmd.Connection = cn;

                cn.Open();

                using (SqlDataReader dr = cmd.ExecuteReader())
                {
                    while (dr.Read())
                    {
                        expectedDetails.dvdID = (int)dr["dvdID"];
                        expectedDetails.Title = dr["Title"].ToString();
                        expectedDetails.ReleaseDate = DateTime.Parse(dr["ReleaseDate"].ToString());
                        expectedDetails.MPAA = dr["MPAA"].ToString();
                        expectedDetails.Studio = dr["Studio"].ToString();
                        expectedDetails.AverageRating = (int)dr["AverageRating"];

                    }
                }
            }

            DVD dvd_detailed = repo.FillInDetails(1);

            Assert.AreEqual(expectedDetails.dvdID, dvd_detailed.dvdID);
            Assert.AreEqual(expectedDetails.AverageRating, dvd_detailed.AverageRating);
            Assert.AreEqual(expectedDetails.MPAA, dvd_detailed.MPAA);
            Assert.AreEqual(expectedDetails.ReleaseDate, dvd_detailed.ReleaseDate);
            Assert.AreEqual(expectedDetails.Studio, dvd_detailed.Studio);
        }
예제 #12
0
파일: DALTests.cs 프로젝트: Turrino/DVDLib
        public void DeleteDVD_Top1_DeletedDVD_DoesNotShowUpInList(int ID_to_mark)
        {
            Settings set = new Settings(connectionString);
            Repo repo = new Repo();

            List<int> expectedIDs = new List<int>();

            repo.DeleteDVD(ID_to_mark);

            using (SqlConnection cn = new SqlConnection(connectionString))
            {
                SqlCommand cmd = new SqlCommand();
                cmd.CommandText = "SELECT * FROM DVDs WHERE Deleted IS NULL OR Deleted <> 1";
                cmd.Connection = cn;

                cn.Open();

                using (SqlDataReader dr = cmd.ExecuteReader())
                {
                    while (dr.Read())
                    {
                        expectedIDs.Add((int)dr["dvdID"]);
                    }
                }
            }

            Assert.IsTrue(!expectedIDs.Contains(ID_to_mark));

            repo.RestoreDVD(ID_to_mark);
        }
예제 #13
0
파일: DALTests.cs 프로젝트: Turrino/DVDLib
        public void Borrow_And_Return_DVDs(bool borrow)
        {
            DVD toBorrow = new DVD()
            {
                Title = "BorrowThis",
                CastMembers = new List<Cast>()
            };

            Settings set = new Settings(connectionString);
            Repo repo = new Repo();

            int newID = repo.AddDVD(toBorrow);

            repo.DVD_BorrowReturn(1, newID, true);

            List<DVD> dvds = repo.GetList();

            Assert.IsTrue(!dvds.FirstOrDefault(d => d.Title == "BorrowThis" && d.dvdID == newID).Available);

            if (!borrow)
            {
                repo.DVD_BorrowReturn(1, newID, false);
                dvds = repo.GetList();
                Assert.IsTrue(dvds.FirstOrDefault(d => d.Title == "BorrowThis" && d.dvdID == newID).Available);
            }

            using (SqlConnection cn = new SqlConnection(connectionString))
            {
                DynamicParameters p = new DynamicParameters();
                p.Add("dvdID", newID);

                cn.Query("EraseDVDRecord", p, commandType: CommandType.StoredProcedure);
            }
        }