public async Task <ActionResult <Player> > Post(TopScorers player) { if (player == null) { return(BadRequest()); } db.Players.Add(player); await db.SaveChangesAsync(); return(Ok(player)); }
public async Task <ActionResult <Player> > Delete(int id) { TopScorers player = db.Players.FirstOrDefault(x => x.player_id == id); if (player == null) { return(NotFound()); } db.Players.Remove(player); await db.SaveChangesAsync(); return(Ok(player)); }
public async Task <ActionResult <Player> > Put(TopScorers player) { if (player == null) { return(BadRequest()); } if (!db.Players.Any(x => x.player_id == player.player_id)) { return(NotFound()); } db.Update(player); await db.SaveChangesAsync(); return(Ok(player)); }
private static async void BotOnMessageReceived(object sender, Telegram.Bot.Args.MessageEventArgs e) { var client = new HttpClient(); var message = e.Message; if (message == null || message.Type != MessageType.Text) { return; } string name = $"{message.From.FirstName} {message.From.LastName}"; Console.WriteLine($"{name} { message.Text}"); switch (message.Text) { case "/start": string text = @"Список команд: /start - запуск бота /inline - меню /keyboard - клавіатура"; await Bot.SendTextMessageAsync(message.From.Id, text); break; case "/gettopscorer": var inlineKeyboard = new InlineKeyboardMarkup(new[] { new[] { InlineKeyboardButton.WithCallbackData("0"), InlineKeyboardButton.WithCallbackData("1"), InlineKeyboardButton.WithCallbackData("2"), InlineKeyboardButton.WithCallbackData("3"), InlineKeyboardButton.WithCallbackData("4") }, new[] { InlineKeyboardButton.WithCallbackData("5"), InlineKeyboardButton.WithCallbackData("6"), InlineKeyboardButton.WithCallbackData("7"), InlineKeyboardButton.WithCallbackData("8"), InlineKeyboardButton.WithCallbackData("9") }, new[] { InlineKeyboardButton.WithCallbackData("10"), InlineKeyboardButton.WithCallbackData("11"), InlineKeyboardButton.WithCallbackData("12"), InlineKeyboardButton.WithCallbackData("13"), InlineKeyboardButton.WithCallbackData("14") }, new[] { InlineKeyboardButton.WithCallbackData("15"), InlineKeyboardButton.WithCallbackData("16"), InlineKeyboardButton.WithCallbackData("17"), InlineKeyboardButton.WithCallbackData("18"), InlineKeyboardButton.WithCallbackData("19") } }); await Bot.SendTextMessageAsync(message.From.Id, "Виберіть номер футболіста 0 - 19 ", replyMarkup : inlineKeyboard); string data = buttonText; //await Bot.SendTextMessageAsync(message.From.Id, $"{data}"); //var message1 = message; //message = Convert.ToString(e.Message); /*var request5.numberNote = Convert.ToInt32(message.Text)*/ ; //await Bot.SendTextMessageAsync(message.From.Id, $"{m}"); //await Bot.SendTextMessageAsync(message.From.Id, $"{data}"); var content = await client.GetStringAsync($"https://localhost:44344/api/sportinfo/data"); TopScorers topScorers = JsonConvert.DeserializeObject <TopScorers>(content); await Bot.SendTextMessageAsync(message.From.Id, $"Ім’я: {topScorers.firstname}"); await Bot.SendTextMessageAsync(message.From.Id, $"Призвище: {topScorers.lastname}"); await Bot.SendTextMessageAsync(message.From.Id, $"Національність: {topScorers.nationality}"); await Bot.SendTextMessageAsync(message.From.Id, $"Загальний час на полі: {topScorers.games.minutes_played}"); await Bot.SendTextMessageAsync(message.From.Id, $"Кількість голів: {topScorers.goals.total}"); await Bot.SendTextMessageAsync(message.From.Id, $"Кількість ударів: {topScorers.shots.total}"); await Bot.SendTextMessageAsync(message.From.Id, $"Кількість ударів в площину воріт: {topScorers.shots.on}"); await Bot.SendTextMessageAsync(message.From.Id, $"Кількість асистів: {topScorers.goals.assists}"); await Bot.SendTextMessageAsync(message.From.Id, $"Кількість жовтих карток: {topScorers.cards.yellow}"); await Bot.SendTextMessageAsync(message.From.Id, $"Кількість червоних карток: {topScorers.cards.red}"); break; default: break; } }
public Game Play(Club a, Club b, string season = "Training", string league = "Training", bool notFinal = true) { int homePlus = 0; if (notFinal) { homePlus += 3; } Random rnd = new Random(); var aPlayers = _dbContext.Players.Where(p => p.ClubId == a.Id).OrderBy(p => - p.Score).Take(11).ToList(); var bPlayers = _dbContext.Players.Where(p => p.ClubId == b.Id).OrderBy(p => - p.Score).Take(11).ToList(); int aAvg, bAvg, sumA = 0, sumB = 0; string [] defenders = new string[7] { "RB", "RWB", "CB", "LB", "LWB", "LCB", "RCB" }; string[] midlefields = new string[13] { "CDM", "CM", "CAM", "RM", "RW", "LM", "LW", "LCM", "RCM", "LDM", "RAM", "LAM", "RDM" }; string[] attackers = new string[6] { "CF", "RF", "LF", "ST", "LS", "RS" }; // A Team var aAttackers = new List <Player>(); var aMidleFields = new List <Player>();; var aDefenders = new List <Player>();; foreach (var aPlayer in aPlayers) { sumA += aPlayer.Score; if (attackers.Contains(aPlayer.Position)) { aAttackers.Add(aPlayer); } else if (midlefields.Contains(aPlayer.Position)) { aMidleFields.Add(aPlayer); } else if (defenders.Contains(aPlayer.Position)) { aDefenders.Add(aPlayer); } } var aPlayingClub = aAttackers.Concat(aMidleFields).ToList(); aPlayingClub = aPlayingClub.Concat(aDefenders).ToList(); aAvg = sumA / 11; // B Team var bAttackers = new List <Player>(); var bMidleFields = new List <Player>(); var bDefenders = new List <Player>(); foreach (var bPlayer in bPlayers) { sumB += bPlayer.Score; if (attackers.Contains(bPlayer.Position)) { bAttackers.Add(bPlayer); } else if (midlefields.Contains(bPlayer.Position)) { bMidleFields.Add(bPlayer); } else if (defenders.Contains(bPlayer.Position)) { bDefenders.Add(bPlayer); } } var bPlayingClub = bAttackers.Concat(bMidleFields).ToList(); bPlayingClub = bPlayingClub.Concat(bDefenders).ToList(); bAvg = sumB / 11; string aGoals = ""; string bGoals = ""; int aScore = 0; int bScore = 0; for (int i = 0; i < 90; i++) { if (rnd.Next(1, 51 - Math.Abs(aAvg - bAvg)) == 1) { if (rnd.Next(aAvg, 101 + homePlus) > rnd.Next(bAvg, 101)) { foreach (var aPlayer in aPlayingClub) { if (rnd.Next(0, 2) == 1) { aGoals += aPlayer.Name + " " + i + ", "; aScore++; if (_dbContext.TopScorers.FirstOrDefault(c => c.PlayerId == aPlayer.Id && c.League == league && c.Season == season) != null) { var topScorer = _dbContext.TopScorers.FirstOrDefault(c => c.PlayerId == aPlayer.Id && c.League == league && c.Season == season); topScorer.Count++; _dbContext.Update(topScorer); _dbContext.SaveChanges(); } else { var topScorer = new TopScorers() { PlayerId = aPlayer.Id, Count = 1, League = league, Season = season }; _dbContext.Entry(topScorer).State = EntityState.Added; _dbContext.SaveChanges(); } break; } } } else { foreach (var bPlayer in bPlayingClub) { if (rnd.Next(0, 2) == 1) { bGoals += bPlayer.Name + " " + i + ", "; bScore++; if (_dbContext.TopScorers.FirstOrDefault(c => c.PlayerId == bPlayer.Id && c.League == league && c.Season == season) != null) { var topScorer = _dbContext.TopScorers.FirstOrDefault(c => c.PlayerId == bPlayer.Id && c.League == league && c.Season == season); topScorer.Count++; _dbContext.Update(topScorer); _dbContext.SaveChanges(); } else { var topScorer = new TopScorers() { PlayerId = bPlayer.Id, Count = 1, League = league, Season = season }; _dbContext.Entry(topScorer).State = EntityState.Added; _dbContext.SaveChanges(); } break; } } } } } string winner; if (aScore > bScore) { winner = a.Name; } else if (bScore > aScore) { winner = b.Name; } else { winner = "Draw"; } var game = new Game() { HomeClub = a.Name, GuestClub = b.Name, League = league, Season = season, HomeGoals = aGoals, GuestGoals = bGoals, HomeScore = aScore, GuestScore = bScore, Winner = winner }; _dbContext.Entry(game).State = EntityState.Added; _dbContext.SaveChanges(); return(game); }