Ejemplo n.º 1
0
        public bool Create(string fullName, string email, string password)
        {
            using (var db = new JudgeAppContext())
            {
                if (this.UserExists(email, password))
                {
                    return(false);
                }

                var isAdmin = !db.Users.Any();

                var user = new User
                {
                    Email    = email,
                    FullName = fullName,
                    Password = password,
                    IsAdmin  = isAdmin,
                };

                db.Users.Add(user);
                db.SaveChanges();

                return(true);
            }
        }
Ejemplo n.º 2
0
 static Launcher()
 {
     using (var db = new JudgeAppContext())
     {
         db.Database.Migrate();
     }
 }
Ejemplo n.º 3
0
        public IActionResult Contests()
        {
            if (!this.User.IsAuthenticated)
            {
                return(this.Redirect("/"));
            }

            var contests = new JudgeAppContext().Contests
                           .Where(p => p.IsActive)
                           .Select(p =>
                                   $@"
                                                 <tr>
                                                     <th scope=""row"">{p.Name}</th>
                                                     <td>{p.Submissions.Count}</td>
                                                     <td><a type=""button"" method=""post"" class=""btn btn-warning"" href=""/users/edit?id={p.Id}"" role=""button"">
                                                 Edit</a>
                                                      <a type=""button"" method=""post"" class=""btn btn-danger"" href=""/users/delete?id={p.Id}"" role=""button"">
                                                 Delete</a></td>
                                                 </tr>")
                           .ToList();

            this.ViewModel["contests"] = string.Join(string.Empty, contests);

            return(this.View());
        }
Ejemplo n.º 4
0
        protected override void InitializeController()
        {
            base.InitializeController();

            if (this.User.IsAuthenticated)
            {
                this.ViewModel["layoutAnnonymousDisplay"] = "none";
                this.ViewModel["annonymousDisplay"]       = "none";
                this.ViewModel["layoutUserDisplay"]       = "flex";
                this.ViewModel["userDisplay"]             = "block";

                using (var db = new JudgeAppContext())
                {
                    this.Profile = db.Users
                                   .First(u => u.Email == this.User.Name);

                    if (this.IsAdmin)
                    {
                        this.ViewModel["layoutUserDisplay"]  = "none";
                        this.ViewModel["userDisplay"]        = "none";
                        this.ViewModel["adminDisplay"]       = "block";
                        this.ViewModel["layoutAdminDisplay"] = "flex";
                    }
                }
            }
        }
Ejemplo n.º 5
0
 public bool UserExists(string email)
 {
     using (var db = new JudgeAppContext())
     {
         return(db.Users.Any(u => u.Email == email));
     }
 }
Ejemplo n.º 6
0
 public bool UserExists(string email, string password)
 {
     using (var db = new JudgeAppContext())
     {
         return(db.Users.Any(u => u.Email == email && u.Password == password));
     }
 }
Ejemplo n.º 7
0
        public IActionResult Delete(int id)
        {
            using (var db = new JudgeAppContext())
            {
                var contest = db.Contests.First(c => c.Id == id);

                this.ViewModel["contestName"] = contest.Name;
                return(this.View());
            }
        }
Ejemplo n.º 8
0
        public IActionResult Submissions()
        {
            var submissions = new JudgeAppContext().Contests
                              .Select(s =>
                                      $@"<a href=""#"" class=""list-group-item"">{s.Name}</a>")
                              .ToList();

            this.ViewModel["contests"] = string.Join(string.Empty, contests);

            return(this.View());
        }
Ejemplo n.º 9
0
        public void Delete(int id, ContestModel model, User currentUser)
        {
            using (var db = new JudgeAppContext())
            {
                var contest = db.Contests.First(p => p.Id == id);

                if (!currentUser.IsAdmin && contest.UserId != currentUser.Id)
                {
                    return;
                }

                contest.IsActive = false;
                db.SaveChanges();
            }
        }
Ejemplo n.º 10
0
        public void Create(ContestModel model, User creator)
        {
            using (var db = new JudgeAppContext())
            {
                var contest = new Contest()
                {
                    Name     = model.Name,
                    UserId   = creator.Id,
                    IsActive = true,
                };

                db.Contests.Add(contest);
                db.SaveChanges();
            }
        }
Ejemplo n.º 11
0
        public IActionResult Login(LoginModel model)
        {
            if (!this.IsValidModel(model))
            {
                this.ShowError(LoginError);
                return(this.View());
            }

            if (!this.users.UserExists(model.Email))
            {
                this.ViewModel["show-error"] = "block";
                this.ViewModel["message"]    = LoginError;
                return(View());
            }

            this.SignIn(model.Email);

            using (var db = new JudgeAppContext())
            {
                this.Profile = db.Users.First(u => u.Email == model.Email);
            }

            return(this.Redirect("/"));
        }