Exemplo n.º 1
0
        /// <summary>
        /// Creates the AuditLog.
        /// </summary>
        /// <param name="request">The request.</param>
        /// <returns></returns>
        public async Task <APIResponse> CreateAuditLog(CreateAuditLogRequest request)
        {
            try
            {
                var client = httpClientFactory.CreateClient(AuditLogServiceOperation.serviceName);

                var         param       = JsonConvert.SerializeObject(request);
                HttpContent contentPost = new StringContent(param, Encoding.UTF8, "application/json");

                var response = await client.PostAsync(servicesConfig.AuditLog + AuditLogServiceOperation.CreateAuditLog(), contentPost);

                if (response.IsSuccessStatusCode)
                {
                    var auditLog = JsonConvert.DeserializeObject <AuditLogResponse>(await response.Content.ReadAsStringAsync());
                    return(new APIResponse(auditLog, HttpStatusCode.Created));
                }

                return(new APIResponse(response.StatusCode));
            }
            catch (Exception ex)
            {
                logger.Error(ex, "Exception in method 'CreateAuditLog()'");
                var exMessage = ex.InnerException != null ? ex.InnerException.Message : ex.Message;
                return(new APIResponse(exMessage, HttpStatusCode.InternalServerError));
            }
        }