/// <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); }
/// <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; } }
/// <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; } }
/// <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)); }
/// <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); }
/// <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; } }