Пример #1
0
        public override async Task <IActionResult> ExecuteAsync(SchoolInDto dto, School entity)
        {
            if (entity.YearOfEstablishment != null && entity.YearOfEstablishment < 1700)
            {
                return(new BadRequestObjectResult(_responseBuilder.AddError(_localizer["YearOfEstablishmentError"]).Build()));
            }

            return(await base.ExecuteAsync(dto, entity));
        }
Пример #2
0
        public void OnActionExecuting(ActionExecutingContext context)
        {
            var dto = context.ActionArguments.ContainsKey(DtoVariableName) ? context.ActionArguments[DtoVariableName] : null;

            if (dto == null)
            {
                context.Result = new ApiUnprocessableEntityResult(_responseBuilder.AddError(ApiResources.ModelDataMissing).Build());
            }
            else if (!context.ModelState.IsValid)
            {
                _modelStateResolver.GetModelErrors(context.ModelState).ForEach(error => _responseBuilder.AddError(error.Message, error.Field));
                context.Result = new ApiUnprocessableEntityResult(_responseBuilder.Build());
            }
        }
        public void OnActionExecuting(ActionExecutingContext context)
        {
            var queryString = context.ActionArguments["queryString"] as QueryString;

            if (queryString.ValidateQueryString)
            {
                queryString.Errors.ForEach(error => _responseBuilder.AddError(
                                               string.Format(ApiResources.ResourceManager.GetString(error.Type.ToString()), error.ParameterName), error.Info));

                if (_responseBuilder.HasErrors())
                {
                    context.Result = new InvalidQueryStringResult(_responseBuilder.Build());
                }
            }
        }