protected override bool AuthorizeCore(HttpContextBase httpContext)
        {
            try
            {
                //если пользователь неавторизован, то не надо просить его заполнить личные данные
                if (!httpContext.User.Identity.IsAuthenticated) return true;

                var dataAccess = new DataAccess();

                var user = dataAccess.Users.Find(int.Parse(httpContext.User.Identity.Name));

                dataAccess.Entry(user).Reference(u => u.Player).Load();

                return user.Player != null;
            }
            catch
            {
                return true;
            }
        }
Esempio n. 2
0
        public static void Main(string[] args)
        {
            try
            {
                System.Data.Entity.Database.SetInitializer(new DataAccessInitializer());
                var dataAccess = new DataAccess();

                var pairTouranment = new PairTournament()
                {
                    Name = "Парный",
                    NumberOfPlayers = 4
                };

                dataAccess.PairTournaments.Add(pairTouranment);
                dataAccess.SaveChanges();

                var player1 = dataAccess.Players.FirstOrDefault(p => p.Id == 1);
                var player2 = dataAccess.Players.FirstOrDefault(p => p.Id == 2);
                var player3 = dataAccess.Players.FirstOrDefault(p => p.Id == 3);
                var player4 = dataAccess.Players.FirstOrDefault(p => p.Id == 4);

                pairTouranment.Participants.Add(new PairInTournament()
                {
                    Number = 1,
                    Player1 = player1,
                    Player2 = player2,
                    Seed = true
                });

                pairTouranment.Participants.Add(new PairInTournament()
                {
                    Number = 2,
                    Player1 = player3,
                    Player2 = player4,
                    Seed = true
                });

                dataAccess.SaveChanges();

                //pairTouranment.Matches.Add(new PairMatch()
                //{
                //    Player1 = player1,
                //    Player2 = player2,
                //    Player3 = player3,
                //    Player4 = player4,
                //    Winner1 = player1,
                //    Winner2 = player2,
                //    Stage = Stage.Final,
                //    Time = DateTime.Now,
                //    Score = "6:4;"
                //});

                //dataAccess.SaveChanges();

                //pairTouranment.Places.Add(new PairPlace()
                //{
                //    Player1 = player1,
                //    Player2 = player2,
                //    Position = 1
                //});

                dataAccess.SaveChanges();

                dataAccess.PairTournaments.Remove(pairTouranment);
                dataAccess.SaveChanges();
            }
            catch (Exception e)
            {

            }

            System.Console.ReadLine();
        }