public void ApiDeleteBlogPostComment( string id, string apiKey ) { using ( Rock.Data.UnitOfWorkScope uow = new Rock.Data.UnitOfWorkScope() ) { Rock.CMS.UserService userService = new Rock.CMS.UserService(); Rock.CMS.User user = userService.Queryable().Where( u => u.ApiKey == apiKey ).FirstOrDefault(); if (user != null) { uow.objectContext.Configuration.ProxyCreationEnabled = false; Rock.CMS.BlogPostCommentService BlogPostCommentService = new Rock.CMS.BlogPostCommentService(); Rock.CMS.BlogPostComment BlogPostComment = BlogPostCommentService.Get( int.Parse( id ) ); if ( BlogPostComment.Authorized( "Edit", user ) ) { BlogPostCommentService.Delete( BlogPostComment, user.PersonId ); BlogPostCommentService.Save( BlogPostComment, user.PersonId ); } else throw new WebFaultException<string>( "Not Authorized to Edit this BlogPostComment", System.Net.HttpStatusCode.Forbidden ); } else throw new WebFaultException<string>( "Invalid API Key", System.Net.HttpStatusCode.Forbidden ); } }
public void ApiCreateBlogPostComment( string apiKey, Rock.CMS.DTO.BlogPostComment BlogPostComment ) { using ( Rock.Data.UnitOfWorkScope uow = new Rock.Data.UnitOfWorkScope() ) { Rock.CMS.UserService userService = new Rock.CMS.UserService(); Rock.CMS.User user = userService.Queryable().Where( u => u.ApiKey == apiKey ).FirstOrDefault(); if (user != null) { uow.objectContext.Configuration.ProxyCreationEnabled = false; Rock.CMS.BlogPostCommentService BlogPostCommentService = new Rock.CMS.BlogPostCommentService(); Rock.CMS.BlogPostComment existingBlogPostComment = new Rock.CMS.BlogPostComment(); BlogPostCommentService.Add( existingBlogPostComment, user.PersonId ); uow.objectContext.Entry(existingBlogPostComment).CurrentValues.SetValues(BlogPostComment); if (existingBlogPostComment.IsValid) BlogPostCommentService.Save( existingBlogPostComment, user.PersonId ); else throw new WebFaultException<string>( existingBlogPostComment.ValidationResults.AsDelimited(", "), System.Net.HttpStatusCode.BadRequest ); } else throw new WebFaultException<string>( "Invalid API Key", System.Net.HttpStatusCode.Forbidden ); } }
public Rock.CMS.DTO.BlogPostComment ApiGet( string id, string apiKey ) { using (Rock.Data.UnitOfWorkScope uow = new Rock.Data.UnitOfWorkScope()) { Rock.CMS.UserService userService = new Rock.CMS.UserService(); Rock.CMS.User user = userService.Queryable().Where( u => u.ApiKey == apiKey ).FirstOrDefault(); if (user != null) { uow.objectContext.Configuration.ProxyCreationEnabled = false; Rock.CMS.BlogPostCommentService BlogPostCommentService = new Rock.CMS.BlogPostCommentService(); Rock.CMS.BlogPostComment BlogPostComment = BlogPostCommentService.Get( int.Parse( id ) ); if ( BlogPostComment.Authorized( "View", user ) ) return BlogPostComment.DataTransferObject; else throw new WebFaultException<string>( "Not Authorized to View this BlogPostComment", System.Net.HttpStatusCode.Forbidden ); } else throw new WebFaultException<string>( "Invalid API Key", System.Net.HttpStatusCode.Forbidden ); } }
public void UpdateBlogPostComment( string id, Rock.CMS.DTO.BlogPostComment BlogPostComment ) { var currentUser = Rock.CMS.UserService.GetCurrentUser(); if ( currentUser == null ) throw new WebFaultException<string>("Must be logged in", System.Net.HttpStatusCode.Forbidden ); using ( Rock.Data.UnitOfWorkScope uow = new Rock.Data.UnitOfWorkScope() ) { uow.objectContext.Configuration.ProxyCreationEnabled = false; Rock.CMS.BlogPostCommentService BlogPostCommentService = new Rock.CMS.BlogPostCommentService(); Rock.CMS.BlogPostComment existingBlogPostComment = BlogPostCommentService.Get( int.Parse( id ) ); if ( existingBlogPostComment.Authorized( "Edit", currentUser ) ) { uow.objectContext.Entry(existingBlogPostComment).CurrentValues.SetValues(BlogPostComment); if (existingBlogPostComment.IsValid) BlogPostCommentService.Save( existingBlogPostComment, currentUser.PersonId ); else throw new WebFaultException<string>( existingBlogPostComment.ValidationResults.AsDelimited(", "), System.Net.HttpStatusCode.BadRequest ); } else throw new WebFaultException<string>( "Not Authorized to Edit this BlogPostComment", System.Net.HttpStatusCode.Forbidden ); } }
public Rock.CMS.DTO.BlogPostComment Get( string id ) { var currentUser = Rock.CMS.UserService.GetCurrentUser(); if ( currentUser == null ) throw new WebFaultException<string>("Must be logged in", System.Net.HttpStatusCode.Forbidden ); using (Rock.Data.UnitOfWorkScope uow = new Rock.Data.UnitOfWorkScope()) { uow.objectContext.Configuration.ProxyCreationEnabled = false; Rock.CMS.BlogPostCommentService BlogPostCommentService = new Rock.CMS.BlogPostCommentService(); Rock.CMS.BlogPostComment BlogPostComment = BlogPostCommentService.Get( int.Parse( id ) ); if ( BlogPostComment.Authorized( "View", currentUser ) ) return BlogPostComment.DataTransferObject; else throw new WebFaultException<string>( "Not Authorized to View this BlogPostComment", System.Net.HttpStatusCode.Forbidden ); } }
public void DeleteBlogPostComment( string id ) { var currentUser = Rock.CMS.UserService.GetCurrentUser(); if ( currentUser == null ) throw new WebFaultException<string>("Must be logged in", System.Net.HttpStatusCode.Forbidden ); using ( Rock.Data.UnitOfWorkScope uow = new Rock.Data.UnitOfWorkScope() ) { uow.objectContext.Configuration.ProxyCreationEnabled = false; Rock.CMS.BlogPostCommentService BlogPostCommentService = new Rock.CMS.BlogPostCommentService(); Rock.CMS.BlogPostComment BlogPostComment = BlogPostCommentService.Get( int.Parse( id ) ); if ( BlogPostComment.Authorized( "Edit", currentUser ) ) { BlogPostCommentService.Delete( BlogPostComment, currentUser.PersonId ); BlogPostCommentService.Save( BlogPostComment, currentUser.PersonId ); } else throw new WebFaultException<string>( "Not Authorized to Edit this BlogPostComment", System.Net.HttpStatusCode.Forbidden ); } }