public void UpdatePage(int pageId, PageUpdate update) { var page = _db.Pages.SingleOrDefault(r => r.id == pageId && !r.deleted); if (page == null) { throw new Exception($"The page with id {pageId} does not exist"); } // Always set the child components JSON page.json = update.json.Replace("\\r", ""); // This is a column update so create the column if (update.column != null) { if (update.dataSourceId == null) { throw new Exception("DatasourceId is missing from the update"); } using (var tbl = new FlexTable(_config.GetConnectionString("DefaultConnection"), update.dataSourceId)) { tbl.CreateColumn(update.column.name, update.column.type, true); } } _db.SaveChanges(); }
bool IFileSet.Write(ITransaction transaction, PageUpdate update) { if (transaction == null) { ulong filePageNumber; int fileIndex; GetPageLocation(update.PageNumber, out filePageNumber, out fileIndex); return(_dataFiles[fileIndex].Write(filePageNumber, update.Data, update.Offset)); } TransactionDetail transactionDetail; lock (_transactions) { if (!_transactions.TryGetValue(transaction, out transactionDetail)) { transactionDetail = new TransactionDetail { PendingUpdates = new List <PageUpdate>() }; _transactions.Add(transaction, transactionDetail); } } lock (transactionDetail) transactionDetail.PendingUpdates.Add(update); return(true); }
public PageView UpdatePage(PageUpdate update) { using (var response = Post($"{_service}UpdatePage", update)) { ValidateResponse(response); return(Read <PageView>(response)); } }
List <PageUpdate> ILogFile.GetUpdates(ulong offset) { if (offset == 0UL) { offset = 4UL; } var header = new byte[4 + 8 + 1 + 4]; lock (_lock) { _fileStream.Seek((long)offset, SeekOrigin.Begin); if (_fileStream.Read(header, 0, header.Length) != header.Length) { throw new FileLayerException("Failed to read updates from " + _fileStream.Name + " log file, " + "the supplied offset " + offset + " is beyond the end of the log file"); } var count = BitConverter.ToUInt32(header, 13); var pageUpdates = new List <PageUpdate>(); var updateHead = new byte[20]; for (var i = 0; i < count; i++) { if (_fileStream.Read(updateHead, 0, updateHead.Length) != updateHead.Length) { throw new FileLayerException("Failed to read update head " + i + " from " + _fileStream.Name + " log file, " + "the log entry at offset " + offset + " extends beyond the end of the log file"); } var pageUpdate = new PageUpdate { SequenceNumber = BitConverter.ToUInt32(updateHead, 0), PageNumber = BitConverter.ToUInt64(updateHead, 4), Offset = BitConverter.ToUInt32(updateHead, 12), Data = new byte[BitConverter.ToUInt32(updateHead, 16)] }; if (_fileStream.Read(pageUpdate.Data, 0, pageUpdate.Data.Length) != pageUpdate.Data.Length) { throw new FileLayerException("Failed to read update data " + i + " from " + _fileStream.Name + " log file, " + "the log entry at offset " + offset + " extends beyond the end of the log file"); } pageUpdates.Add(pageUpdate); } return(pageUpdates); } }
public PageView UpdatePage(PageUpdate update) { if ((update.Type.HasFlag(PageUpdateType.Approve) || update.Type.HasFlag(PageUpdateType.Reject)) && _user != null && !_user.InRole("approver")) { throw new UnauthorizedAccessException("You do not have the permission to update this page."); } if ((update.Type.HasFlag(PageUpdateType.Publish) || update.Type.HasFlag(PageUpdateType.Unpublish)) && _user != null && !_user.InRole("publisher")) { throw new UnauthorizedAccessException("You do not have the permission to update this page."); } var pageVersion = GetCurrentPagesQuery().FirstOrDefault(x => x.PageId == update.Id); if (pageVersion == null) { throw new PageNotFoundException("Failed to find the page with that ID."); } if (update.Type.HasFlag(PageUpdateType.Pending)) { pageVersion.ApprovalStatus = ApprovalStatus.Pending; UpdatePageApprovedVersion(pageVersion.Page); } else if (update.Type.HasFlag(PageUpdateType.Approve)) { pageVersion.ApprovalStatus = ApprovalStatus.Approved; UpdatePageApprovedVersion(pageVersion.Page); } else if (update.Type.HasFlag(PageUpdateType.Reject)) { pageVersion.ApprovalStatus = ApprovalStatus.Rejected; UpdatePageApprovedVersion(pageVersion.Page); } if (update.Type.HasFlag(PageUpdateType.Publish)) { pageVersion.IsPublished = true; UpdatePageApprovedVersion(pageVersion.Page); } else if (update.Type.HasFlag(PageUpdateType.Unpublish)) { pageVersion.IsPublished = false; UpdatePageApprovedVersion(pageVersion.Page); } _database.SaveChanges(); return(pageVersion.ToView(Converter)); }
public JsonResult UpdatePage(string token, int pageId, [FromBody] PageUpdate value) { var page = _repo.GetPage(pageId); _auth.AuthenticateForWorkspace(token, page.WorkspaceId); _repo.UpdatePage(pageId, value); return(Json(new { success = true, // data = value })); }
public PageView UpdatePage(PageUpdate update) { return(_service.UpdatePage(update)); }