Beispiel #1
0
        public DVDLibrary.Models.Dvd GetById(int dvdId)
        {
            var repository = new DvdLibraryEntities();
            var dvd        = repository.Dvds.FirstOrDefault(m => m.DvdId == dvdId);

            DVDLibrary.Models.Dvd dvdx = new DVDLibrary.Models.Dvd();
            dvdx.DvdId       = dvd.DvdId;
            dvdx.Title       = dvd.Title;
            dvdx.ReleaseYear = dvd.ReleaseYear;
            dvdx.Director    = dvd.Director;
            dvdx.Rating      = dvd.Rating.RatingName;               //fix this
            dvdx.Notes       = dvd.Notes;
            return(dvdx);
        }
Beispiel #2
0
        public void Update(DVDLibrary.Models.Dvd dvd)
        {
            var repository = new DvdLibraryEntities();

            Dvd model = new Dvd();

            model.DvdId       = dvd.DvdId;
            model.Title       = dvd.Title;
            model.ReleaseYear = dvd.ReleaseYear;
            model.Director    = dvd.Director;
            model.RatingId    = (from r in repository.Ratings where r.RatingName == dvd.Rating select r.RatingId).FirstOrDefault();                    //fix this
            model.Notes       = dvd.Notes;

            repository.Entry(model).State = EntityState.Modified;
            repository.SaveChanges();
        }
Beispiel #3
0
        public void Insert(DVDLibrary.Models.Dvd dvd)
        {
            var repository = new DvdLibraryEntities();

            Dvd dvdx = new Dvd();

            dvdx.Title       = dvd.Title;
            dvdx.RatingId    = (from r in repository.Ratings where r.RatingName == dvd.Rating select r.RatingId).FirstOrDefault();                    //fix this
            dvdx.ReleaseYear = dvd.ReleaseYear;
            dvdx.Director    = dvd.Director;
            dvdx.Notes       = dvd.Notes;

            repository.Dvds.Add(dvdx);
            repository.SaveChanges();
            dvdx.RatingId = dvd.DvdId;
        }