public async Task<bool> Put (ID7NodeRevision nodeRevision, CancellationToken tkn) { if (!IsLoggedIn) throw Error.BadAct($"‹{this.GetType().Name}› is not logged in."); if (nodeRevision.vid < 1) return Error_n("Invalid node revision format.", "Revision ID (vid) must be set."); var req = _auth.Req.PUT(URL.Api_EntityNodeX, nodeRevision.nid); nodeRevision.uid = this.CurrentUser.uid; req.Body = nodeRevision; //Debug_n($"Updating node [nid:{nodeRevision.nid}]...", ""); IResponseShim resp = null; try { resp = await _client.Send(req, tkn); } catch (RestServiceException ex) { OnNodeEdit.Err(this, ex); } catch (Exception ex) { OnUnhandled.Err(this, ex); } if (resp == null) return Error_n("Failed to update node.", "Response is NULL"); if (!resp.IsSuccess) return Error_n("Failed to update node.", resp.Message); //return Debug_n("Node successfully updated.", ""); return true; }
public async Task<T> Put<T>(T nodeRevision, CancellationToken cancelToken, string taskTitle = null, string successMessage = null, params Func<T, object>[] successMsgArgs) where T : ID7NodeRevision { if (!IsLoggedIn) throw Error.BadAct($"‹{this.GetType().Name}› is not logged in."); Trace_n(taskTitle.IsBlank() ? "Updating existing node on server..." : taskTitle, ""); string m; T d7n = default(T); if (nodeRevision.vid < 1) return Error_(d7n, "Invalid node revision format.", "Revision ID (vid) must be set."); var req = _auth.Req.PUT(URL.Api_EntityNodeX, nodeRevision.nid); nodeRevision.uid = this.CurrentUser.uid; req.Body = nodeRevision; try { d7n = await _client.Send<T>(req, cancelToken, "", successMessage, successMsgArgs); } catch (RestServiceException ex) { OnNodeEdit.Err(this, ex); } catch (Exception ex) { OnUnhandled.Err(this, ex); } if (d7n.IsValidNode(out m)) //return Trace_(d7n, "Node successfully updated.", "[nid: {0}] {1} title: {2}", d7n.nid, d7n.type.Guillemet(), d7n.title.Quotify()); return d7n; else return Error_(d7n, "Invalid node.", m); }