コード例 #1
0
        public async Task <IActionResult> CreateOrUpdateBusinessPartner([FromBody] DopplerUserDto dopplerUser)
        {
            _logger.LogInformation($"Received user: {dopplerUser.Email}");
            _logger.LogInformation($"Json request: {JsonConvert.SerializeObject(dopplerUser)}");

            try
            {
                await _businessPartnerService.CreateOrUpdateBusinessPartner(dopplerUser);

                return(new OkObjectResult("Successfully"));
            }
            catch (ValidationException e)
            {
                var messageError = $"Failed at creating/updating user: {dopplerUser.Id}. Because the user has a validation error: {e.Message}";
                _logger.LogError(e, messageError);
                await _slackService.SendNotification(messageError);

                return(new BadRequestObjectResult(e.Message));
            }
            catch (Exception e)
            {
                var messageError = $"Failed at creating/updating user: {dopplerUser.Id}, Object sent: {JsonConvert.SerializeObject(dopplerUser)} ";
                _logger.LogError(e, messageError);
                await _slackService.SendNotification(messageError);

                return(new ObjectResult(new
                {
                    StatusCode = 400,
                    ErrorMessage = $"Failed at creating/updating user: {dopplerUser.Id}",
                    ExceptionLogged = e
                }));
            }
        }