コード例 #1
0
        public override async Task OnActionExecutionAsync(ActionExecutingContext context, ActionExecutionDelegate next)
        {
            var _roomRepository = context.HttpContext.RequestServices.GetService <IRoomRepository>();

            var descriptor = context.ActionDescriptor as ControllerActionDescriptor;

            if (descriptor != null)
            {
                var parameters = descriptor.MethodInfo.GetParameters();

                foreach (var parameter in parameters)
                {
                    if (parameter.ParameterType != typeof(CommonAPI_RoomIdDTO) && parameter.ParameterType != typeof(CommonAPI_RoomDomainDTO))
                    {
                        continue;
                    }

                    var argument = context.ActionArguments[parameter.Name];

                    var errorCode = await EvaluateValidationAttributes(argument, context.HttpContext, _roomRepository, parameter.ParameterType);

                    if (errorCode != OperationErrorMessages.NoError)
                    {
                        context.Result = ResultResponceExtension.ObjectResultResponse <object>(errorCode);
                    }
                }
            }

            await base.OnActionExecutionAsync(context, next);
        }
コード例 #2
0
        public override async Task OnActionExecutionAsync(ActionExecutingContext context, ActionExecutionDelegate next)
        {
            var descriptor = context.ActionDescriptor as ControllerActionDescriptor;

            if (descriptor != null)
            {
                var parameters = descriptor.MethodInfo.GetParameters();

                foreach (var parameter in parameters)
                {
                    if (parameter.ParameterType.GetInterfaces().Contains(typeof(IInternalAPI_PostDTO)))
                    {
                        var config = context.HttpContext.RequestServices.GetService <IOptions <InternalApiConfig> >();

                        var requestAccessKey = ((IInternalAPI_PostDTO)context.ActionArguments[parameter.Name]).AccessKey;
                        var correctAccessKey = config.Value.AccessKey;
                        if (requestAccessKey != correctAccessKey)
                        {
                            context.Result = ResultResponceExtension.ObjectResultResponse <object>(
                                OperationErrorMessages.InternalApiWrongAccessKey);

                            break;
                        }
                    }
                }
            }

            await base.OnActionExecutionAsync(context, next);
        }
コード例 #3
0
        public override async Task OnActionExecutionAsync(ActionExecutingContext context, ActionExecutionDelegate next)
        {
            if (!context.ModelState.IsValid)
            {
                context.Result = ResultResponceExtension.ObjectResultResponse(OperationErrorMessages.InvalidModel, context.ModelState);
            }

            await base.OnActionExecutionAsync(context, next);
        }
コード例 #4
0
        public override async Task OnActionExecutionAsync(ActionExecutingContext context, ActionExecutionDelegate next)
        {
            var _workContext      = context.HttpContext.RequestServices.GetService <IWorkContext>();
            var _memberRepository = context.HttpContext.RequestServices.GetService <IMemberRepository>();
            var member            = await _memberRepository.GetMemberById(_workContext.MemberId.Value);

            if (!member.IsApproved)
            {
                context.Result = ResultResponceExtension.ObjectResultResponse <object>(OperationErrorMessages.MemberIsNotApproved);
            }

            await base.OnActionExecutionAsync(context, next);
        }
コード例 #5
0
        public override async Task OnActionExecutionAsync(ActionExecutingContext context, ActionExecutionDelegate next)
        {
            var _attemptRepository = context.HttpContext.RequestServices.GetService <IAttemptRepository>();

            var descriptor = context.ActionDescriptor as ControllerActionDescriptor;

            if (descriptor != null)
            {
                var errorCode = await EvaluateValidationAttributes(context.HttpContext, _attemptRepository);

                if (errorCode != OperationErrorMessages.NoError)
                {
                    context.Result = ResultResponceExtension.ObjectResultResponse <object>(errorCode);
                }
            }

            await base.OnActionExecutionAsync(context, next);
        }