Beispiel #1
0
        public BlogEntry Get(int blogId)
        {
            BlogEntry result;

            using (var context = new EFEntities())
            {
                EFBlogEntry x = context.BlogEntries.Include("Category").SingleOrDefault(y => y.BlogId == blogId);
                result = new BlogEntry()
                {
                    BlogId      = x.BlogId,
                    DateCreated = x.DateCreated,
                    FullText    = x.FullText,
                    Author      = x.Author,
                    PreviewText = x.PreviewText,
                    Title       = x.Title,
                    Category    = new Category()
                    {
                        Id   = x.Category.CategoryId,
                        Text = x.Category.CategoryName
                    },
                    UnprocessedTags = x.TagListString,
                    Tags            = new List <string>()
                };
            }
            result.ConvertUnprocessedToTagList();
            return(result);
        }
Beispiel #2
0
 public ActionResult Post(BlogEntry newPost)
 {
     newPost.ConvertUnprocessedToTagList();
     newPost.Category = repo.GetCategories().FirstOrDefault(x => x.Id == newPost.Category.Id);
     repo.Add(newPost);
     return(RedirectToAction("Approve"));
 }
Beispiel #3
0
        public List <BlogEntry> GetPostsByTag(string tags)
        {
            List <BlogEntry> result  = new List <BlogEntry>();
            BlogEntry        discard = new BlogEntry()
            {
                UnprocessedTags = tags
            };

            discard.ConvertUnprocessedToTagList();
            using (var context = new EFEntities())
            {
                foreach (var tag in discard.Tags)
                {
                    List <BlogEntry> tagCheck = context.BlogEntries.Include("Category").Where(a => a.TagListString.Contains(tag) && a.Posted == true).ToList().Select(x => new BlogEntry()
                    {
                        BlogId      = x.BlogId,
                        DateCreated = x.DateCreated,
                        FullText    = x.FullText,
                        Author      = x.Author,
                        PreviewText = x.PreviewText,
                        Title       = x.Title,
                        Category    = new Category()
                        {
                            Id   = x.Category.CategoryId,
                            Text = x.Category.CategoryName
                        },
                        UnprocessedTags = x.TagListString,
                        Tags            = new List <string>()
                    }).ToList();
                    foreach (var tagCheckEntry in tagCheck)
                    {
                        if (!result.Contains(tagCheckEntry))
                        {
                            result.Add(tagCheckEntry);
                        }
                    }
                }
            }

            foreach (BlogEntry x in result)
            {
                x.ConvertUnprocessedToTagList();
            }
            return(result);
        }