Esempio n. 1
0
        public async Task <IActionResult> Put(string id, WebHook webHook)
        {
            if (webHook == null)
            {
                return(BadRequest());
            }
            if (!string.Equals(id, webHook.Id, StringComparison.OrdinalIgnoreCase))
            {
                return(BadRequest());
            }

            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            try
            {
                // Validate parts of WebHook
                await _registrationsManager.VerifySecretAsync(webHook);

                await _registrationsManager.VerifyFiltersAsync(webHook);

                await _registrationsManager.VerifyAddressAsync(webHook);
            }
            catch (Exception ex)
            {
                var message = $"Could not register WebHook due to error: {ex.Message}";
                _logger.LogInformation(ex.Message, ex);
                return(BadRequest(message));
            }

            try
            {
                // Update WebHook for this user
                var result = await _registrationsManager.UpdateWebHookAsync(User, webHook, AddPrivateFilters);

                return(CreateHttpResult(result));
            }
            catch (Exception ex)
            {
                var message = $"Could not register WebHook due to error: {ex.Message}";
                _logger.LogInformation(ex.Message, ex);
                return(StatusCode((int)HttpStatusCode.InternalServerError, message));
            }
        }
Esempio n. 2
0
        //[ValidateModel]
        public async Task <IHttpActionResult> Put(string id, WebHook webHook)
        {
            if (webHook == null)
            {
                return(BadRequest());
            }
            if (!string.Equals(id, webHook.Id, StringComparison.OrdinalIgnoreCase))
            {
                return(BadRequest());
            }

            try
            {
                // Validate parts of WebHook
                await _registrationsManager.VerifySecretAsync(webHook);

                await _registrationsManager.VerifyFiltersAsync(webHook);

                await _registrationsManager.VerifyAddressAsync(webHook);
            }
            catch (Exception ex)
            {
                string msg = string.Format(CultureInfo.CurrentCulture, BaladorResource.RegistrationController_RegistrationFailure, ex.Message);
                Configuration.DependencyResolver.GetLogger().Info(msg);
                HttpResponseMessage error = Request.CreateErrorResponse(HttpStatusCode.BadRequest, msg, ex);
                return(ResponseMessage(error));
            }

            try
            {
                // Update WebHook for this user
                StoreResult result = await _registrationsManager.UpdateWebHookAsync(User, webHook, AddPrivateFilters);

                return(CreateHttpResult(result));
            }
            catch (Exception ex)
            {
                string msg = string.Format(CultureInfo.CurrentCulture, BaladorResource.RegistrationController_UpdateFailure, ex.Message);
                Configuration.DependencyResolver.GetLogger().Error(msg, ex);
                HttpResponseMessage error = Request.CreateErrorResponse(HttpStatusCode.InternalServerError, msg, ex);
                return(ResponseMessage(error));
            }
        }
        public async Task <IActionResult> Put(string id, [FromBody] WebHook webHook)
        {
            if (webHook == null)
            {
                return(BadRequest());
            }
            if (!string.Equals(id, webHook.Id, StringComparison.OrdinalIgnoreCase))
            {
                return(BadRequest());
            }

            InitializeCollections(webHook);

            try
            {
                // Validate parts of WebHook
                await _registrationsManager.VerifySecretAsync(webHook);

                await _registrationsManager.VerifyFiltersAsync(webHook);

                await _registrationsManager.VerifyAddressAsync(webHook);
            }
            catch (Exception ex)
            {
                var message = string.Format(CultureInfo.CurrentCulture, CustomApiResources.RegistrationController_RegistrationFailure, ex.Message);
                _logger.LogInformation(message, ex);
                return(BadRequest(message));
            }

            try
            {
                // Update WebHook for this user
                var result = await _registrationsManager.UpdateWebHookAsync(User, webHook, AddPrivateFilters);

                return(CreateHttpResult(result));
            }
            catch (Exception ex)
            {
                var message = string.Format(CultureInfo.CurrentCulture, CustomApiResources.RegistrationController_UpdateFailure, ex.Message);
                _logger.LogError(message, ex);
                throw;
            }
        }