Пример #1
0
 public List <BlogPost> GetAllNonDraftBlogsByAuthor(string userName)
 {
     using (var ctx = new TechTruffleShuffleEntities())
     {
         return(ctx.BlogPost.Include("Hashtags").Include("BlogCategory").Include("BlogStatus").Include("User").Where(b => (b.BlogStatus.BlogStatusDescription == "Removed" || b.BlogStatus.BlogStatusDescription == "Published" || b.BlogStatus.BlogStatusDescription == "Pending") && (((b.User.FirstName + " " + b.User.LastName).Contains(userName)) || ((b.User.FirstName + b.User.LastName).Contains(userName)))).ToList());
     }
 }
Пример #2
0
 public StaticPage GetStaticPageByID(int ID)
 {
     using (var ctx = new TechTruffleShuffleEntities())
     {
         return(ctx.StaticPage.SingleOrDefault(i => i.StaticPageID == ID));
     }
 }
Пример #3
0
 public List <BlogPost> GetAllNonDraftBlogs()
 {
     using (var ctx = new TechTruffleShuffleEntities())
     {
         return(ctx.BlogPost.Include("Hashtags").Include("BlogCategory").Include("BlogStatus").Include("User").Where(b => (b.BlogStatus.BlogStatusDescription == "Removed" || b.BlogStatus.BlogStatusDescription == "Published" || b.BlogStatus.BlogStatusDescription == "Pending")).ToList());
     }
 }
Пример #4
0
 public List <BlogPost> GetAllPosts()
 {
     using (var ctx = new TechTruffleShuffleEntities())
     {
         return(ctx.BlogPost.Include("Hashtags").Include("BlogCategory").Include("BlogStatus").Include("User").ToList());
     }
 }
Пример #5
0
 public List <StaticPage> GetAllStaticPages()
 {
     using (var ctx = new TechTruffleShuffleEntities())
     {
         return(ctx.StaticPage.ToList());
     }
 }
Пример #6
0
 public List <BlogPost> GetPublishedPostsByTitle(string title)
 {
     using (var ctx = new TechTruffleShuffleEntities())
     {
         var getPublishedByTitle = ctx.BlogPost.Include("Hashtags").Include("BlogCategory").Include("BlogStatus").Include("User").Where(b => b.BlogStatus.BlogStatusDescription == "Published").Where(t => t.Title.Contains(title));
         return(getPublishedByTitle.ToList());
     }
 }
Пример #7
0
 public void AddHashTag(Hashtag newHash)
 {
     using (var ctx = new TechTruffleShuffleEntities())
     {
         ctx.Hashtag.Add(newHash);
         ctx.SaveChanges();
     }
 }
Пример #8
0
 public List <BlogPost> GetAllRemovedPosts()
 {
     using (var ctx = new TechTruffleShuffleEntities())
     {
         var getRemovedPosts = ctx.BlogPost.Include("Hashtags").Include("BlogCategory").Include("BlogStatus").Include("User").Where(i => i.BlogStatus.BlogStatusDescription == "Removed");
         return(getRemovedPosts.ToList());
     }
 }
Пример #9
0
 public List <BlogPost> GetAllPublishedPostsByCategory(int blogCategoryId)
 {
     using (var ctx = new TechTruffleShuffleEntities())
     {
         var getPublishedPostsByCategory = ctx.BlogPost.Include("Hashtags").Include("BlogCategory").Include("BlogStatus").Include("User").Where(c => c.BlogCategoryId == blogCategoryId).Where(s => s.BlogStatus.BlogStatusDescription == "Published");
         return(getPublishedPostsByCategory.ToList());
     }
 }
Пример #10
0
 public BlogPost GetBlogPostById(int blogpostId)
 {
     using (var ctx = new TechTruffleShuffleEntities())
     {
         var getThisPost = ctx.BlogPost.Include("Hashtags").Include("BlogCategory").Include("BlogStatus").Include("User").SingleOrDefault(i => i.BlogPostId == blogpostId);
         return(getThisPost);
     }
 }
Пример #11
0
 public void CreateStaticPage(StaticPage staticPage)
 {
     using (var ctx = new TechTruffleShuffleEntities())
     {
         ctx.StaticPage.Add(staticPage);
         ctx.SaveChanges();
     }
 }
Пример #12
0
        public Hashtag GetHashtag(string hashtagName)
        {
            using (var ctx = new TechTruffleShuffleEntities())
            {
                var hashtag = ctx.Hashtag.SingleOrDefault(c => c.HashtagName == hashtagName);

                return(hashtag);
            }
        }
Пример #13
0
        public List <BlogStatus> GetAllBlogStatuses()
        {
            using (var ctx = new TechTruffleShuffleEntities())
            {
                var getAllBlogStatuses = ctx.BlogStatus;

                return(getAllBlogStatuses.ToList());
            }
        }
Пример #14
0
        public BlogStatus GetBlogStatus(string status)
        {
            using (var ctx = new TechTruffleShuffleEntities())
            {
                var blogStatus = ctx.BlogStatus.SingleOrDefault(c => c.BlogStatusDescription == status);

                return(blogStatus);
            }
        }
Пример #15
0
        public BlogCategory GetBlogCategory(int id)
        {
            using (var ctx = new TechTruffleShuffleEntities())
            {
                var blogCategory = ctx.BlogCategory.SingleOrDefault(c => c.BlogCategoryId == id);

                return(blogCategory);
            }
        }
Пример #16
0
        public List <Hashtag> GetAllHashTags()
        {
            using (var ctx = new TechTruffleShuffleEntities())
            {
                var getAllHashtags = ctx.Hashtag;

                return(getAllHashtags.ToList());
            }
        }
Пример #17
0
        public List <BlogPost> GetAllFeaturedPosts()
        {
            using (var ctx = new TechTruffleShuffleEntities())
            {
                var isFeaturedPost = ctx.BlogPost.Include("Hashtags").Include("BlogCategory").Include("BlogStatus").Include("User").Where(i => i.IsFeatured == true).Where(p => p.BlogStatus.BlogStatusDescription == "Published");

                return(isFeaturedPost.ToList());
            }
        }
Пример #18
0
        public List <BlogCategory> GetAllBlogCategories()
        {
            using (var ctx = new TechTruffleShuffleEntities())
            {
                var getAllBlogCategories = ctx.BlogCategory;

                return(getAllBlogCategories.ToList());
            }
        }
Пример #19
0
 public void DeleteBlogPostDraft(int postId)
 {
     using (var ctx = new TechTruffleShuffleEntities())
     {
         var deleteThis = ctx.BlogPost.SingleOrDefault(i => i.BlogPostId == postId);
         ctx.BlogPost.Remove(deleteThis);
         ctx.SaveChanges();
     };
 }
Пример #20
0
        public List <BlogPost> GetAllPublishedPostsByHashtag(string hashtags)
        {
            using (var ctx = new TechTruffleShuffleEntities())
            {
                var getCollectionOfHashtags = ctx.BlogPost.Include("Hashtags").Include("BlogCategory").Include("BlogStatus").Include("User").Where(n => n.BlogStatus.BlogStatusDescription == "Published");
                getCollectionOfHashtags = getCollectionOfHashtags.Where(p => p.Hashtags.Any(t => t.HashtagName.Contains(hashtags)));

                return(getCollectionOfHashtags.ToList());
            }
        }
Пример #21
0
        public List <BlogPost> GetAllPublishedPostsByDate(string dateStart)
        {
            DateTime thisDate = new DateTime();

            DateTime.TryParse(dateStart, out thisDate);

            using (var ctx = new TechTruffleShuffleEntities())
            {
                var getPublishedPostByDate = ctx.BlogPost.Include("Hashtags").Include("BlogCategory").Include("BlogStatus").Include("User").Where(s => s.BlogStatus.BlogStatusDescription == "Published").Where(d => d.DateStart == thisDate);
                return(getPublishedPostByDate.ToList());
            }
        }
Пример #22
0
        public void CreateNewBlogPost(BlogPost newPost)
        {
            using (var ctx = new TechTruffleShuffleEntities())
            {
                var thisUser   = ctx.Users.SingleOrDefault(u => u.UserName == newPost.User.UserName);
                var thisStatus = ctx.BlogStatus.SingleOrDefault(s => s.BlogStatusId == newPost.BlogStatusId);
                newPost.User = thisUser;

                foreach (var hash in newPost.Hashtags.Where(i => i.HashtagId > 0))
                {
                    ctx.Hashtag.Attach(hash);
                }

                ctx.BlogStatus.Attach(newPost.BlogStatus);
                ctx.BlogPost.Add(newPost);
                ctx.SaveChanges();
            }
        }
Пример #23
0
        public void EditBlogPost(BlogPost updatedBlogPost)
        {
            using (var ctx = new TechTruffleShuffleEntities())
            {
                updatedBlogPost.User = ctx.Users.SingleOrDefault(u => u.Id == updatedBlogPost.UserId);

                updatedBlogPost.BlogCategoryId = updatedBlogPost.BlogCategory.BlogCategoryId;
                updatedBlogPost.BlogStatusId   = updatedBlogPost.BlogStatus.BlogStatusId;



                var allTagsOnBlogPost = updatedBlogPost.Hashtags;
                updatedBlogPost.Hashtags = new List <Hashtag>();
                ctx.BlogPost.Attach(updatedBlogPost);
                ctx.Entry(updatedBlogPost).State = System.Data.Entity.EntityState.Modified;
                ctx.Entry(updatedBlogPost).Collection(i => i.Hashtags).Load();

                var current = updatedBlogPost.Hashtags.ToList();

                updatedBlogPost.Hashtags.Clear();

                foreach (var hash in allTagsOnBlogPost)
                {
                    var currentHashTag = current.SingleOrDefault(i => i.HashtagId == hash.HashtagId);
                    if (currentHashTag == null)
                    {
                        ctx.Hashtag.Attach(hash);
                        updatedBlogPost.Hashtags.Add(hash);
                    }
                    else
                    {
                        updatedBlogPost.Hashtags.Add(currentHashTag);
                    }
                }

                ctx.BlogStatus.Attach(updatedBlogPost.BlogStatus);
                ctx.SaveChanges();
            }
        }