Пример #1
0
        protected override async Task <ValidationBag> Validate(UpdateCustomerRequest request, CancellationToken cancellationToken)
        {
            var bag = new ValidationBag();

            var customer = await _financialContext.Customers.FindAsync(request.Customer.Id);

            if (customer == null)
            {
                bag.AddError(ValidationErrorCode.CustomerNotFound, new { request.Customer.Id });
            }

            if (request.Customer.Name.Length > 250)
            {
                bag.AddError(ValidationErrorCode.InvalidMaxNameLength, new { request.Customer.Name });
            }
            if (request.Customer.Surname.Length > 250)
            {
                bag.AddError(ValidationErrorCode.InvalidMaxSurnameLength, new { request.Customer.Surname });
            }
            if (string.IsNullOrWhiteSpace(request.Customer.Name))
            {
                bag.AddError(ValidationErrorCode.InvalidMinNameLength, new { request.Customer.Name });
            }
            if (string.IsNullOrWhiteSpace(request.Customer.Surname))
            {
                bag.AddError(ValidationErrorCode.InvalidMinSurnameLength, new { request.Customer.Surname });
            }


            return(bag);
        }
Пример #2
0
        protected override async Task <ValidationBag> Validate(AddUserRequest request, CancellationToken cancellationToken)
        {
            var bag = new ValidationBag();

            if (string.IsNullOrEmpty(request.Name))
            {
                bag.AddError(ValidationErrorCode.InvalidName);
            }

            if (string.IsNullOrEmpty(request.Email))
            {
                bag.AddError(ValidationErrorCode.InvalidEmail);
            }

            return(bag);
        }
        protected override async Task <ValidationBag> Validate(AddAccountRequest request, CancellationToken cancellationToken)
        {
            var bag = new ValidationBag();

            if (!await _financialContext.Customers.AnyAsync(_ => _.Id == request.CustomerId, cancellationToken))
            {
                bag.AddError(ValidationErrorCode.CustomerNotFound);
            }

            if (decimal.Compare(request.InitialCredit, 0) < 0)
            {
                bag.AddError(ValidationErrorCode.InvalidUnderZeroInitialCredit, new { request.InitialCredit });
            }

            return(bag);
        }
        protected override async Task <ValidationBag> Validate(GetCustomerRequest request, CancellationToken cancellationToken)
        {
            var bag = new ValidationBag();

            if (!await _financialContext.Customers.AnyAsync(_ => _.Id == request.CustomerId, cancellationToken))
            {
                bag.AddError(ValidationErrorCode.CustomerNotFound);
            }

            return(bag);
        }
Пример #5
0
        protected override async Task <ValidationBag> Validate(GetUserByIdRequest request, CancellationToken cancellationToken)
        {
            var bag = new ValidationBag();

            var user = await _userRepository.Single(_ => _.Id == request.Id);

            if (user == null)
            {
                bag.AddError(ValidationErrorCode.UserDoesNotExist, $"There is no user for id {request.Id}.");
            }

            return(bag);
        }
Пример #6
0
        protected override async Task <ValidationBag> Validate(AddCustomerRequest request, CancellationToken cancellationToken)
        {
            var bag = new ValidationBag();

            if (request.Customer.Name.Length > 250)
            {
                bag.AddError(ValidationErrorCode.InvalidMaxNameLength, new { request.Customer.Name });
            }
            if (request.Customer.Surname.Length > 250)
            {
                bag.AddError(ValidationErrorCode.InvalidMaxSurnameLength, new { request.Customer.Surname });
            }
            if (string.IsNullOrWhiteSpace(request.Customer.Name))
            {
                bag.AddError(ValidationErrorCode.InvalidMinNameLength, new { request.Customer.Name });
            }
            if (string.IsNullOrWhiteSpace(request.Customer.Surname))
            {
                bag.AddError(ValidationErrorCode.InvalidMinSurnameLength, new { request.Customer.Surname });
            }

            return(bag);
        }