public IActionResult Editor(int id)
        {
            var profile = GetProfile();

            List <SelectListItem> categories = null;
            var post = new BlogPost();

            categories = _db.Categories.CategoryList(c => c.ProfileId == profile.Id).ToList();

            if (id > 0)
            {
                post = _db.BlogPosts.SingleIncluded(p => p.Id == id).Result;
            }

            if (post.PostCategories != null)
            {
                foreach (var pc in post.PostCategories)
                {
                    foreach (var cat in categories)
                    {
                        if (pc.CategoryId.ToString() == cat.Value)
                        {
                            cat.Selected = true;
                        }
                    }
                }
            }

            var model = new AdminEditorModel {
                Profile = profile, CategoryList = categories, BlogPost = post
            };

            return(View(_theme + "Editor.cshtml", model));
        }
Exemple #2
0
        public IActionResult Editor(int id, string user = "******")
        {
            var profile     = GetProfile();
            var userProfile = profile;

            if (user != "0")
            {
                userProfile = this.db.Profiles.Single(p => p.Id == int.Parse(user));
            }

            var post       = new BlogPost();
            var categories = this.db.Categories.CategoryList(c => c.ProfileId == userProfile.Id).ToList();

            if (id > 0)
            {
                if (profile.IsAdmin)
                {
                    post = this.db.BlogPosts.SingleIncluded(p => p.Id == id).Result;
                }
                else
                {
                    post = this.db.BlogPosts.SingleIncluded(p => p.Id == id && p.Profile.Id == profile.Id).Result;
                }
            }

            if (post.PostCategories != null)
            {
                foreach (var pc in post.PostCategories)
                {
                    foreach (var cat in categories)
                    {
                        if (pc.CategoryId.ToString() == cat.Value)
                        {
                            cat.Selected = true;
                        }
                    }
                }
            }

            var model = new AdminEditorModel {
                Profile = profile, CategoryList = categories, BlogPost = post
            };

            return(View(this.theme + "Editor.cshtml",
                        model));
        }