private void PopulateUserScoreBox(int userId)
        {
            List <Category> allCategories = Category.GetAllCategories();

            int    currentScore = 0;
            string resultData;

            foreach (Category cat in allCategories)
            {
                UserScore currentResultByCategory = UserScore.GetUserScoreData(this.currentUser, cat);

                if (currentResultByCategory == null ||
                    currentResultByCategory.Score == 0 ||
                    currentResultByCategory.Score == null)
                {
                    currentScore = 0;
                }
                else
                {
                    currentScore = (int)currentResultByCategory.Score;
                }

                resultData = cat.CategoryName + " - " + currentScore;

                PointOnCategory.Items.Add(new ListBoxItem {
                    Name    = "Id" + cat.Id,
                    Content = resultData
                });
            }
        }
        public static void UpdateUserScore(GameUser user, Topic topic, ushort points)
        {
            List <UserScore> allUserScores     = App.DbManager.UserScore.Where(u => u.UserId == user.Id).ToList();
            List <Category>  categoriesForUser = allUserScores.Select(c => c.Category).ToList();

            bool isUpdate = false;

            foreach (Category cat in categoriesForUser)
            {
                if (cat.Id == topic.CategoryId)
                {
                    UserScore userScore = allUserScores.First(c => c.CategoryId == topic.CategoryId);
                    userScore.Score += points;
                    isUpdate         = true;
                }
            }

            // First result for that user and that category
            if (!isUpdate)
            {
                UserScore userResult = new UserScore(user, topic, points);
                App.DbManager.UserScore.Add(userResult);
            }

            App.DbManager.SaveChanges();
        }
 public void SavePointsFromTopic(ushort points)
 {
     UserScore.UpdateUserScore(this.currentUser, this.currentTopic, points);
 }