public async Task <(bool, string)> Amend(RentContractDataViewModel newContractVM) { //newData = new NewDataModel //{ // durationDays = aContract.durationDays + 10, // expiryDate = aContract.expiryDate.AddDays(10), // status = RentContractStatus.SIGNED, // content = "The content of the contract has been amended again." //} var newContract = ContractVMToApiModel(newContractVM); var originalContract = await GetByIdAsync(newContract.ID); var aTxAmendContract = new TxAmendContractModel { contract = originalContract, newData = new NewDataModel { ID = newContract.ID, expiryDate = newContract.expiryDate, durationDays = newContract.durationDays, status = newContract.status, content = newContract.content, } }; (var success, var message) = await bcContractTx.Create(aTxAmendContract); return(success, message); }
public async Task <(bool, string)> Create(TxAmendContractModel amendData) { var success = true; var errorMsg = string.Empty; try { var jsonContent = ReturnApiJsonForInsert(amendData); var response = await SendRequestAsync <TxAmendContractModelResponse>(RequestType.Post, ApiUrl, jsonContent); LogHelper.Info(Logger, $"{nameof(Create)} - success: {response.Success} - message: {response.Message}"); if (!response.Success) { throw new Exception(response.Message); } } catch (Exception ex) { LogHelper.Exception(Logger, $"{nameof(Create)} Exception", ex); errorMsg = ex.Message; success = false; } return(success, errorMsg); }
private string ReturnApiJsonForInsert(TxAmendContractModel amendData) { /* * { * "$class": "org.example.basic.UpdateContract", * "contract": "resource:org.example.basic.RentContract#8eddbcb9-879f-427d-bca2-0e63ff2f22dd", * "newData": { * "$class": "org.example.basic.UpdateContractData", * "expiryDate": "2019-11-01T08:57:34.9228348+01:00", * "durationDays": 305, * "status": "SIGNED", * "content": "The content of the contract has been amended." * } * } */ var jsonObj = (new[] { amendData }).Select(x => { var xObj = new Newtonsoft.Json.Linq.JObject( new Newtonsoft.Json.Linq.JProperty("$class", GetFullClass(x._Class)), new Newtonsoft.Json.Linq.JProperty("contract", $"resource:{GetFullResource(x.contract._Class, x.contract.ID)}"), new Newtonsoft.Json.Linq.JProperty("newData", new Newtonsoft.Json.Linq.JObject( new Newtonsoft.Json.Linq.JProperty("$class", GetFullClass(x.newData._Class)), new Newtonsoft.Json.Linq.JProperty("expiryDate", x.newData.expiryDate.ToString("o")), new Newtonsoft.Json.Linq.JProperty("durationDays", x.newData.durationDays), new Newtonsoft.Json.Linq.JProperty("status", x.newData.status.ToString()), new Newtonsoft.Json.Linq.JProperty("content", x.newData.content) )) ); return(xObj); }).First(); string json = JsonConvert.SerializeObject(jsonObj, Formatting.Indented); return(json); }