public async void Seed() { League league1 = new League { LeagueId = 1, Name = "Pierwsza Liga" }; League league2 = new League { LeagueId = 2, Name = "Druga Liga" }; League league3 = new League { LeagueId = 3, Name = "Trzecia Liga" }; League league4 = new League { LeagueId = 4, Name = "Czwarta Liga" }; await _context.AddAsync(league1); await _context.AddAsync(league2); await _context.AddAsync(league3); await _context.AddAsync(league4); await _context.SaveChangesAsync(); }
public async Task <int> AddResult(Domain.Result.Result result, string userId) { string[] resultScoreset1 = result.Set1.Split(":"); string[] resultScoreset2 = result.Set2.Split(":"); string[] resultScoreset3 = null; if (!CheckResult(resultScoreset1) || !CheckResult(resultScoreset2)) { return(-1); } if (result.Set3 != null) { resultScoreset3 = result.Set3.Split(":"); if (!CheckResult(resultScoreset3)) { return(-1); } } var player1 = await _context.CompetitorData.Where(x => x.UserId == userId).FirstOrDefaultAsync(); var player2 = await _context.CompetitorData.Where(x => x.CompetitorDataId == result.Enemy).FirstOrDefaultAsync(); if (result.League != 0 && (player1.LeagueId != result.League || player2.LeagueId != result.League)) { return(-2); } DAO.Match match = new DAO.Match { Competitor1Set1 = Int32.Parse(resultScoreset1[0]), Competitor2Set1 = Int32.Parse(resultScoreset1[1]), Competitor1Set2 = Int32.Parse(resultScoreset2[0]), Competitor2Set2 = Int32.Parse(resultScoreset2[1]), Competitor1 = player1.CompetitorDataId, Competitor2 = player2.CompetitorDataId, Confirmation = false, Protest = false, AddingTime = DateTime.Now }; if (resultScoreset3 != null) { match.Competitor1Set3 = Int32.Parse(resultScoreset3[0]); match.Competitor2Set3 = Int32.Parse(resultScoreset3[1]); } await _context.AddAsync(match); await _context.SaveChangesAsync(); UpdateTable(match); return(0); }
public async Task <int> AddCode(Domain.Code.Code code) { var legueExist = _context.League.Where(b => b.LeagueId == code.LegueId).FirstOrDefault(); if (legueExist == null && code.LegueId != 0) { return(-1); } var competitor = new DAO.CompetitorData { FirstName = code.FirstName, LastName = code.LastName, LeagueId = code.LegueId, }; await _context.AddAsync(competitor); await _context.SaveChangesAsync(); if (code.LegueId != 0) { var LastPLayer = _context.LeagueTable.OrderBy(k => k.Points).FirstOrDefault(); int position = 1; if (LastPLayer != null) { position = LastPLayer.Position; if (LastPLayer.Points != 0) { position += 1; } } LeagueTable league = new LeagueTable() { CompetitorDataId = competitor.CompetitorDataId, MatechesWon = 0, MatchesLoss = 0, SetsWon = 0, SetsLoss = 0, Points = 0, Position = position, LeagueId = code.LegueId }; await _context.AddAsync(league); } if (code.Competition) { var LastPLayer = _context.RankingTable.OrderByDescending(k => k.Position).FirstOrDefault(); int position = 1; if (LastPLayer != null) { position = LastPLayer.Position + 1; } RankingTable league = new RankingTable() { CompetitorDataId = competitor.CompetitorDataId, MatechesWon = 0, MetchesLoss = 0, Position = position }; await _context.AddAsync(league); } await _context.SaveChangesAsync(); return(competitor.CompetitorDataId); }