public ReturnSet<bool> AddPost(PostCreationRequestItem requestItem) { using (var eFactory = new EFModel()) { var post = eFactory.Posts.Create(); post.Active = true; post.Created = DateTime.Now; post.Modified = DateTime.Now; post.Body = requestItem.Body; post.Summary = requestItem.Body.Length > 255 ? requestItem.Body.Substring(0, 252) + "..." : requestItem.Body; post.Title = requestItem.Title; post.SafeURL = requestItem.Title.Replace(" ", "-"); eFactory.Posts.Add(post); eFactory.SaveChanges(); var key = eFactory.DGTPostKeys.Create(); key.PostID = post.ID; key.PostKey = $"{post.Created.Year}_{post.Created.Month}_{post.Created.Day}_{post.SafeURL}"; eFactory.DGTPostKeys.Add(key); eFactory.SaveChanges(); return new ReturnSet<bool>(true); } }
public ReturnSet<PostResponseItem> GetPost(int year, int month, int day, string posturl) { using (var eFactory = new EFModel()) { var postKey = $"{year}/{month}/{day}/{posturl}"; var post = eFactory.DGTPostKeys.FirstOrDefault(a => a.PostKey == postKey); if (post == null) { throw new Exception($"Could not get Post {postKey}"); } return GetPost(post.PostID); } }
public ReturnSet<PostResponseItem> GetPost(int id) { using (var eFactory = new EFModel()) { var post = eFactory.Posts.FirstOrDefault(a => a.ID == id); if (post == null) { throw new Exception($"Could not get Post {id}"); } return new ReturnSet<PostResponseItem>(new PostResponseItem { Body = post.Body, Title = post.Title, PostDate = post.Created, Tags = new List<TagResponseItem>() }); } }
public ReturnSet<ContentResponseItem> GetContentPost(string postname) { using (var eFactory = new EFModel()) { var result = eFactory.ContentPosts.FirstOrDefault(a => a.URLSafename == postname); if (result == null) { return new ReturnSet<ContentResponseItem>(ErrorCodes.UNCATEGORIZED); } var response = new ContentResponseItem { Body = result.Body, Title = result.Title }; return new ReturnSet<ContentResponseItem>(response); } }
public ReturnSet<List<PostListingResponseItem>> GetPostListing(int pageSize, int? pageNumber = null) { using (var eFactory = new EFModel()) { var postListing = eFactory.Database.SqlQuery<PostListing>("POSTS_getPostListingSP @pageSize, @pageNumber", new SqlParameter("@pageSize", pageSize), new SqlParameter("@pageNumber", pageNumber.HasValue ? pageNumber.ToString() : "")); if (postListing == null) { throw new Exception("SP in getting posts returned null"); } return new ReturnSet<List<PostListingResponseItem>>(postListing.Select(a => new PostListingResponseItem { ID = a.ID, PostDate = a.Created, Title = a.Title, URL = a.SafeURL, Summary = a.Summary }).ToList()); } }