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 void CreateBlogPostComment( 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 = new Rock.CMS.BlogPostComment(); BlogPostCommentService.Add( existingBlogPostComment, currentUser.PersonId ); 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 ); } }