public ActionResult CreateRounds(Tournament tournament, int? count) { foreach (var member in tournament.Members) { member.MemberName = _members.All.FirstOrDefault(c => c.MemberId == member.MemberId).MemberName; } tournament.Owner = _users.CurrentUser; _tournaments.InsertOrUpdate(tournament); _tournaments.Save(); for (int i = 0; i < count; i++) { var round = new Round{ Tournament = tournament }; _rounds.InsertOrUpdate(round); _rounds.Save(); //Высчитывается количество столов в раунде, исходя из общего количества участников, учитывая четность/нечетность var tablesCount = tournament.Members.Count() % 2 == 0 ? tournament.Members.Count() / 2 : tournament.Members.Count() / 2 + 1; for (int z = 0; z < tablesCount; z++) { var table = new Table { Round = round }; _tables.InsertOrUpdate(table); _tables.Save(); } } var rounds = _rounds.All; if (tournament != null && _rounds.All.Where(c => c.Tournament.TournamentId == tournament.TournamentId).Any()) { rounds = _rounds.All.Where(c => c.Tournament.TournamentId == tournament.TournamentId); } return PartialView(rounds); }
void ITournamentRepository.InsertOrUpdate(Tournament tournament) { if (tournament.TournamentId == default(int)) { _context.Tournaments.Add(tournament); } else { _context.Entry(tournament).State = System.Data.EntityState.Modified; } }
public ActionResult Create(Tournament tournament) { foreach (var member in tournament.Members) { member.MemberName = _members.All.FirstOrDefault(c => c.MemberId == member.MemberId).MemberName; } tournament.Owner = _users.CurrentUser; _tournaments.InsertOrUpdate(tournament); _tournaments.Save(); return RedirectToAction("Index", "Tournament"); }
void ITournamentRepository.Remove(Tournament tournament) { _context.Entry(tournament).State = System.Data.EntityState.Deleted; }
public ActionResult Edit(Tournament tournament) { if (ModelState.IsValid) { _tournaments.InsertOrUpdate(tournament); _tournaments.Save(); } return RedirectToAction("Index", "Tournament"); }