예제 #1
0
        public BlogPosts GetPostsByTag(TagList tags)
        {
            using (BlogDatabaseContext context = new BlogDatabaseContext())
            {
                UnitOfWork uow = new UnitOfWork(context);

                var efposts = uow.Blogs.GetBlogsByTag(tags.tagList);

                List <BlogPost> blogPosts = new List <BlogPost>();

                foreach (var efpost in efposts)
                {
                    blogPosts.Add(_mapper.Map <BlogPost>(efpost));
                    blogPosts.Last().taglist = efpost.Taglist.Split(",").ToList();
                }

                blogPosts.OrderByDescending(u => u.updatedat.Date).ThenBy(u => u.updatedat.TimeOfDay);

                BlogPosts blogPostsToReturn = new BlogPosts();

                blogPostsToReturn.blogPosts = blogPosts;

                blogPostsToReturn.postCount = blogPosts.Count();

                return(blogPostsToReturn);
            }
        }
예제 #2
0
 public UnitOfWork(BlogDatabaseContext context)
 {
     if (context == null)
     {
         throw new ArgumentNullException("Context was not supplied");
     }
     _context = context;
 }
예제 #3
0
        public bool CheckSlug(string slug)
        {
            using (BlogDatabaseContext context = new BlogDatabaseContext())
            {
                UnitOfWork uow = new UnitOfWork(context);

                return(uow.Blogs.CheckSlugAvailability(slug));
            }
        }
예제 #4
0
        public void DeletePost(string slug)
        {
            using (BlogDatabaseContext context = new BlogDatabaseContext())
            {
                UnitOfWork uow = new UnitOfWork(context);
                uow.Blogs.DeleteBlogPost(slug);

                uow.Commit();
            }
        }
예제 #5
0
        public static void Seed(BlogDatabaseContext context)
        {
            context.Database.EnsureDeleted();
            context.Database.EnsureCreated();

            context.Tag.Add(new Tag()
            {
                TagName = "2018"
            });

            context.SaveChanges();
        }
예제 #6
0
        public TagList GetTagList()
        {
            using (BlogDatabaseContext context = new BlogDatabaseContext())
            {
                UnitOfWork uow = new UnitOfWork(context);

                TagList tagList = new TagList();

                tagList.tagList = uow.Tags.GetAllTags().Select(u => u.TagName).ToList();

                return(tagList);
            }
        }
예제 #7
0
        public BlogPost GetBlogPost(string slug)
        {
            using (BlogDatabaseContext context = new BlogDatabaseContext())
            {
                UnitOfWork uow = new UnitOfWork(context);

                Post foundBlogPost = uow.Blogs.GetBySlug(slug);

                BlogPost blogPost = _mapper.Map <BlogPost>(foundBlogPost);
                blogPost.taglist = foundBlogPost.Taglist.Split(",").ToList();

                return(blogPost);
            }
        }
예제 #8
0
        public bool ValidateTags(TagList tagList)
        {
            using (BlogDatabaseContext context = new BlogDatabaseContext())
            {
                UnitOfWork uow            = new UnitOfWork(context);
                List <Tag> tagsToValidate = new List <Tag>();
                foreach (var tag in tagList.tagList)
                {
                    Tag newTag = new Tag();
                    newTag.TagName = tag;
                    tagsToValidate.Add(newTag);
                }

                bool valid = uow.Tags.ValidateTags(tagsToValidate);
                return(valid);
            }
        }
예제 #9
0
        public BlogPost PostBlogPost(BlogPost blogToPost)
        {
            using (BlogDatabaseContext context = new BlogDatabaseContext())
            {
                UnitOfWork uow = new UnitOfWork(context);

                Post blogef = _mapper.Map <Post>(blogToPost);

                blogef.Taglist = string.Join(",", blogToPost.taglist);

                if (blogef is null)
                {
                    throw new Exception("Missing Blog Info");
                }

                uow.Blogs.AddNewBlog(blogef);

                uow.Commit();
                return(blogToPost);
            }
        }
예제 #10
0
        public BlogPost UpdateBlogPost(BlogPost blogPostToUpdate)
        {
            using (BlogDatabaseContext context = new BlogDatabaseContext())
            {
                UnitOfWork uow    = new UnitOfWork(context);
                Post       blogef = _mapper.Map <Post>(blogPostToUpdate);
                blogef.Taglist = string.Join(",", blogPostToUpdate.taglist);

                if (CheckSlug(blogPostToUpdate.slug))
                {
                    uow.Blogs.AddNewBlog(blogef);
                }
                else
                {
                    uow.Blogs.UpdateBlogPost(blogef);
                }

                uow.Commit();

                return(blogPostToUpdate);
            }
        }
예제 #11
0
 public BlogRepository(BlogDatabaseContext context)
     : base(context)
 {
 }
예제 #12
0
 public Repository(BlogDatabaseContext context)
 {
     //_objectSet = context.CreateObjectSet<T>();
     _dbSet = context.Set <T>();
 }
예제 #13
0
 public ArticleRepository(BlogDatabaseContext context, IMapper mapper)
 {
     this.context = context;
     this.mapper  = mapper;
 }
예제 #14
0
 public PostService(BlogDatabaseContext dbContext)
 {
     _dbContext = dbContext;
 }
예제 #15
0
 /// <summary>
 /// Default constructir
 /// </summary>
 /// <param name="databaseContext">Database context</param>
 public DatabaseProvider(BlogDatabaseContext databaseContext)
 {
     _databaseContext = databaseContext;
 }
예제 #16
0
 public ArticleQueries(BlogDatabaseContext context, IMapper mapper)
 {
     this.context = context;
     this.mapper  = mapper;
 }
 public ValuesController(BlogDatabaseContext dbContext)
 {
     this.dbContext = dbContext;
 }