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(); } }
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); } }
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); }
public void Edit(Dvd dvd) { var found = _dvds.FirstOrDefault(d => d.DvdID == dvd.DvdID); }
public void Add(Dvd dvd) { dvd.DvdID = _dvds.Max(d => d.DvdID) + 1; _dvds.Add(dvd); }