コード例 #1
0
ファイル: DvdEFRepo.cs プロジェクト: ColeJSmith19/guildWork
        public void Delete(int dvdID)
        {
            var repository = new DvdLibraryEntities();
            var dvd        = repository.Dvds.Find(dvdID);

            if (dvd != null)
            {
                Dvd delete = new Dvd
                {
                    DvdID       = dvd.DvdID,
                    Title       = dvd.DvdTitle,
                    ReleaseYear = dvd.Release.ReleaseYear,
                    Director    = dvd.Director.DirectorName,
                    Rating      = dvd.Rating.RatingName,
                    Notes       = dvd.Notes
                };

                repository.Dvds.Remove(dvd);
                repository.SaveChanges();
            }
        }
コード例 #2
0
ファイル: DvdEFRepo.cs プロジェクト: ColeJSmith19/guildWork
        public Dvd GetByID(int dvdID)
        {
            var repository = new DvdLibraryEntities();
            var dvdToGet   = repository.Dvds.Find(dvdID);
            Dvd returnDvd  = new Dvd();

            if (dvdToGet != null)
            {
                returnDvd.DvdID       = dvdToGet.DvdID;
                returnDvd.Title       = dvdToGet.DvdTitle;
                returnDvd.ReleaseYear = dvdToGet.Release.ReleaseYear;
                returnDvd.Director    = dvdToGet.Director.DirectorName;
                returnDvd.Rating      = dvdToGet.Rating.RatingName;
                returnDvd.Notes       = dvdToGet.Notes;
                return(returnDvd);
            }
            else
            {
                return(null);
            }
        }
コード例 #3
0
ファイル: DvdADORepo.cs プロジェクト: ColeJSmith19/guildWork
        public List <Dvd> GetByYear(int dvdYear)
        {
            List <Dvd> dvds = new List <Dvd>();

            using (SqlConnection conn = new SqlConnection())
            {
                conn.ConnectionString = ConfigurationManager.ConnectionStrings["DvdDatabase"].ConnectionString;
                SqlCommand cmd = new SqlCommand();
                cmd.Connection  = conn;
                cmd.CommandType = System.Data.CommandType.StoredProcedure;

                cmd.CommandText = "GetDvdByReleaseYear";
                cmd.Parameters.AddWithValue("@DvdReleaseYear", dvdYear);

                conn.Open();
                using (SqlDataReader dr = cmd.ExecuteReader())
                {
                    while (dr.Read())
                    {
                        Dvd currentRow = new Dvd();

                        currentRow.DvdID       = (int)dr["DvdID"];
                        currentRow.Title       = dr["DvdTitle"].ToString();
                        currentRow.ReleaseYear = (short)dr["ReleaseYear"];
                        currentRow.Director    = dr["DirectorName"].ToString();
                        currentRow.Rating      = dr["RatingName"].ToString();

                        if (dr["Notes"] != DBNull.Value)
                        {
                            currentRow.Notes = dr["Notes"].ToString();
                        }

                        dvds.Add(currentRow);
                    }
                }
            }
            return(dvds);
        }
コード例 #4
0
 public void Edit(Dvd dvd)
 {
     var found = _dvds.FirstOrDefault(d => d.DvdID == dvd.DvdID);
 }
コード例 #5
0
 public void Add(Dvd dvd)
 {
     dvd.DvdID = _dvds.Max(d => d.DvdID) + 1;
     _dvds.Add(dvd);
 }