public ActionResult Bracket(int id)
        {
            var groups = new GroupsContext();
            Groups group = groups.Groups.Single(x => x.Id == id);

            var registrationsContext = new RegistrationContext();
            var registrations = registrationsContext.Registration.Where(r => r.GroupId == id).ToList();

            List<ApplicationUser> usersInGroup = new List<ApplicationUser>();

            var allUsers = new ApplicationDbContext();
            List<GroupWithUsers> allUsersInTournament = new List<GroupWithUsers>();

            foreach (var regs in registrations)
            {
                if (group.Id == regs.GroupId)
                {
                    usersInGroup.Add( allUsers.Users.Single(u => u.Id == regs.UserId));
                }
            }

            if (group.ClosedRegistation == true)
            { 
                if (group.IdFinalFight == null)
                {
                    
                }

                //show
            }

            return View(group);            
        }
 public void AddRegistration(Registration registration)
 {
     using (var registrationsContext = new RegistrationContext())
     {
         registrationsContext.Entry(registration).State = System.Data.Entity.EntityState.Added;
         registrationsContext.SaveChanges();
     }
 }
        public ActionResult DetailsPost(int SelectList, int tournamentId)
        {
            var currentUser = User.Identity.GetUserId();

            var registrationsContext = new RegistrationContext();

            var registration = new Registration();
            registration.Paid = false;
            registration.GroupId = SelectList;
            registration.UserId = currentUser;
            registration.TournamentId = tournamentId;

            if (ModelState.IsValid)
            {
                registrationsContext.AddRegistration(registration);
                UpdateModel(registrationsContext);
            }

            var tournament = ForDetails(currentUser, tournamentId);

            return View(tournament);
        }
        public ActionResult MyTournaments()
        {
            var CurrentUserId = User.Identity.GetUserId();
            var tournamentContext = new TournamentsContext();
            List<Tournament> organizedTournaments = tournamentContext.Tournament.Where(t => t.OrganizerId == CurrentUserId).ToList();

            var registrationContext = new RegistrationContext();
            var registredTo = registrationContext.Registration.Where(r => r.UserId == CurrentUserId).ToList();
            var participateTournaments = new List<Tournament>();
            foreach (var reg in registredTo)
            {
                var tourn = tournamentContext.Tournament.Single(t => t.Id == reg.TournamentId);
                participateTournaments.Add(tourn);
            }

            ViewBag.CountOrg = organizedTournaments.Count();
            ViewBag.CountPart = participateTournaments.Count();

            var tuple = new Tuple<List<Tournament>, List<Tournament>>(organizedTournaments, participateTournaments);

            return View(tuple);
        }
        private bool CurrentUserInTournament(int tournamentId, string currentUserId)
        {
            var registrationContext = new RegistrationContext();
            var currentUserRegistration = registrationContext.Registration.SingleOrDefault(r => r.UserId == currentUserId & r.TournamentId == tournamentId);

            if (currentUserRegistration == null)
            {
                return false;
            }
            else { return true; }
        }
        private bool DidPay(int tournamentId, string currentUser)
        {
            var registrationContext = new RegistrationContext();

            var isRegistred = registrationContext.Registration.Where(r => r.UserId == currentUser && r.TournamentId == tournamentId).ToList();

            if (isRegistred.Count != 0)
            {
                var reg = registrationContext.Registration.Single(r => r.UserId == currentUser && r.TournamentId == tournamentId);
                return reg.Paid;
            }
            else
            {
                return false;
            }
        }