Exemplo n.º 1
0
        public async Task <ActionResult> Delete(Guid productId, Guid productOptionId)
        {
            try
            {
                await _productOptionService.DeleteAsync(productId, productOptionId);

                return(Ok());
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.Message));
            }
        }
        public async Task <IActionResult> DeleteProductOption(Guid id)
        {
            try
            {
                _logger.LogDebug($"Received {nameof(DeleteProductOption)} request with Id {id}");
                await _service.DeleteAsync(id);

                _logger.LogDebug($"Returned {nameof(DeleteProductOption)} response with Id {id}");
                return(Accepted());
            }
            catch (ProductOptionNotFoundException exception)
            {
                _logger.LogWarning(exception, exception.Message);
                return(NotFound(exception.Message));
            }
        }
Exemplo n.º 3
0
        public async Task <IActionResult> DeleteOption(Guid id)
        {
            try
            {
                await _productOptionService.GetProductOptionAsync(id);

                await _productOptionService.DeleteAsync(id);

                return(NoContent());
            }
            catch (RecordNotFoundException e)
            {
                Log.Error(e, ExceptionTemplates.RecordNotFoundError);
                return(NotFound(e.Message));
            }
            catch (Exception e)
            {
                Log.Error(e, ExceptionTemplates.UnknownError);
                return(StatusCode(500));
            }
        }
Exemplo n.º 4
0
        public async Task <IActionResult> DeleteAsync(Guid productId, Guid productOptionId)
        {
            _logger.Information($"Executing DELETE - '/products/{productId}/options/{productOptionId}'");

            if (!ModelState.IsValid)
            {
                return(WebApi.Response.Error(new Error(ErrorCode.BadRequest, AppConstants.InvalidRequest)));
            }

            try
            {
                var result = await _productOptionService.DeleteAsync(productId, productOptionId);

                return(result.IsSuccess()
                        ? WebApi.Response.NoContent()
                        : WebApi.Response.Error(result.Error));
            }
            catch (Exception ex)
            {
                _logger.Error("An error has occurred while deleting a product option. ProductId: {productId}, ProductOptionId: {productOptionId}, Details: {message}", productId, productOptionId, ex.Message);
            }

            return(WebApi.Response.Fatal());
        }