コード例 #1
0
        /// <summary>
        /// Adds a Badge to the display so it can be seen by the user.
        /// </summary>
        /// 
        /// <param name="badge">The Badge to add to the display.</param>
        public void AddBadgeToDisplay(Badge badge)
        {
            DisplayBadgeControl displayBadgeControl = (DisplayBadgeControl)LoadControl("DisplayBadgeControl.ascx");
            displayBadgeControl.LoadBadgeIntoDisplay(badge);

            _displayBadgeControls.Controls.Add(displayBadgeControl);
        }
コード例 #2
0
        /// <summary>
        /// Loads a Badge's information into the display so it can be seen by the user.
        /// </summary>
        /// 
        /// <param name="badge">The Badge to load into the display.</param>
        public void LoadBadgeIntoDisplay(Badge badge)
        {
            _badgeName.Text = badge.Name;
            _badgeImage.ImageUrl = badge.ImagePath;
            _activityPointsValue.Text = badge.GetNextLevelReward().ToString();
            _badgeProgressNumerical.Text = BadgeManager.GetFormattedProgress(badge.ID);
            _badgeProgressBar.Value = badge.Progress;

            if (badge.IsComplete())
            {
                _activityPointsValue.Visible = false;
                _activityScoreImage.Visible = false;
            }
        }
コード例 #3
0
ファイル: BadgeDAO.cs プロジェクト: mlcamilli/ActivEarth
 /// <summary>
 /// Saves a badge as a new entry in the DB.
 /// </summary>
 /// <param name="badge">Badge object to add to the DB.</param>
 /// <returns>ID of the created badge on success, 0 on failure.</returns>
 public static int CreateNewBadge(Badge badge)
 {
     try
     {
         using (SqlConnection connection = ConnectionManager.GetConnection())
         {
             var data = new ActivEarthDataProvidersDataContext(connection);
             var badgeData = new BadgeDataProvider
             {
                 user_id = badge.UserID,
                 badge_level = (byte)badge.Level,
                 progress = (byte)badge.Progress,
                 statistic = (byte)badge.StatisticBinding
             };
             data.BadgeDataProviders.InsertOnSubmit(badgeData);
             data.SubmitChanges();
             return badgeData.id;
         }
     }
     catch (Exception)
     {
         return 0;
     }
 }
コード例 #4
0
ファイル: BadgeManager.cs プロジェクト: mlcamilli/ActivEarth
 /// <summary>
 /// Creates a new Badge and adds it to the collection.
 /// </summary>
 /// <param name="user">User to whom the Badge belongs.</param>
 /// <param name="statistic">Statistic being tracked by the badge.</param>
 /// <returns>Database ID for the created badge.</returns>
 public static Badge CreateBadge(int userId, Statistic statistic)
 {
     Badge newBadge = new Badge(userId, statistic);
     return BadgeDAO.GetBadgeFromBadgeId(BadgeDAO.CreateNewBadge(newBadge));
 }
コード例 #5
0
ファイル: BadgeDAO.cs プロジェクト: mlcamilli/ActivEarth
 /// <summary>
 /// Loads the information stored in external tables for the badge (LevelRequirements, LevelRewards, etc.)
 /// </summary>
 /// <param name="badge">The badge to finish loading.</param>
 private static void LoadExternalBadgeData(Badge badge)
 {
     badge.LevelRequirements = BadgeLevelInfoDAO.GetBadgeRequirementArray(badge.StatisticBinding);
     badge.LevelRewards = BadgeLevelInfoDAO.GetBadgeRewardArray(badge.StatisticBinding);
     badge.ImagePath = BadgeLevelInfoDAO.GetBadgeImagePath(badge.StatisticBinding, badge.Level);
     badge.FormatString = StatisticInfoDAO.GetStatisticFormatString(badge.StatisticBinding);
     badge.Name = StatisticInfoDAO.GetStatisticName(badge.StatisticBinding);
 }
コード例 #6
0
ファイル: BadgeDAO.cs プロジェクト: mlcamilli/ActivEarth
        /// <summary>
        /// Updates an existing Badge in the DB.
        /// </summary>
        /// <param name="badge">Badge whose record needs updating.</param>
        /// <returns>True on success, false on failure.</returns>
        public static bool UpdateBadge(Badge badge)
        {
            try
            {
                using (SqlConnection connection = ConnectionManager.GetConnection())
                {
                    var data = new ActivEarthDataProvidersDataContext(connection);
                    BadgeDataProvider dbBadge =
                        (from c in data.BadgeDataProviders where c.id == badge.ID select c).FirstOrDefault();
                    if (dbBadge != null)
                    {
                        dbBadge.user_id = badge.UserID;
                        dbBadge.badge_level = (byte)badge.Level;
                        dbBadge.progress = (byte)badge.Progress;
                        dbBadge.statistic = (byte)badge.StatisticBinding;

                        data.SubmitChanges();
                        return true;
                    }
                    else
                    {
                        return false;
                    }
                }
            }
            catch (Exception)
            {
                return false;
            }
        }