Exemplo n.º 1
0
        public async Task <int> UpdateAsync(IUser registrar, CancellationToken token = default(CancellationToken))
        {
            if (IsDeleted)
            {
                throw new IdentityException("Identity has been deleted");
            }
            if (registrar == null)
            {
                throw new ArgumentException("Registrar should be a valid member");
            }
            string updateURL = "";

            try
            {
                updateURL = client.GetURL(HFCA_IDENTITY + "/" + EnrollmentId);
                logger.Debug($"identity  url: {updateURL}, registrar: {registrar.Name}");
                string  body   = client.ToJson(IdToJsonObject());
                JObject result = await client.HttpPutAsync(updateURL, body, registrar, token).ConfigureAwait(false);

                statusCode = result["statusCode"]?.Value <int>() ?? 500;
                if (statusCode < 400)
                {
                    GetHFCAIdentity(result);
                    logger.Debug($"identity  url: {updateURL}, registrar: {registrar} done.");
                }

                return(statusCode);
            }
            catch (HTTPException e)
            {
                string            msg = $"[Code: {e.StatusCode}] - Error while updating user '{EnrollmentId}' from url '{updateURL}': {e.Message}";
                IdentityException identityException = new IdentityException(msg, e);
                logger.Error(msg);
                throw identityException;
            }
            catch (Exception e)
            {
                string            msg = $"Error while updating user '{EnrollmentId}' from url '{updateURL}':  {e.Message}";
                IdentityException identityException = new IdentityException(msg, e);
                logger.Error(msg);
                throw identityException;
            }
        }