public async Task Create(
            string projectId,
            IProjectSettings project,
            CancellationToken cancellationToken = default(CancellationToken)
            )
        {
            if (project == null)
            {
                throw new ArgumentException("project must not be null");
            }
            if (string.IsNullOrEmpty(projectId))
            {
                throw new ArgumentException("projectId must be provided");
            }

            var p = ProjectSettings.FromIProjectSettings(project);

            if (string.IsNullOrEmpty(p.Id))
            {
                p.Id = projectId;
            }

            dbContext.Projects.Add(p);

            int rowsAffected = await dbContext.SaveChangesAsync(cancellationToken)
                               .ConfigureAwait(false);
        }
示例#2
0
        public async Task Create(
            string projectId,
            IPage page,
            CancellationToken cancellationToken = default(CancellationToken)
            )
        {
            if (page == null)
            {
                throw new ArgumentException("page must not be null");
            }
            //if (string.IsNullOrEmpty(projectId)) throw new ArgumentException("projectId must be provided");

            var p = PageEntity.FromIPage(page);

            if (string.IsNullOrEmpty(p.Id))
            {
                p.Id = Guid.NewGuid().ToString();
            }

            if (string.IsNullOrEmpty(p.ProjectId))
            {
                p.ProjectId = projectId;
            }
            p.LastModified = DateTime.UtcNow;
            p.PubDate      = DateTime.UtcNow;

            dbContext.Pages.Add(p);

            int rowsAffected = await dbContext.SaveChangesAsync(cancellationToken)
                               .ConfigureAwait(false);
        }
        public async Task Create(
            string projectId,
            IPost post,
            CancellationToken cancellationToken = default(CancellationToken)
            )
        {
            if (post == null)
            {
                throw new ArgumentException("post must not be null");
            }
            //if (string.IsNullOrEmpty(projectId)) throw new ArgumentException("projectId must be provided");

            var p = PostEntity.FromIPost(post);

            if (string.IsNullOrEmpty(p.Id))
            {
                p.Id = Guid.NewGuid().ToString();
            }

            if (string.IsNullOrEmpty(p.BlogId))
            {
                p.BlogId = projectId;
            }
            post.LastModified = DateTime.UtcNow;

            dbContext.Posts.Add(p);

            //need to add PostCategorys
            foreach (var c in p.Categories)
            {
                if (string.IsNullOrEmpty(c))
                {
                    continue;
                }
                var t = c.Trim();
                if (string.IsNullOrEmpty(t))
                {
                    continue;
                }

                dbContext.PostCategories.Add(new PostCategory
                {
                    ProjectId    = projectId,
                    PostEntityId = p.Id,
                    Value        = t
                });
            }

            int rowsAffected = await dbContext.SaveChangesAsync(cancellationToken)
                               .ConfigureAwait(false);
        }