|
@ -1,5 +1,6 @@ |
|
|
using FluentValidation; |
|
|
using FluentValidation; |
|
|
using Microsoft.eShopOnContainers.Services.Ordering.API.Application.Commands; |
|
|
using Microsoft.eShopOnContainers.Services.Ordering.API.Application.Commands; |
|
|
|
|
|
using Microsoft.Extensions.Logging; |
|
|
using System; |
|
|
using System; |
|
|
using System.Collections.Generic; |
|
|
using System.Collections.Generic; |
|
|
using System.Linq; |
|
|
using System.Linq; |
|
@ -9,19 +10,21 @@ namespace Ordering.API.Application.Validations |
|
|
{ |
|
|
{ |
|
|
public class CreateOrderCommandValidator : AbstractValidator<CreateOrderCommand> |
|
|
public class CreateOrderCommandValidator : AbstractValidator<CreateOrderCommand> |
|
|
{ |
|
|
{ |
|
|
public CreateOrderCommandValidator() |
|
|
|
|
|
|
|
|
public CreateOrderCommandValidator(ILogger<CreateOrderCommandValidator> logger) |
|
|
{ |
|
|
{ |
|
|
RuleFor(command => command.City).NotEmpty(); |
|
|
RuleFor(command => command.City).NotEmpty(); |
|
|
RuleFor(command => command.Street).NotEmpty(); |
|
|
RuleFor(command => command.Street).NotEmpty(); |
|
|
RuleFor(command => command.State).NotEmpty(); |
|
|
RuleFor(command => command.State).NotEmpty(); |
|
|
RuleFor(command => command.Country).NotEmpty(); |
|
|
RuleFor(command => command.Country).NotEmpty(); |
|
|
RuleFor(command => command.ZipCode).NotEmpty(); |
|
|
RuleFor(command => command.ZipCode).NotEmpty(); |
|
|
RuleFor(command => command.CardNumber).NotEmpty().Length(12, 19); |
|
|
|
|
|
|
|
|
RuleFor(command => command.CardNumber).NotEmpty().Length(12, 19); |
|
|
RuleFor(command => command.CardHolderName).NotEmpty(); |
|
|
RuleFor(command => command.CardHolderName).NotEmpty(); |
|
|
RuleFor(command => command.CardExpiration).NotEmpty().Must(BeValidExpirationDate).WithMessage("Please specify a valid card expiration date"); |
|
|
|
|
|
RuleFor(command => command.CardSecurityNumber).NotEmpty().Length(3); |
|
|
|
|
|
|
|
|
RuleFor(command => command.CardExpiration).NotEmpty().Must(BeValidExpirationDate).WithMessage("Please specify a valid card expiration date"); |
|
|
|
|
|
RuleFor(command => command.CardSecurityNumber).NotEmpty().Length(3); |
|
|
RuleFor(command => command.CardTypeId).NotEmpty(); |
|
|
RuleFor(command => command.CardTypeId).NotEmpty(); |
|
|
RuleFor(command => command.OrderItems).Must(ContainOrderItems).WithMessage("No order items found"); |
|
|
|
|
|
|
|
|
RuleFor(command => command.OrderItems).Must(ContainOrderItems).WithMessage("No order items found"); |
|
|
|
|
|
|
|
|
|
|
|
logger.LogTrace("----- INSTANCE CREATED - {ClassName}", GetType().Name); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
private bool BeValidExpirationDate(DateTime dateTime) |
|
|
private bool BeValidExpirationDate(DateTime dateTime) |
|
@ -34,4 +37,4 @@ namespace Ordering.API.Application.Validations |
|
|
return orderItems.Any(); |
|
|
return orderItems.Any(); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
} |