コード例 #1
0
        internal static async Task <HaeAsiakkaatResponse> Post(HttpClient client, HaeAsiakkaatRequest initiatedRequest)
        {
            var response = await client.PostAsJsonAsync("api/asti/haeasiakkaita", initiatedRequest);

            try
            {
                var json = await response.Content.ReadAsStringAsync();

                if (!response.IsSuccessStatusCode)
                {
                    throw new HttpRequestException((int)response.StatusCode + " HttpRequestException, Content: " + json);
                }

                // Check first just the state code
                HandleResponseStateCode(JObject.Parse(json).SelectToken("tilaKoodi").ToObject <ResponseStateCode>());

                return(JsonConvert.DeserializeObject <HaeAsiakkaatResponse>(
                           json,
                           new JsonSerializerSettings {
                    MissingMemberHandling = MissingMemberHandling.Error
                }));
            }
            // Any JsonExceptions mean that the API has changed, and client needs update
            catch (JsonException e)
            {
                throw new ClientFaultException(e);
            }
        }
コード例 #2
0
        /// <summary>
        /// Async call to check if person has an account in suomi.fi/viestit -service.
        /// Throws ClientFaultException in case of this Client working improperly.
        /// Throws custom Keha.SuomiFiViestitHub.Client.Exceptions on returned error codes.
        /// </summary>
        /// <returns>Returns true if Customer has a Viestit-account and it is active.</returns>
        public async Task <bool> CustomerHasAccount(string socialSecurityNumber)
        {
            var req = new HaeAsiakkaatRequest
            {
                CustomerIds = new List <string>(new[] { socialSecurityNumber })
            };

            InitRequest(req);

            var data = await HubApi.CustomerHasViestitAccount.Post(_client, req);

            return(data.CustomerStates[0].CustomerStateCode == CustomerStateCode.HasAccount && !data.CustomerStates[0].AccountPassive);
        }