Exemplo n.º 1
0
        public async Task Create(
            string projectId,
            IPage page,
            CancellationToken cancellationToken = default(CancellationToken)
            )
        {
            if (page == null)
            {
                throw new ArgumentException("page must not be null");
            }

            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;

            using (var dbContext = _contextFactory.CreateContext())
            {
                dbContext.Pages.Add(p);

                int rowsAffected = await dbContext.SaveChangesAsync(cancellationToken)
                                   .ConfigureAwait(false);
            }
        }
        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;
            }

            using (var db = _contextFactory.CreateContext())
            {
                db.Projects.Add(p);

                int rowsAffected = await db.SaveChangesAsync(cancellationToken)
                                   .ConfigureAwait(false);
            }
        }
Exemplo n.º 3
0
        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;

            using (var db = _contextFactory.CreateContext())
            {
                db.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;
                    }

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

                int rowsAffected = await db.SaveChangesAsync(cancellationToken)
                                   .ConfigureAwait(false);
            }
        }
        public async Task <ContentHistory> Fetch(
            string projectId,
            Guid id,
            CancellationToken cancellationToken = default(CancellationToken)
            )
        {
            cancellationToken.ThrowIfCancellationRequested();

            using (var _db = _contextFactory.CreateContext())
            {
                return(await _db.ContentHistory.AsNoTracking().SingleOrDefaultAsync(p => p.Id == id && p.ProjectId == projectId).ConfigureAwait(false));
            }
        }
 public async Task Create(
     string projectId,
     ContentHistory contentHistory,
     CancellationToken cancellationToken = default(CancellationToken)
     )
 {
     using (var _db = _contextFactory.CreateContext())
     {
         _db.ContentHistory.Add(contentHistory);
         int rowsAffected = await _db.SaveChangesAsync().ConfigureAwait(false);
     }
 }
Exemplo n.º 6
0
        public async Task <IProjectSettings> GetProjectSettings(
            string projectId,
            CancellationToken cancellationToken
            )
        {
            cancellationToken.ThrowIfCancellationRequested();

            using (var db = _contextFactory.CreateContext())
            {
                return(await db.Projects
                       .Where(p => p.Id == projectId)
                       .FirstOrDefaultAsync(cancellationToken)
                       .ConfigureAwait(false));
            }
        }
Exemplo n.º 7
0
        public async Task <List <IPage> > GetAllPages(
            string projectId,
            CancellationToken cancellationToken = default(CancellationToken)
            )
        {
            cancellationToken.ThrowIfCancellationRequested();

            using (var dbContext = _contextFactory.CreateContext())
            {
                var query = from x in dbContext.Pages
                            where x.ProjectId == projectId
                            select x;

                var items = await query
                            .AsNoTracking()
                            .ToListAsync <IPage>(cancellationToken)
                            .ConfigureAwait(false);

                return(items);
            }
        }
        public async Task <List <IPost> > GetPostsReadyForPublish(
            string blogId,
            CancellationToken cancellationToken = default(CancellationToken)
            )
        {
            cancellationToken.ThrowIfCancellationRequested();
            var currentTime = DateTime.UtcNow;

            using (var db = _contextFactory.CreateContext())
            {
                var query = from x in db.Posts
                            where x.BlogId == blogId &&
                            x.DraftPubDate != null &&
                            x.DraftPubDate < currentTime
                            select x;

                var items = await query
                            .AsNoTracking()
                            .ToListAsync <IPost>(cancellationToken)
                            .ConfigureAwait(false);

                return(items);
            }
        }