protected void Page_Load(object sender, EventArgs e)
        {
            Master.FindControl("panelSiteMapPath").Visible = false;

            if (Context.User.Identity.IsAuthenticated)
            {
                var dbContext = new MasterChefDbContext();
                var data = new MasterChefData(dbContext);

                var user = data.Users.All()
                    .Single(x => x.UserName == this.Context.User.Identity.Name);
                var adminRole = data.Roles.All()
                    .Single(x => x.Name == "admin");

                if (user.Roles.Any(role => role.RoleId == adminRole.Id))
                {
                    this._isAdmin = true;
                }
            }
        }
示例#2
0
        protected void Page_Load(object sender, EventArgs e)
        {
            Master.FindControl("panelSiteMapPath").Visible = false;

            if (Context.User.Identity.IsAuthenticated)
            {
                var dbContext = new MasterChefDbContext();
                var data      = new MasterChefData(dbContext);

                var user = data.Users.All()
                           .Single(x => x.UserName == this.Context.User.Identity.Name);
                var adminRole = data.Roles.All()
                                .Single(x => x.Name == "admin");

                if (user.Roles.Any(role => role.RoleId == adminRole.Id))
                {
                    this._isAdmin = true;
                }
            }
        }
        public IQueryable <HomeNewestArticlesViewModel> ListViewNewestArticles_GetData()
        {
            var dbContext = new MasterChefDbContext();
            var data      = new MasterChefData(dbContext);

            var allArticles = data.Articles.All().ToList();
            var result      = allArticles
                              .OrderByDescending(article => article.CreatedOn)
                              .Take(3)
                              .Select(x => new HomeNewestArticlesViewModel
            {
                ID        = x.ID,
                Title     = x.Title,
                ImagePath = x.Image.Path,
                Comments  = x.Comments.Count,
                Likes     = x.Likes.Count
            })
                              .AsQueryable();

            return(result);
        }
        public IQueryable<HomeNewestArticlesViewModel> ListViewNewestArticles_GetData()
        {
            var dbContext = new MasterChefDbContext();
            var data = new MasterChefData(dbContext);

            var allArticles = data.Articles.All().ToList();
            var result = allArticles
                .OrderByDescending(article => article.CreatedOn)
                .Take(3)
                .Select(x => new HomeNewestArticlesViewModel
                {
                    ID = x.ID,
                    Title = x.Title,
                    ImagePath = x.Image.Path,
                    Comments = x.Comments.Count,
                    Likes = x.Likes.Count
                })
                .AsQueryable();

            return result;
        }