示例#1
0
        public async Task PublishDraftVersion(string contentType, string contentId, string versionCode)
        {
            var toPublish = await GetVersionInfo(contentType, contentId, versionCode);

            if (toPublish.Status != ContentStatus.Draft)
            {
                throw new InvalidOperationException("Only draft versions can be published");
            }

            var oldPublished = await GetPublishedVersionInfo(contentType, contentId);

            if (oldPublished != null)
            {
                oldPublished.Status = ContentStatus.Archived;
                _connectDb.Attach <ContentVersion>(oldPublished);
                _connectDb.Entry(oldPublished).State = Microsoft.EntityFrameworkCore.EntityState.Modified;
            }

            toPublish.Status = ContentStatus.Published;

            _connectDb.Attach <ContentVersion>(toPublish);
            _connectDb.Entry(toPublish).State = Microsoft.EntityFrameworkCore.EntityState.Modified;

            await _connectDb.SaveChangesAsync();
        }
示例#2
0
        public async Task <FileDocument> UpdateAsync(FileDocument document)
        {
            using (var db = new ConnectDbContext(_writeDb))
            {
                db.Attach(document);
                db.Entry(document).State = EntityState.Modified;

                db.SaveChanges();
            }

            return(document);
        }
示例#3
0
        public void UpdateModel(TModel model)
        {
            var widget = new JsonWidget
            {
                Id        = model.Id,
                ModelType = model.GetType().FullName,
                ModelJson = JsonConvert.SerializeObject(model)
            };

            _db.Attach <JsonWidget>(widget);
            _db.Entry(widget).State = Microsoft.EntityFrameworkCore.EntityState.Modified;

            _db.SaveChanges();
        }