Exemplo n.º 1
0
        public async Task OnActionExecutionAsync(ActionExecutingContext context, ActionExecutionDelegate next)
        {
            if (!context.ModelState.IsValid)
            {
                BasicApiResponse responseObj =
                    new BasicApiResponse(false,
                                         context.ModelState.Values.SelectMany(v => v.Errors.Select(e => new ErrorMessage()
                {
                    Code = ApiErrorCode.Validation, Message = e.ErrorMessage
                })).ToArray());
                context.Result = new JsonResult(responseObj);
                return;
            }

            await next();
        }
Exemplo n.º 2
0
        public HttpResponseMessage Delete(string id)
        {
            BasicApiResponse response = new BasicApiResponse();

            try
            {
                this.CustomerService.DeleteCustomer(id);

                response.Message = ResponseMessages.DeleteCustomerOk;
            }
            catch (Exception ex)
            {
                response.Message = ex.Message;
                return(this.Request.CreateResponse(HttpStatusCode.InternalServerError, response));
            }

            return(this.Request.CreateResponse(HttpStatusCode.OK, response));
        }