示例#1
0
 public bool Insert(OnLineGame entity)
 {
     try
     {
         if (!Validate(entity))
         {
             return(false);
         }
         var newGame = new OnLineGame()
         {
             GameTitle       = entity.GameTitle.Trim(),
             GameDescription = entity.GameDescription,
             GameRating      = entity.GameRating,
             UserId          = entity.UserId
         };
         _context.OnLineGames.Add(newGame);
         _context.SaveChanges();
         return(true);
     }
     catch (Exception ex)
     {
         //Log4net.Add(ex.InnerException,"Insert");
         return(false);
     }
 }
示例#2
0
 public bool Update(OnLineGame entity)
 {
     if (!Validate(entity))
     {
         return(false);
     }
     try
     {
         using (var db = new GameRaterEntities())
         {
             db.OnLineGames.Attach(entity);
             var ModifiedGame = db.Entry(entity);
             ModifiedGame.Property(e => e.GameTitle).IsModified       = true;
             ModifiedGame.Property(e => e.GameDescription).IsModified = true;
             ModifiedGame.Property(e => e.GameRating).IsModified      = true;
             db.SaveChanges();
             return(true);
         }
     }
     catch (Exception ex)
     {
         //Log4net.Add(ex.InnerException,"Update");
         return(false);
     }
 }