public void AddWarRecord(int mRecordId, WarRecord wRecord) { using (SqlConnection connection = new SqlConnection(builder.ConnectionString)) { StringBuilder sbWarRecord = new StringBuilder(); sbWarRecord.Append(string.Format("INSERT INTO WarRecord (ID, SeasonId, CreateDate, MonthRecord_Id) VALUES ({0}, {1}, '{2}', {3});", wRecord.Id, wRecord.SeasonId, wRecord.CreateDate, mRecordId)); String sql = sbWarRecord.ToString(); SqlCommand myCommand = new SqlCommand(sql, connection); try { connection.Open(); myCommand.ExecuteNonQuery(); } catch (Exception) { //do nothing } finally { if (connection.State == ConnectionState.Open) { connection.Close(); } } } }
public static List <WarRecord> GetParticipantsFromWarlog(string participantJson) { JObject jsonResp = JObject.Parse(participantJson); List <WarRecord> warList = new List <WarRecord>(); foreach (var item in jsonResp["items"]) { WarRecord _record = new WarRecord() { CreateDate = DateTime.ParseExact(item["createdDate"].ToString().Remove(8), "yyyyMMdd", CultureInfo.InvariantCulture), SeasonId = item["seasonId"].ToString(), Participants = new List <ParticipantRecord>() }; _record.Id = Int32.Parse(string.Format("{0}{1}{2}", _record.CreateDate.Day, _record.CreateDate.Month, _record.CreateDate.Year)); foreach (var war in item["participants"]) { _record.Participants.Add(new ParticipantRecord() { Tag = war["tag"].ToString().Substring(1), Name = war["name"].ToString(), BattlePlayed = war["battlesPlayed"].ToString(), CardsColleccted = war["cardsEarned"].ToString(), Wins = war["wins"].ToString() }); } warList.Add(_record); } return(warList); }