Ejemplo n.º 1
0
 protected virtual async Task <TPublishRecord> GetRecordAsync(IContentItem entity, Site site, bool allSites)
 {
     return(await _dbContext.Set <TPublishRecord>()
            .FirstOrDefaultAsync(r =>
                                 r.Type == entity.GetKey() && r.ContentId == entity.Id &&
                                 (allSites || r.SiteIds.Contains(site.Id))));
 }
Ejemplo n.º 2
0
 protected async Task <IEnumerable <TPublishRecord> > GetRecordsAsync(IContentItem entity)
 {
     return(await _dbContext.Set <TPublishRecord>()
            .Where(r =>
                   r.Type == entity.GetKey() && r.ContentId == entity.Id)
            .ToListAsync());
 }
Ejemplo n.º 3
0
        public virtual async Task <bool> PublishAsync(IContentItem entity, TConfig config, bool needUpdate,
                                                      Site site, bool allSites = false)
        {
            try
            {
                var isNew  = false;
                var record = await GetRecordAsync(entity, site, allSites);

                if (record != null && !needUpdate)
                {
                    return(true);
                }

                if (record == null)
                {
                    isNew  = true;
                    record = new TPublishRecord
                    {
                        Id        = Guid.NewGuid(),
                        ContentId = entity.Id,
                        Type      = entity.GetKey(),
                        SiteIds   = !allSites ? new[] { site.Id } : entity.SiteIds
                    };
                }

                await DoPublishAsync(record, entity, site, config);

                if (isNew)
                {
                    _dbContext.Set <TPublishRecord>().Add(record);
                }
                else
                {
                    _dbContext.Set <TPublishRecord>().Update(record);
                }

                await _dbContext.SaveChangesAsync();

                return(true);
            }
            catch (Exception ex)
            {
                Logger.LogError(ex, "Error while publishing to {publisher}: {errorText}", GetType().FullName,
                                ex.ToString());
                return(false);
            }
        }
 public Task <int> GetCommentsCountAsync(IContentItem entity)
 {
     return(GetDbSet().Where(c => c.ContentId == entity.Id && c.ContentType == entity.GetKey())
            .CountAsync());
 }