Exemplo n.º 1
0
        public bool Create(string email, string password, Positions position)
        {
            using (var db = new ModPanelContext())
            {
                if (this.UserExists(email, password))
                {
                    return(false);
                }

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

                var user = new User
                {
                    Email      = email,
                    Password   = password,
                    IsAdmin    = isAdmin,
                    Position   = position,
                    isApproved = false,
                };

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

                return(true);
            }
        }
Exemplo n.º 2
0
        public void Update(PostModel model)
        {
            using (var db = new ModPanelContext())
            {
                var post = db.Posts.First(p => p.Title == model.Title);
                post.Content = model.Content;

                db.SaveChanges();
            }
        }
Exemplo n.º 3
0
        public IActionResult Approve(int id)
        {
            using (var db = new ModPanelContext())
            {
                db.Users.First(u => u.Id == id).isApproved = true;
                db.SaveChanges();
            }

            return(this.Redirect("/users/users"));
        }
Exemplo n.º 4
0
        public IActionResult Delete(int id)
        {
            if (!this.User.IsAuthenticated || !this.IsAdmin)
            {
                return(this.Redirect("/"));
            }

            using (var db = new ModPanelContext())
            {
                db.Posts.First(p => p.Id == id).IsActive = false;
                db.SaveChanges();
            }

            return(this.Redirect("/users/posts"));
        }
Exemplo n.º 5
0
        public void Create(int userID, string title, string content, string email, DateTime CreatedOn)
        {
            using (var db = new ModPanelContext())
            {
                var post = new Post
                {
                    UserId    = userID,
                    Title     = title,
                    Content   = content,
                    CreatedOn = CreatedOn,
                };

                db.Posts.Add(post);
                db.SaveChanges();
            }
        }