private List <ClanMember> GetClanStatistics(ClashRoyaleApi clashRoyaleApi) { using (var entities = new ClanManagerEntities()) { var dbMembers = entities.Member; List <ClanWar> latestWars = clashRoyaleApi.GetLatestClanWars(); var lastInfoPlayers = clashRoyaleApi.GetClanInfo(); List <ClanMember> members = new List <ClanMember>(); foreach (var player in lastInfoPlayers.members) { var clanMember = new ClanMember { Name = player.name, Tag = player.tag }; members.Add(clanMember); var dbMember = dbMembers.FirstOrDefault(s => s.Tag == player.tag); if (dbMember != null) { clanMember.JoinDate = dbMember.JoinDate; } else { clanMember.JoinDate = DateTime.Now; } } if (latestWars != null) { foreach (ClanWar war in latestWars) { foreach (var participant in war.participants) { var clanMember = members.FirstOrDefault(s => s.Tag == participant.tag); if (clanMember != null) { clanMember.ClanWars += participant.battlesPlayed; clanMember.ClanWins += participant.wins; clanMember.Percent = Math.Round((((double)(clanMember.ClanWins * 100)) / clanMember.ClanWars), 2); } } } } List <ClanMember> loyalMembers = members.Where(s => s.ClanWars > 5).ToList(); var newMembers = members.Where(s => s.ClanWars <= 5).ToList(); loyalMembers = loyalMembers.OrderByDescending(p => p.Percent).ToList(); newMembers = newMembers.OrderByDescending(p => p.Percent).ToList(); loyalMembers.AddRange(newMembers); return(loyalMembers); } }
public ActionResult Save(string message) { if (!string.IsNullOrEmpty(message)) { using (var entities = new ClanManagerEntities()) { entities.Suggestion.Add(new Suggestion { Message = message, DateTime = DateTime.Now }); entities.SaveChanges(); } } return(Json("Success")); }
private void ATimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e) { var clashRoyaleApi = new ClashRoyaleApi(); var clashRoyaleApiUk = new ClashRoyaleApi("PL8YLLUC"); var clanInfo = clashRoyaleApi.GetClanInfo(); var ukClanInfo = clashRoyaleApiUk.GetClanInfo(); var allMambers = clanInfo.members.ToList(); allMambers.AddRange(ukClanInfo.members); using (var entities = new ClanManagerEntities()) { var existingMembers = entities.Member; if (existingMembers.Any()) { foreach (var member in existingMembers) { if (!allMambers.Any(s => s.tag != member.Tag)) { entities.Member.Remove(member); } } } foreach (var member in allMambers) { if (!existingMembers.Any(s => s.Tag == member.tag)) { entities.Member.Add(new Member { JoinDate = DateTime.Now, Name = member.name, Tag = member.tag }); } } entities.SaveChanges(); } }