コード例 #1
0
 public List <Rating> GetRatingList()
 {
     using (var ctx = new DvdContext())
     {
         return(ctx.Rating.ToList());
     }
 }
コード例 #2
0
 public List <Director> GetDirectorList()
 {
     using (var ctx = new DvdContext())
     {
         return(ctx.Director.ToList());
     }
 }
コード例 #3
0
 public List <Dvd> GetDvdList()
 {
     using (var ctx = new DvdContext())
     {
         List <Dvd> dvdList = ctx.Dvd.Include("Director").Include("Rating").ToList();
         return(dvdList);
     }
 }
コード例 #4
0
 public bool DeleteDvd(int dvdId)
 {
     try
     {
         Dvd dvd = GetDvd(dvdId);
         using (var ctx = new DvdContext())
         {
             ctx.Entry(dvd).State = System.Data.Entity.EntityState.Deleted;
             ctx.SaveChanges();
         }
         return(true);
     }
     catch (Exception e)
     {
         return(false);
     }
 }
コード例 #5
0
 public bool UpdateDvd(Dvd dvd)
 {
     try
     {
         using (var ctx = new DvdContext())
         {
             //dvd.Director = DirectorRepositoryEF.GetDirectorbyId(dvd.DirectorId);
             //dvd.Rating = RateRepositoryEF.GetRatebyId(dvd.RatingId);
             ctx.Entry(dvd).State = System.Data.Entity.EntityState.Modified;
             ctx.SaveChanges();
             dvd.Director = DirectorFactory.Create().GetDirectorbyId(dvd.DirectorId);
             dvd.Rating   = RatingFactory.Create().GetRatingbyId(dvd.RatingId);
             return(true);
         }
     }
     catch (Exception e)
     {
         return(false);
     }
 }
コード例 #6
0
 public int InsertDvd(Dvd dvd)
 {
     try
     {
         using (var ctx = new DvdContext())
         {
             //dvd.Director = DirectorRepositoryEF.GetDirectorbyId(dvd.DirectorId);
             //dvd.Rating = RateRepositoryEF.GetRatebyId(dvd.RatingId);
             ctx.Dvd.Add(dvd);
             ctx.SaveChanges();
             //dvd.Director = DirectorRepositoryEF.GetDirectorbyId(dvd.DirectorId);
             //dvd.Rating = RateRepositoryEF.GetRatebyId(dvd.RatingId);
             dvd.Director = DirectorFactory.Create().GetDirectorbyId(dvd.DirectorId);
             dvd.Rating   = RatingFactory.Create().GetRatingbyId(dvd.RatingId);
             return(ctx.Dvd.Max(d => d.DvdId));
         }
     }
     catch (Exception e)
     {
         return(-1);
     }
 }