void ITableRepository.InsertOrUpdate(Table table)
 {
     if (table.TableId == default(int))
     {
         _context.Tables.Add(table);
     }
     else
     {
         _context.Entry(table).State = System.Data.EntityState.Modified;
     }
 }
 void ITableRepository.Remove(Table table)
 {
     _context.Entry(table).State = System.Data.EntityState.Deleted;
 }
        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);
        }