Esempio n. 1
0
 public void SetUserStatistic(Statistic statToSet, float val)
 {
     if (_userStatisticMap.ContainsKey(statToSet))
     {
         _userStatisticMap[statToSet].Value = val;
         //UserStatisticDAO.UpdateUserStatistic(_userStatisticMap[statToSet]);
         StatisticManager.SetUserStatistic(_user.UserID, statToSet, val);
     }
     else
     {
         UserStatistic userStatistic = new UserStatistic(statToSet, val);
         int userStatisticId = UserStatisticDAO.CreateNewStatisticForUser(_user.UserID, statToSet, 0);
         userStatistic.UserStatisticID = userStatisticId;
         _userStatisticMap[statToSet] = userStatistic;
         StatisticManager.SetUserStatistic(_user.UserID, statToSet, val);
     }
 }
Esempio n. 2
0
 public void SetStatistic(Statistic statToSet, float val)
 {
     if (_stats.ContainsKey(statToSet))
     {
         _stats[statToSet].Value = val;
     }
     else
     {
         _stats[statToSet] = new UserStatistic(statToSet, val);
     }
 }
Esempio n. 3
0
        /// <summary>
        /// Gets a statistic for a user based on the statistic type.
        /// </summary>
        /// <param name="statToGet">Statistic to retrieve.</param>
        /// <returns>UserStatistic for type of Statistic</returns>
        public UserStatistic GetUserStatistic(Statistic statToGet)
        {
            UserStatistic stat = new UserStatistic(statToGet);

            if (_userStatisticMap.ContainsKey(statToGet))
            {
                stat = _userStatisticMap[statToGet];
            }
            else
            {
               stat = UserStatisticDAO.GetStatisticFromUserIdAndStatType(_user.UserID, statToGet);

               if (stat == null)
               {
                   stat = new UserStatistic(statToGet);
               }
            }

            return stat;
        }
Esempio n. 4
0
        /// <summary>
        /// Updates an existing UserStatistic in the DB.
        /// </summary>
        /// <param name="statistic">UserStatistic whose record needs updating.</param>
        /// <returns>True on success, false on failure.</returns>
        public static bool UpdateUserStatistic(UserStatistic statistic)
        {
            try
            {
                using (SqlConnection connection = ConnectionManager.GetConnection())
                {
                    var data = new ActivEarthDataProvidersDataContext(connection);
                    UserStatisticDataProvider dbStatistic =
                        (from p in data.UserStatisticDataProviders where p.id == statistic.UserStatisticID select p).FirstOrDefault();

                    if (dbStatistic != null)
                    {
                        dbStatistic.statistic_type = (byte)statistic.Statistic;
                        dbStatistic.user_id = statistic.UserID;
                        dbStatistic.value = statistic.Value;

                        data.SubmitChanges();
                    }
                    else
                    {
                        return false;
                    }
                }

                return true;
            }
            catch (Exception)
            {
                return false;
            }
        }