static Launcher() { using (var db = new ModPanelContext()) { db.Database.Migrate(); } }
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); } }
public bool UserExists(string email, string password) { using (var db = new ModPanelContext()) { return(db.Users.Any(u => u.Email == email && u.Password == password)); } }
public IActionResult Posts() { if (!this.User.IsAuthenticated || !this.IsAdmin) { return(this.Redirect("/")); } var allposts = new ModPanelContext().Posts .Where(p => p.IsActive) .Select(p => $@" <tr> <th scope=""row"">{p.Id}</th> <td>{p.Title}</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["posts"] = string.Join(string.Empty, allposts); return(this.View()); }
public IActionResult Users() { if (!this.User.IsAuthenticated || !this.Profile.IsAdmin) { return(this.Redirect("/")); } var users = new ModPanelContext().Users .Select(u => u.isApproved ? $@" <tr> <th scope=""row"">{u.Id}</th> <td>{u.Email}</td> <td>{u.Position}</td> <td>{u.Posts.Count}</td> <td>{u.Logs.Count}</td> </tr>" : $@" <tr> <th scope=""row"">{u.Id}</th> <td>{u.Email}</td> <td>{u.Position}</td> <td>{u.Posts.Count}</td> <td><a type=""button"" method=""post"" class=""btn btn-primary"" href=""/users/approve?id={u.Id}"" role=""button""> Approve</a></td> </tr>") .ToList(); this.ViewModel["users"] = string.Join(string.Empty, users); return(this.View()); }
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(); } }
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")); }
public static void Main(string[] args) { var server = new WebServer( 1337, new ControllerRouter(), new ResourceRouter()); var dbContext = new ModPanelContext(); MvcEngine.Run(server, dbContext); }
protected bool isApproved(string email) { using (var db = new ModPanelContext()) { if (db.Users.First(e => e.Email == email).isApproved) { return(true); } return(false); } }
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")); }
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(); } }
public IEnumerable <Post> All() { using (var db = new ModPanelContext()) { return(db.Posts .Where(p => p.IsActive) .Select(p => new Post { Id = p.Id, UserId = p.UserId, Title = p.Title, Content = p.Content, CreatedOn = p.CreatedOn, IsActive = true, }) .ToList()); } }
public override void OnAuthentication() { if (this.User.IsAuthenticated) { this.Model.Data["anonymousDisplay"] = "none"; this.Model.Data["userDisplay"] = "flex"; using (var context = new ModPanelContext()) { this.DbUser = context .Users .First(u => u.Email == this.User.Name); if (this.DbUser.IsAdmin) { this.Model.Data["adminDisplay"] = "flex"; } } } }
protected override void InitializeController() { base.InitializeController(); if (this.User.IsAuthenticated) { this.ViewModel["annonymousDisplay"] = "none"; this.ViewModel["userDisplay"] = "flex"; using (var db = new ModPanelContext()) { this.Profile = db.Users .First(u => u.Email == this.User.Name); if (this.IsAdmin) { this.ViewModel["userDisplay"] = "none"; this.ViewModel["adminDisplay"] = "flex"; } } } }
public IActionResult Index() { var userEmails = new ModPanelContext().Users.Select(ie => new { ie.Id, ie.Email }); var allposts = this.posts .All() .Select(p => $@" <div class=""card border-primary mb-3""> <div class=""card-body text-primary""> <h4 class=""card-title"">{p.Title}</h4> <p class=""card-text"">{p.Content}</p> </div> <div class=""card-footer bg-transparent text-right""> <span class=""text-muted"">Created on {p.CreatedOn.ToShortDateString()} by <em><strong>{userEmails.First(u => u.Id == p.UserId).Email}</strong></em> </span> </div> </div>") .ToList(); this.ViewModel["posts"] = string.Join(string.Empty, allposts); return(this.View()); }