Example #1
0
 static Launcher()
 {
     using (var db = new ModPanelDbContext())
     {
         db.Database.Migrate();
     }
 }
Example #2
0
        public override void OnAuthentication()
        {
            this.Model["topMenu"] = this.User.IsAuthenticated ? Constants.UsersTopMenuHtml : Constants.GuestsTopMenuHtml;

            if (this.User.IsAuthenticated)
            {
                this.Model["topMenu"] = Constants.UsersTopMenuHtml;

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

                    if (this.Profile.IsAdmin)
                    {
                        this.Model["adminMenu"] = Constants.AdminOnlyMenu;
                    }
                }
            }
            else
            {
                this.Model["topMenu"] = Constants.GuestsTopMenuHtml;
            }

            base.OnAuthentication();
        }
Example #3
0
        public bool Create(string email, string password, PositionType position)
        {
            using (var db = new ModPanelDbContext())
            {
                if (db.Users.Any(u => u.Email == email))
                {
                    return(false);
                }

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

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

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

                return(true);
            }
        }
Example #4
0
 public bool UserIsApproved(string email)
 {
     using (var db = new ModPanelDbContext())
     {
         return(db.Users
                .Any(u => u.Email == email && u.IsApproved));
     }
 }
        static StartUp()
        {
            using (ModPanelDbContext db = new ModPanelDbContext())
            {
                db.Database.Migrate();
            }

            AutoMapperConfiguration.Initialize();
        }
        static Launcher()
        {
            using (var context = new ModPanelDbContext())
            {
                context.Database.Migrate();
            }

            AutoMapperConfiguration.Initialize();
        }
Example #7
0
 public bool UserExists(string email, string password)
 {
     using (var db = new ModPanelDbContext())
     {
         return(db
                .Users
                .Any(u => u.Email == email && u.Password == password));
     }
 }
        public static void Main()
        {
            var context = new ModPanelDbContext();

            var server = new WebServer(
                42420,
                new ControllerRouter(),
                new ResourceRouter());

            MvcEngine.Run(server, new ModPanelDbContext());
        }
Example #9
0
 public PostsModel GetById(int id)
 {
     using (var db = new ModPanelDbContext())
     {
         return(db.Posts.Where(p => p.Id == id)
                .Select(p => new PostsModel
         {
             Title = p.Title,
             Content = p.Content
         })
                .FirstOrDefault());
     }
 }
Example #10
0
 public IEnumerable <PostsAdminToList> All()
 {
     using (var db = new ModPanelDbContext())
     {
         return(db.Posts
                .Select(p => new PostsAdminToList
         {
             Id = p.Id,
             Title = p.Title
         })
                .ToList());
     }
 }
Example #11
0
        public void Create(string admin, LogType type, string additionalInformation)
        {
            using (var db = new ModPanelDbContext())
            {
                var log = new Log
                {
                    Admin = admin,
                    Type  = type,
                    AdditionalInformation = additionalInformation
                };

                db.Logs.Add(log);
                db.SaveChanges();
            }
        }
Example #12
0
 public IEnumerable <AdminUserAdding> All()
 {
     using (var db = new ModPanelDbContext())
     {
         return(db.Users
                .Select(u => new AdminUserAdding {
             Id = u.Id,
             Email = u.Email,
             Position = u.Position,
             Posts = u.Posts.Count,
             IsApproved = u.IsApproved,
         })
                .ToList());
     }
 }
Example #13
0
 public IEnumerable <LogModel> All()
 {
     using (var db = new ModPanelDbContext())
     {
         return(db
                .Logs
                .OrderByDescending(l => l.Id)
                .Select(l => new LogModel {
             Admin = l.Admin,
             AdditionalInformation = l.AdditionalInformation,
             Type = l.Type
         })
                .ToList());
     }
 }
Example #14
0
        public void Update(int id, string title, string content)
        {
            using (var db = new ModPanelDbContext())
            {
                var post = db.Posts.Find(id);

                if (post == null)
                {
                    return;
                }

                post.Title   = title;
                post.Content = content;
                db.SaveChanges();
            }
        }
Example #15
0
        public void Create(string title, string content, int userId)
        {
            using (var db = new ModPanelDbContext())
            {
                var post = new Post
                {
                    Title     = title.Capitalize(),
                    Content   = content,
                    UserId    = userId,
                    CreatedOn = DateTime.UtcNow
                };

                db.Posts.Add(post);
                db.SaveChanges();
            }
        }
Example #16
0
        public string Approve(int id)
        {
            using (var db = new ModPanelDbContext())
            {
                var user = db.Users.Find(id);

                if (user != null)
                {
                    user.IsApproved = true;

                    db.SaveChanges();
                }

                return(user?.Email);
            }
        }
Example #17
0
        public string Delete(int id)
        {
            using (var db = new ModPanelDbContext())
            {
                var post = db.Posts.Find(id);

                if (post == null)
                {
                    return(null);
                }

                db.Posts.Remove(post);
                db.SaveChanges();

                return(post.Title);
            }
        }
Example #18
0
        protected override void InitializeController()
        {
            base.InitializeController();

            if (this.User.IsAuthenticated)
            {
                this.ViewModel["anonymousDisplay"] = "none";
                this.ViewModel["userDisplay"]      = "flex";

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

                    if (this.Profile.IsAdmin)
                    {
                        this.ViewModel["adminDisplay"] = "flex";
                    }
                }
            }
        }
Example #19
0
        public IEnumerable <HomeListingModel> AllWithDetails(string search = null)
        {
            using (var db = new ModPanelDbContext())
            {
                var query = db.Posts.AsQueryable();

                if (!string.IsNullOrWhiteSpace(search))
                {
                    query = query.Where(p => p.Title.ToLower().Contains(search.ToLower()));
                }

                return(query
                       .OrderByDescending(p => p.Id)
                       .Select(p => new HomeListingModel
                {
                    Title = p.Title,
                    Content = p.Content,
                    CreatedBy = p.User.Email,
                    CreatedOn = p.CreatedOn
                })
                       .ToList());
            }
        }
Example #20
0
 public PostService(ModPanelDbContext context)
 {
     this.context = context;
 }
 public UserService(ModPanelDbContext db)
 {
     this.db = db;
 }
Example #22
0
 public PostsService()
 {
     this.db = new ModPanelDbContext();
 }
 public PostService(ModPanelDbContext database)
 {
     this.database = database;
 }
Example #24
0
 public UserService()
 {
     this.db = new ModPanelDbContext();
 }
Example #25
0
 public PostService(ModPanelDbContext db)
 {
     this.db = db;
 }
Example #26
0
 public LogService(ModPanelDbContext db)
 {
     this.db = db;
 }
Example #27
0
 public UserService(ModPanelDbContext context)
 {
     this.context = context;
 }