Example #1
0
 public User CreateNewUser(User user)
 {
     try
     {
         using (NameGameDBEntities entities = new NameGameDBEntities())
         {
             User usr = entities.Users.FirstOrDefault(u => u.UserName == user.UserName);
             if (usr == null)
             {
                 //create new user
                 User newUser = entities.Users.Add(user);
                 entities.SaveChanges();
                 //we don't need to send the password back
                 newUser.Password = "";
                 return(newUser);
             }
             else
             {
                 //return null indicating that a user was not created
                 return(null);
             }
         }
     }
     catch (Exception ex)
     {
         return(null);
     }
 }
Example #2
0
 public Game AddGameToDB(Game newGame)
 {
     using (NameGameDBEntities entities = new NameGameDBEntities())
     {
         entities.Games.Add(newGame);
         entities.SaveChanges();
         return(newGame);
     }
 }
Example #3
0
 public void UpdateGameData(Game game)
 {
     using (NameGameDBEntities entities = new NameGameDBEntities())
     {
         Game gm = entities.Games.FirstOrDefault(g => g.GameId == game.GameId);
         if (gm != null)
         {
             //only QAttempts and QCompleted should be changing - so comment out the others for now
             //gm.GameData = game.GameData;
             //gm.GameMode = game.GameMode;
             //gm.QAnswers = game.QAnswers;
             //gm.QCount = game.QCount;
             gm.QAttempts  = game.QAttempts;
             gm.QCompleted = game.QCompleted;
             entities.SaveChanges();
         }
     }
 }