예제 #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();
            }
        }