Exemplo n.º 1
0
        public List <GetDvds> GetAllDvd()
        {
            List <GetDvds> dvds = new List <GetDvds>();

            using (var cn = new SqlConnection(Settings.GetConnectionString()))
            {
                SqlCommand cmd = new SqlCommand("GetAll", cn);
                cmd.CommandType = CommandType.StoredProcedure;

                cn.Open();

                using (SqlDataReader dr = cmd.ExecuteReader())
                {
                    while (dr.Read())
                    {
                        GetDvds row = new GetDvds();

                        row.DvdId       = (int)dr["DvdId"];
                        row.Title       = dr["Title"].ToString();
                        row.ReleaseYear = (int)dr["ReleaseYear"];
                        row.Director    = dr["DirectorName"].ToString();
                        row.Rating      = dr["RatingName"].ToString();
                        row.Notes       = dr["Notes"].ToString();

                        dvds.Add(row);
                    }
                }
            }
            return(dvds);
        }
Exemplo n.º 2
0
        public GetDvds GetById(int dvdId)
        {
            GetDvds dvd = new GetDvds();

            using (var cn = new SqlConnection(Settings.GetConnectionString()))
            {
                SqlCommand cmd = new SqlCommand("GetById", cn);
                cmd.CommandType = CommandType.StoredProcedure;

                cmd.Parameters.AddWithValue("@DvdId", dvdId);

                cn.Open();

                using (SqlDataReader dr = cmd.ExecuteReader())
                {
                    while (dr.Read())
                    {
                        GetDvds row = new GetDvds();

                        row.DvdId       = (int)dr["DvdId"];
                        row.Title       = dr["Title"].ToString();
                        row.ReleaseYear = (int)dr["ReleaseYear"];
                        row.Director    = dr["DirectorName"].ToString();
                        row.Rating      = dr["RatingName"].ToString();
                        row.Notes       = dr["Notes"].ToString();

                        return(row);
                    }
                }
                return(null);
            }
        }
Exemplo n.º 3
0
        public IHttpActionResult UpdateDvd(GetDvds dvd)
        {
            var repo = DvdRepositoryFactory.GetRepository();

            repo.Edit(dvd.DvdId, dvd.Title, dvd.ReleaseYear, dvd.Director, dvd.Rating, dvd.Notes);

            return(Ok());
        }
Exemplo n.º 4
0
        public IHttpActionResult NewDvd(GetDvds dvd)
        {
            var repo = DvdRepositoryFactory.GetRepository();

            repo.SaveNew(dvd.Title, dvd.ReleaseYear, dvd.Director, dvd.Rating, dvd.Notes);

            return(Ok());
        }
Exemplo n.º 5
0
        public GetDvds GetById(int dvdId)
        {
            GetDvds dvd        = new GetDvds();
            Dvd     getDvdInfo = _dvd.FirstOrDefault(x => x.DvdId == dvdId);

            dvd.DvdId       = dvdId;
            dvd.Title       = getDvdInfo.Title;
            dvd.ReleaseYear = getDvdInfo.ReleaseYear;
            dvd.Director    = getDvdInfo.Director.DirectorName;
            dvd.Rating      = getDvdInfo.Rating.RatingName;
            dvd.Notes       = getDvdInfo.Notes;

            return(dvd);
        }
Exemplo n.º 6
0
        public void EFCanEditDvd()
        {
            var    repo         = new DvdRepositoryEF();
            int    dvdId        = 2;
            string title        = "Edited dvd";
            int    releaseYear  = 1900;
            string directorName = "Edited director";
            string ratingName   = "R";
            string notes        = "This has been edited";

            repo.Edit(dvdId, title, releaseYear, directorName, ratingName, notes);
            GetDvds dvd = repo.GetById(2);

            Assert.AreEqual(2, dvd.DvdId);
            Assert.AreEqual(title, dvd.Title);
        }
Exemplo n.º 7
0
        public GetDvds GetById(int dvdId)
        {
            GetDvds dvd = new GetDvds();

            using (DvdCatalogEntities data = new DvdCatalogEntities())
            {
                var getDvd = (from r in data.Dvds.Include("Director").Include("Rating") where r.DvdId == dvdId select r);
                foreach (var x in getDvd)
                {
                    dvd.DvdId       = x.DvdId;
                    dvd.Title       = x.Title;
                    dvd.ReleaseYear = x.ReleaseYear;
                    dvd.Director    = x.Director.DirectorName;
                    dvd.Rating      = x.Rating.RatingName;
                    dvd.Notes       = x.Notes;
                }
            }
            return(dvd);
        }
Exemplo n.º 8
0
        public List <GetDvds> GetAllDvd()
        {
            List <GetDvds> dvds = new List <GetDvds>();

            for (int index = 0; index < _dvd.Count(); index++)
            {
                GetDvds dvdGet = new GetDvds();

                dvdGet.DvdId       = _dvd[index].DvdId;
                dvdGet.Title       = _dvd[index].Title;
                dvdGet.ReleaseYear = _dvd[index].ReleaseYear;
                dvdGet.Director    = _dvd[index].Director.DirectorName;
                dvdGet.Rating      = _dvd[index].Rating.RatingName;
                dvdGet.Notes       = _dvd[index].Notes;

                dvds.Add(dvdGet);
            }

            return(dvds);
        }
Exemplo n.º 9
0
        public List <GetDvds> GetByDirector(string directorName)
        {
            List <GetDvds> dvds = new List <GetDvds>();

            using (DvdCatalogEntities data = new DvdCatalogEntities())
            {
                var getByDirector = (from r in data.Dvds.Include("Director").Include("Rating") where r.Director.DirectorName == directorName select r);
                foreach (var x in getByDirector)
                {
                    GetDvds dvd = new GetDvds();
                    dvd.DvdId       = x.DvdId;
                    dvd.Title       = x.Title;
                    dvd.ReleaseYear = x.ReleaseYear;
                    dvd.Director    = x.Director.DirectorName;
                    dvd.Rating      = x.Rating.RatingName;
                    dvd.Notes       = x.Notes;
                    dvds.Add(dvd);
                }
            }
            return(dvds);
        }
Exemplo n.º 10
0
        public List <GetDvds> GetByRating(string rating)
        {
            List <GetDvds> dvds = new List <GetDvds>();

            foreach (var x in _dvd)
            {
                if (x.Rating.RatingName == rating)
                {
                    GetDvds dvd = new GetDvds();
                    dvd.DvdId       = x.DvdId;
                    dvd.Title       = x.Title;
                    dvd.ReleaseYear = x.ReleaseYear;
                    dvd.Director    = x.Director.DirectorName;
                    dvd.Rating      = x.Rating.RatingName;
                    dvd.Notes       = x.Notes;

                    dvds.Add(dvd);
                }
            }

            return(dvds);
        }