Beispiel #1
0
        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);
            }
        }
Beispiel #2
0
        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);
            }
        }
Beispiel #3
0
        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>()
                });
            }
        }
Beispiel #4
0
        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);
            }
        }
Beispiel #5
0
        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());
            }
        }