コード例 #1
0
 /// <summary>
 /// The method changes the currents userrs team id and transfers the points
 /// </summary>
 /// <example>
 /// <code>
 /// CurrentUser.ChangeTeam(int newTeamID)
 /// </code>
 /// </example>
 public static void ChangeTeam(int newTeamID)
 {
     using (var dbcontext = new TeamContext())
     {
         var oldTeam = dbcontext.Teams.Find(teamId);
         var oldTeamUpdatedpoints = oldTeam;
         if (oldTeam.TeamId != 1)
         {
             oldTeamUpdatedpoints.TeamPointAmount -= poitAmount;
         }
         dbcontext.Entry(oldTeam).CurrentValues.SetValues(oldTeamUpdatedpoints);
         var newTeam   = dbcontext.Teams.Find(newTeamID);
         var newTeamUp = newTeam;
         newTeamUp.TeamPointAmount += poitAmount;
         dbcontext.Entry(newTeam).CurrentValues.SetValues(newTeamUp);
         dbcontext.SaveChanges();
     }
     UpdateUserTeamInDB(newTeamID);
 }
コード例 #2
0
        /// <summary>
        /// The method updates the user in the database
        /// </summary>
        /// <example>
        /// <code>
        /// UpdateUserInDB();
        /// </code>
        /// </example>
        private static void UpdateUserInDB()
        {
            int pointDiff;

            using (var dbcontext = new UserContext())
            {
                var usr    = dbcontext.Users.Find(id);
                var usrNew = usr;
                pointDiff          = poitAmount - int.Parse(usrNew.PointAmount.ToString());
                usrNew.PointAmount = poitAmount;
                dbcontext.Entry(usr).CurrentValues.SetValues(usrNew);
                dbcontext.SaveChanges();
            }
            using (var dbcontext = new TeamContext())
            {
                var team    = dbcontext.Teams.Find(teamId);
                var newTeam = team;
                newTeam.TeamPointAmount = team.TeamPointAmount + pointDiff;
                dbcontext.Entry(team).CurrentValues.SetValues(newTeam);
                dbcontext.SaveChanges();
            }
        }