public ActionResult Edit(int?blogId, BlogConfigModel model) { if (ModelState.IsValid) { Data.Blog blog = null; if (blogId.HasValue) { blog = _blogRepo.GetBy(b => b.Id == blogId.Value); if (!_securityHelper.CurrentUser.IsAdminOfBlog(blog, _securableRepository)) { throw new HttpException(403, "Not Authorized"); } } else { blog = CurrentBlog; } blog.AnalyticsKey = model.AnalyticsKey; blog.AuthoritiveUrl = model.AuthoritiveUrl; blog.Description = model.Description; blog.DisqusShortname = model.DisqusShortname; blog.Name = model.Name; blog.Twitter = model.Twitter; _blogRepo.Update(blog); return(Json(new { success = true })); } return(PartialView("EditModal", model)); }
public ActionResult Edit(int?blogId) { Data.Blog blog = null; if (blogId.HasValue) { blog = _blogRepo.GetBy(b => b.Id == blogId.Value); if (!_securityHelper.CurrentUser.IsAdminOfBlog(blog, _securableRepository)) { throw new HttpException(403, "Not Authorized"); } } else { blog = CurrentBlog; } return(PartialView("EditModal", new BlogConfigModel { AnalyticsKey = blog.AnalyticsKey, AuthoritiveUrl = blog.AuthoritiveUrl, Description = blog.Description, DisqusShortname = blog.DisqusShortname, Name = blog.Name, Twitter = blog.Twitter, BlogStyleId = blog.BlogTemplateId })); }
// Declaration### // ###AddBlogImplementation public override IGraphQlObjectResult <Blog?> AddBlog(string url) => this.ResolveTask(async _ => { var blog = new Data.Blog { Url = url }; context.Add(blog); await context.SaveChangesAsync(); return(blog); }).Nullable(blog => blog.AsContract <BlogResolver>());
// ###AddBlogImplementation public override IGraphQlObjectResult <Blog?> AddBlog(string url) => this.ResolveTask(async _ => { var blog = new Data.Blog { BlogId = Guid.NewGuid(), Url = url }; Data.BloggingData.Blogs.Add(blog); await Task.Yield(); return(blog); }).Nullable(blog => blog.AsContract <BlogResolver>());
public int CreateOrUpdateBlog(BlogModel blog) { var dbBlog = BlogDb.Blogs.FirstOrDefault(a => a.BlogId == blog.BlogId); if (dbBlog == null) { dbBlog = new Data.Blog(); BlogDb.Blogs.InsertOnSubmit(dbBlog); } dbBlog.DisplayName = blog.Name; dbBlog.UrlName = blog.UrlName; dbBlog.Description = blog.Description; BlogDb.SubmitChanges(); blog.BlogId = dbBlog.BlogId; return blog.BlogId; }
public static bool IsAdminOfBlog(this User user, Data.Blog blog, IRepository <Securable> securableRepo) { return(securableRepo.IsMemberOfSecurable(blog.AdminSecurableId, user.Id) || user.IsPlatformAdmin(securableRepo)); }
protected override void Seed(StaticVoid.Blog.Data.BlogContext context) { #if DEBUG #if !DISABLE_SEED // This method will be called after migrating to the latest version. // You can use the DbSet<T>.AddOrUpdate() helper extension method // to avoid creating duplicate seed data. var admin = new User { Id = 1, ClaimedIdentifier = "", Email = "*****@*****.**", FirstName = "Luke", LastName = "McGregor", IsAuthor = true }; context.Users.AddOrUpdate(admin); var blogCreatorSecurable = new Securable { Name = "Blog Creator", Members = new List <User> { admin } }; context.Securables.AddOrUpdate(blogCreatorSecurable); if (!context.Blogs.Any()) { var blog = new Data.Blog { AuthoritiveUrl = "http://*****:*****@staticv0id", Style = new Style { Css = @".test{ }" }, AuthorSecurable = new Securable { Name = "Author : StaticVoid - Test" } }; context.Blogs.AddOrUpdate(blog); } var postDate = new DateTime(2012, 10, 7, 12, 0, 0); context.Posts.AddOrUpdate( new Post { Id = 1, AuthorId = 1, Title = "First Post", Body = "First Post!", Posted = postDate, Status = PostStatus.Published, Path = PostHelpers.MakeUrl(postDate.Year, postDate.Month, postDate.Day, "First Post"), Canonical = "/" + PostHelpers.MakeUrl(postDate.Year, postDate.Month, postDate.Day, "First Post") }); postDate = postDate.AddDays(1); context.Posts.AddOrUpdate( new Post { Id = 2, AuthorId = 1, Title = "Second Post", Body = "Second Post!", Posted = postDate, Status = PostStatus.Published, Path = PostHelpers.MakeUrl(postDate.Year, postDate.Month, postDate.Day, "Second Post"), Canonical = "/" + PostHelpers.MakeUrl(postDate.Year, postDate.Month, postDate.Day, "Second Post") }); #endif #endif }