/// <summary>
        /// Gets all scores for each users which has played in given parameter as GroupName
        /// </summary>
        /// <param name="GroupName">Name of group which want to get user scores from</param>
        /// <returns>Scores containing information about user scores.</returns>
        public Scores GetAllScores(string GroupName)
        {
            Scores scores = new Scores();

            DataTable dt = TableMethods.GetTable(BaseMethod.DbPath, "UserValues",
                "GroupName", "=", new object[] { GroupName });

            if (dt != null && dt.Rows.Count > 0)
            {
                Dictionary<int, string> AllFields = new Dictionary<int, string>();
                FieldsManager fm = new FieldsManager();
                UserValuesManager userFieldsManager = new UserValuesManager();
                ValidItems validItems = new ValidItems();
                var allFields = fm.GetAllFields();
                foreach (var field in allFields)
                    AllFields.Add(field.ID, field.Title);
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    int FieldID = (int)dt.Rows[i]["FieldID"];
                    string UserNick = (string)dt.Rows[i]["UserNick"];
                    string FieldValue = (string)dt.Rows[i]["FieldValue"];
                    if (!AllFields.ContainsKey(FieldID))
                        continue;
                    string FieldTitle = AllFields[FieldID];

                    int score = 0;
                    bool isValidValue = validItems.IsValidValue(FieldID, FieldValue);
                    if (isValidValue)
                    {
                        if (userFieldsManager.IsValueDuplicate(FieldID, GroupName, FieldValue))
                            score = 5;
                        else score = 10;
                    }

                    UserScores us = scores.GetUserScores(UserNick);
                    ScoreItem si = new ScoreItem()
                    {
                        ID = FieldID,
                        Value = FieldValue,
                        Title = FieldTitle,
                        Score = score
                    };
                    us.AddNewScoreItem(si);
                }
            }
            return scores;
        }
Example #2
0
 public void StopGame()
 {
     UserValuesManager uvm = new UserValuesManager();
     Scores scores = uvm.GetAllScores(this.Name);
     SendToAll(MessageTypes.Stop, Serializer.GetSerializedClass<Scores>(scores));
 }