public async Task <HFCAAffiliationResp> UpdateAsync(IUser registrar, bool force, CancellationToken token = default(CancellationToken)) { if (deleted) { throw new AffiliationException("Affiliation has been deleted"); } if (registrar == null) { throw new ArgumentException("Registrar should be a valid member"); } if (string.IsNullOrEmpty(Name)) { throw new ArgumentException("Affiliation name cannot be null or empty"); } string updateURL = ""; try { Dictionary <string, string> queryParm = new Dictionary <string, string>(); queryParm.Add("force", force.ToString()); updateURL = client.GetURL(HFCA_AFFILIATION + "/" + Name, queryParm); logger.Debug($"affiliation url: {updateURL}, registrar: {registrar.Name}"); string body = client.ToJson(AffToJsonObject()); JObject result = await client.HttpPutAsync(updateURL, body, registrar, token).ConfigureAwait(false); GenerateResponse(result); logger.Debug($"identity url: {updateURL}, registrar: {registrar.Name} done."); HFCAAffiliationResp resp = GetResponse(result); childHFCAAffiliations = resp.Children; identities = resp.Identities; return(GetResponse(result)); } catch (HTTPException e) { string msg = $"[Code: {e.StatusCode}] - Error while updating affiliation '{Name}' from url '{updateURL}': {e.Message}"; AffiliationException affiliationException = new AffiliationException(msg, e); logger.Error(msg); throw affiliationException; } catch (Exception e) { string msg = $"Error while updating affiliation {Name} url: {updateURL} {e.Message}"; AffiliationException affiliationException = new AffiliationException(msg, e); logger.Error(msg); throw affiliationException; } }
public async Task <int> ReadAsync(IUser registrar, CancellationToken token = default(CancellationToken)) { if (registrar == null) { throw new ArgumentException("Registrar should be a valid member"); } string readAffURL = ""; try { readAffURL = HFCA_AFFILIATION + "/" + Name; logger.Debug($"affiliation url: {readAffURL}, registrar: {registrar.Name}"); JObject result = await client.HttpGetAsync(readAffURL, registrar, token).ConfigureAwait(false); logger.Debug($"affiliation url: {readAffURL}, registrar: {registrar} done."); HFCAAffiliationResp resp = GetResponse(result); childHFCAAffiliations = resp.Children; identities = resp.Identities; deleted = false; return(resp.StatusCode); } catch (HTTPException e) { string msg = $"[Code: {e.StatusCode}] - Error while getting affiliation '{Name}' from url '{readAffURL}': {e.Message}"; AffiliationException affiliationException = new AffiliationException(msg, e); logger.Error(msg); throw affiliationException; } catch (Exception e) { string msg = $"Error while getting affiliation {Name} url: {readAffURL} {e.Message}"; AffiliationException affiliationException = new AffiliationException(msg, e); logger.Error(msg); throw affiliationException; } }