Beispiel #1
0
        public async Task <ActionResult <SuccessResponse> > DeleteProduct([FromRoute] int id)
        {
            _logger.LogInformation("Calling DeleteProduct on the repository");
            var error = new ErrorResponse {
                RequestId = HttpContext?.TraceIdentifier ?? Guid.NewGuid().ToString()
            };

            try
            {
                if (ModelState.IsValid)
                {
                    _evalRepository.DeleteProductAsync(id);
                    return(Ok());
                }
            }
            catch (Exception e)
            {
                error.Errors.Add(ErrorModel.FromApiErrorCode(ApiErrorCode.UnknownReason));
                _logger.LogError($"Fail to delete record {e.Message}", e);
                return(StatusCode((int)HttpStatusCode.InternalServerError, error));
            }

            return(BadRequest());
        }