public SupplierUpdateCommandValidator(IGenericReadRepository readRepository, ISupplierFiltersProvider filtersProvider) : base(readRepository) { _filtersProvider = filtersProvider; RuleFor(x => x.Id) .NotEmptyWithMessage() .MustExistsWithMessageAsync(SupplierExists); RuleFor(x => x.CompanyName) .NotEmptyWithMessage() .MaxLengthWithMessage(SupplierConstraints.CompanyNameMaxLength); RuleFor(x => x.Ein) .NotEmptyWithMessage() .MaxLengthWithMessage(SupplierConstraints.EinMaxLength) .IsValidEinWithMessage() .MustNotExistWithMessageAsync(EinDoesNotExist); RuleFor(x => x.Phone) .NotEmptyWithMessage() .MaxLengthWithMessage(SupplierConstraints.PhoneMaxLength) .IsValidPhoneNumberWithMessage(); RuleFor(x => x.Email) .NotEmptyWithMessage() .MaxLengthWithMessage(SupplierConstraints.EmailMaxLength) .IsValidEmailWithMessage(); RuleFor(x => x.Address) .NotEmptyWithMessage() .MaxLengthWithMessage(SupplierConstraints.AddressMaxLength); }
public CarPhotoCreateCommandValidator(IGenericReadRepository readRepository, ICarModelFiltersProvider modelFiltersProvider, ICarBodyTypeFiltersProvider bodyTypeFiltersProvider, IColorCodeFiltersProvider colorFiltersProvider) : base(readRepository) { _modelFiltersProvider = modelFiltersProvider; _bodyTypeFiltersProvider = bodyTypeFiltersProvider; _colorFiltersProvider = colorFiltersProvider; RuleFor(x => x.ModelId) .NotEmptyWithMessage() .MustExistsWithMessageAsync(ModelExists); RuleFor(x => x.BodyTypeId) .NotEmptyWithMessage() .MustExistsWithMessageAsync(BodyTypeExists); RuleFor(x => x.ColorId) .NotEmptyWithMessage() .MustExistsWithMessageAsync(ColorExists); RuleFor(x => x.Photo) .NotEmptyWithMessage() .DependentRules(() => { RuleFor(x => x.Photo) .Cascade(CascadeMode.Continue) .MustAsync(FileSizeIsValid) .WithMessage($"File size should be up to {CarPhotoConstraints.FileMaxSize / 1000000.0f}MB") .MustAsync(FileTypeIsValid) .WithMessage($"File type is prohibited. Allowed types - {GetSupportedFileTypesString()}"); }); }
public DeliveryRequestPromoteCommandValidator(IGenericReadRepository readRepository, IDeliveryRequestFiltersProvider deliveryRequestFiltersProvider) : base(readRepository) { _deliveryRequestFiltersProvider = deliveryRequestFiltersProvider; RuleFor(x => x.DeliveryRequestId) .NotEmptyWithMessage() .MustExistsWithMessageAsync(DeliveryRequestExists) .CustomAsync(async(deliveryRequestId, context, cancellationToken) => { var query = await ReadRepository.GetQueryableAsync(deliveryRequestFiltersProvider.ById(deliveryRequestId)); var deliveryRequestStatus = (DeliveryRequestStatuses)query.Select(x => x.StatusId).FirstOrDefault(); string errorMessage; switch (deliveryRequestStatus) { case DeliveryRequestStatuses.Opened: errorMessage = "Delivery request is not assigned to the user."; break; case DeliveryRequestStatuses.Closed: errorMessage = "Delivery request is closed."; break; default: errorMessage = string.Empty; break; } if (!string.IsNullOrEmpty(errorMessage)) { context.AddFailure(nameof(DeliveryRequestAssignCommand.DeliveryRequestId), errorMessage); } }); }
public OrderPromoteCommandValidator(IGenericReadRepository readRepository, IOrderFiltersProvider orderFiltersProvider, IOrderRelationsProvider orderRelationsProvider) : base(readRepository) { _orderFiltersProvider = orderFiltersProvider; RuleFor(x => x.OrderId) .NotEmptyWithMessage() .MustExistsWithMessageAsync(OrderExists) .CustomAsync(async(orderId, context, cancellationToken) => { var query = await ReadRepository.GetQueryableAsync(_orderFiltersProvider.ById(orderId), orderRelationsProvider.JoinDeliveryRequest); var orderInfo = query .Select(x => new { OrderStatus = x.StatusId, DeliveryRequestStatus = x.DeliveryRequest != null ? x.DeliveryRequest.StatusId : (int?)null }) .FirstOrDefault(); if ((OrderStatuses)orderInfo.OrderStatus == OrderStatuses.Completed) { context.AddFailure(nameof(OrderPromoteCommand.OrderId), "Order is completed."); return; } if (orderInfo.DeliveryRequestStatus.HasValue && (DeliveryRequestStatuses)orderInfo.DeliveryRequestStatus != DeliveryRequestStatuses.Closed) { context.AddFailure(nameof(OrderPromoteCommand.OrderId), "You cannot promote the order until the corresponding delivery request is completed."); } }); }
public CarEngineCommandFunctionality(IUnitOfWork unitOfWork, IMapperFactory mapperFactory, IGenericWriteRepository writeRepository, IValidatorFactory validatorFactory, IGenericReadRepository readRepository, IEngineSupportsGearboxFiltersProvider engineGearboxFiltersProvider) : base(unitOfWork, mapperFactory, writeRepository, validatorFactory) { _readRepository = readRepository; _engineGearboxFiltersProvider = engineGearboxFiltersProvider; }
public ClientCreateCommandValidator(IGenericReadRepository readRepository, IClientFiltersProvider clientFiltersProvider) : base(readRepository) { _clientFiltersProvider = clientFiltersProvider; RuleFor(x => x.FirstName) .NotEmptyWithMessage() .MaxLengthWithMessage(ClientConstraints.FirstNameMaxLength); RuleFor(x => x.LastName) .NotEmptyWithMessage() .MaxLengthWithMessage(ClientConstraints.LastNameMaxLength); When(x => x.Email != null, () => { RuleFor(x => x.Email) .MaxLengthWithMessage(ClientConstraints.EmailMaxLength) .IsValidEmailWithMessage(); }); RuleFor(x => x.PassportId) .NotEmptyWithMessage() .MinLengthWithMessage(ClientConstraints.PassportIdMinLength) .MaxLengthWithMessage(ClientConstraints.PassportIdMaxLength) .MustNotExistWithMessageAsync(PassportIdDoesNotExist); RuleFor(x => x.Phone) .NotEmptyWithMessage() .MaxLengthWithMessage(ClientConstraints.PhoneMaxLength) .IsValidPhoneNumberWithMessage(); RuleFor(x => x.Address) .NotEmptyWithMessage() .MaxLengthWithMessage(ClientConstraints.AddressMaxLength); }
public UserUpdatePasswordCommandValidator(IGenericReadRepository readRepository, IUserFiltersProvider userFiltersProvider) : base(readRepository) { _userFiltersProvider = userFiltersProvider; RuleFor(x => x.UserId) .NotEmptyWithMessage() .MustExistsWithMessageAsync(UserExists) .DependentRules(() => { When(x => !string.IsNullOrWhiteSpace(x.OldPasswordHash), () => { RuleFor(x => x.OldPasswordHash) .MustAsync(OldPasswordIsValid) .WithMessage("Old password is invalid"); }); }); RuleFor(x => x.OldPasswordHash) .NotEmptyWithMessage(); RuleFor(x => x.NewPasswordHash) .NotEmptyWithMessage() .MaxLengthWithMessage(UserConstraints.PasswordHashLength) .IsValidMD5HashWithMessage(); }
public UserUpdateActiveStatusCommandValidator(IGenericReadRepository readRepository, IUserFiltersProvider userFiltersProvider) : base(readRepository) { _userFiltersProvider = userFiltersProvider; RuleFor(x => x.UserId) .NotEmptyWithMessage() .MustExistsWithMessageAsync(UserExists); }
public SupplierCommandFunctionality(IUnitOfWork unitOfWork, IMapperFactory mapperFactory, IGenericWriteRepository writeRepository, IValidatorFactory validatorFactory, IGenericReadRepository readRepository, IBrandFiltersProvider brandFiltersProvider, ISupplierPhotoFiltersProvider supplierPhotoFiltersProvider, IFileManager fileManager) : base(unitOfWork, mapperFactory, writeRepository, validatorFactory) { _readRepository = readRepository; _brandFiltersProvider = brandFiltersProvider; _supplierPhotoFiltersProvider = supplierPhotoFiltersProvider; _fileManager = fileManager; }
public BasicOrderRule(IGenericReadRepository <GasStation> gasStationRepo , IGenericReadRepository <Carrier> carrierRepo) { _dispatcherGroupRule = new DispatcherGroupRule(gasStationRepo); _carrierRule = new CarrierRule(); _carrierMaxGallonsRule = new CarrierMaxGallonsRule(carrierRepo); _carrierDeliveryTimeRule = new CarrierDeliveryTimeRule(carrierRepo); }
public WorkCreateCommandValidator(IGenericReadRepository readRepository) : base(readRepository) { RuleFor(x => x.Name) .NotEmptyWithMessage() .MaxLengthWithMessage(WorkConstraints.NameMaxLength); RuleFor(x => x.Price) .IsPositiveOrZeroWithMessage(); }
public CountryCreateCommandValidator(IGenericReadRepository readRepository, ICountryFiltersProvider filtersProvider) : base(readRepository) { _filtersProvider = filtersProvider; RuleFor(x => x.Name) .NotEmptyWithMessage() .MaxLengthWithMessage(CountryConstraints.NameMaxLength) .MustNotExistWithMessageAsync(NameDoesNotExist); }
public OrderFromStockCreateCommandValidator(IGenericReadRepository readRepository, IValidator <OrderWithDeliveryRequestCreateCommand> validator, ICarStockFiltersProvider carStockFiltersProvider) : base(readRepository) { _carStockFiltersProvider = carStockFiltersProvider; RuleFor(x => x) .SetValidator(validator) .MustAsync(CarAmountIsValid) .WithMessage("There are not enough cars in stock to create an order."); }
public CarStockCommandFunctionality(IUnitOfWork unitOfWork, IMapperFactory mapperFactory, IGenericWriteRepository writeRepository, IValidatorFactory validatorFactory, IFileManager fileManager, IGenericReadRepository readRepository, ICarPhotoFiltersProvider carPhotoFiltersProvider, ICarStockFiltersProvider carStockFiltersProvider, ICarStockCommandRepository carStockCommandRepository) : base(unitOfWork, mapperFactory, writeRepository, validatorFactory) { _fileManager = fileManager; _readRepository = readRepository; _carPhotoFiltersProvider = carPhotoFiltersProvider; _carStockFiltersProvider = carStockFiltersProvider; _carStockCommandRepository = carStockCommandRepository; }
public CarComplectationOptionsAssignCommandValidator(IGenericReadRepository readRepository, ICarComplectationFiltersProvider filtersProvider) : base(readRepository) { _filtersProvider = filtersProvider; RuleFor(x => x.ComplectationId) .NotEmptyWithMessage() .MustExistsWithMessageAsync(ComplectationExists); RuleForEach(x => x.Options) .NotEmptyWithMessage() .MaxLengthWithMessage(CarComplectationConstraints.NameMaxLength); }
public UserResetPasswordCommandValidator(IGenericReadRepository readRepository, IUserFiltersProvider userFiltersProvider) : base(readRepository) { _userFiltersProvider = userFiltersProvider; RuleFor(x => x.UserId) .NotEmptyWithMessage() .MustExistsWithMessageAsync(UserExists); RuleFor(x => x.NewPasswordHash) .NotEmptyWithMessage() .MaxLengthWithMessage(UserConstraints.PasswordHashLength) .IsValidMD5HashWithMessage(); }
public CarColorAssignmentCommandValidator(IGenericReadRepository readRepository, ICarModelFiltersProvider modelFiltersProvider, IColorCodeFiltersProvider colorFiltersProvider, IModelSupportsColorFiltersProvider modelColorFiltersProvider) : base(readRepository) { _modelFiltersProvider = modelFiltersProvider; _colorFiltersProvider = colorFiltersProvider; _modelColorFiltersProvider = modelColorFiltersProvider; RuleFor(x => x.ModelId) .NotEmptyWithMessage() .MustExistsWithMessageAsync(ModelExists); RuleFor(x => x.ColorId) .NotEmptyWithMessage() .MustExistsWithMessageAsync(ColorExists); }
public CarComplectationCreateCommandValidator(IGenericReadRepository readRepository, ICarModelFiltersProvider modelFiltersProvider) : base(readRepository) { _modelFiltersProvider = modelFiltersProvider; RuleFor(x => x.Name) .NotEmptyWithMessage() .MaxLengthWithMessage(CarComplectationConstraints.NameMaxLength); RuleFor(x => x.Price) .IsPositiveOrZeroWithMessage(); RuleFor(x => x.ModelId) .NotEmptyWithMessage() .MustExistsWithMessageAsync(ModelExists); }
public CarModelCreateCommandValidator(IGenericReadRepository readRepository, IBrandFiltersProvider brandFiltersProvider) : base(readRepository) { _brandFiltersProvider = brandFiltersProvider; RuleFor(x => x.Name) .NotEmptyWithMessage() .MaxLengthWithMessage(CarModelConstraints.NameMaxLength); RuleFor(x => x.Price) .IsPositiveWithMessage(); RuleFor(x => x.BrandId) .NotEmptyWithMessage() .MustExistsWithMessageAsync(BrandExists); }
public WorkOrderClientCreateCommandValidator(IGenericReadRepository readRepository) : base(readRepository) { RuleFor(x => x.FirstName) .NotEmptyWithMessage() .MaxLengthWithMessage(WorkOrderClientConstraints.FirstNameMaxLength); RuleFor(x => x.LastName) .NotEmptyWithMessage() .MaxLengthWithMessage(WorkOrderClientConstraints.LastNameMaxLength); RuleFor(x => x.Phone) .NotEmptyWithMessage() .MaxLengthWithMessage(WorkOrderClientConstraints.PhoneMaxLength) .IsValidPhoneNumberWithMessage(); }
public DeliveryRequestCreateCommandValidator(IGenericReadRepository readRepository, ICarStockFiltersProvider carStockFiltersProvider, IUserFiltersProvider userFiltersProvider) : base(readRepository) { _carStockFiltersProvider = carStockFiltersProvider; _userFiltersProvider = userFiltersProvider; RuleFor(x => x.CarId) .NotEmptyWithMessage() .MustExistsWithMessageAsync(CarExists); RuleFor(x => x.ManagerId) .NotEmptyWithMessage() .MustExistsWithMessageAsync(ManagerIsValid); RuleFor(x => x.Amount) .IsPositiveWithMessage(); }
public CarBodyTypeAssignCommandValidator(IGenericReadRepository readRepository, ICarModelFiltersProvider modelFiltersProvider, ICarBodyTypeFiltersProvider bodyTypeFiltersProvider, IModelSupportsBodyTypeFiltersProvider modelBodyTypeFiltersProvider) : base(readRepository) { _modelFiltersProvider = modelFiltersProvider; _bodyTypeFiltersProvider = bodyTypeFiltersProvider; _modelBodyTypeFiltersProvider = modelBodyTypeFiltersProvider; RuleFor(x => x.ModelId) .NotEmptyWithMessage() .MustExistsWithMessageAsync(ModelExists); RuleFor(x => x.BodyTypeId) .NotEmptyWithMessage() .MustExistsWithMessageAsync(BodyTypeExists); RuleFor(x => x.Price) .IsPositiveOrZeroWithMessage(); }
public CarStockUpdateCommandValidator(IGenericReadRepository readRepository, IModelSupportsBodyTypeFiltersProvider modelBodyTypeFiltersProvider, ICarModelFiltersProvider modelFiltersProvider, IModelSupportsColorFiltersProvider modelColorFiltersProvider, ICarComplectationFiltersProvider complectationFiltersProvider, IEngineSupportsGearboxFiltersProvider engineGearboxFiltersProvider, ICarStockFiltersProvider carStockFiltersProvider) : base(readRepository) { _modelBodyTypeFiltersProvider = modelBodyTypeFiltersProvider; _modelFiltersProvider = modelFiltersProvider; _modelColorFiltersProvider = modelColorFiltersProvider; _complectationFiltersProvider = complectationFiltersProvider; _engineGearboxFiltersProvider = engineGearboxFiltersProvider; _carStockFiltersProvider = carStockFiltersProvider; RuleFor(x => x.Id) .NotEmptyWithMessage() .MustExistsWithMessageAsync(CarExists); RuleFor(x => x.ModelId) .NotEmptyWithMessage() .MustExistsWithMessageAsync(ModelExists) .DependentRules(() => { RuleFor(x => x.BodyTypeId) .NotEmptyWithMessage() .MustAsync(BodyTypeIsValid) .WithMessage($"The {{PropertyName}} is not compatible with the provided model."); RuleFor(x => x.ColorId) .NotEmptyWithMessage() .MustAsync(ColorIsValid) .WithMessage($"The {{PropertyName}} is not compatible with the provided model."); RuleFor(x => x.EngineGearboxId) .NotEmptyWithMessage() .MustAsync(EngineGearboxIsValid) .WithMessage($"The {{PropertyName}} is not compatible with the provided model."); RuleFor(x => x.ComplectationId) .NotEmptyWithMessage() .MustAsync(ComplectationIsValid) .WithMessage($"The {{PropertyName}} is not compatible with the provided model."); }); RuleFor(x => x.Amount) .IsPositiveOrZeroWithMessage(); RuleFor(x => x.Price) .IsPositiveOrZeroWithMessage(); }
public CarEngineCreateCommandValidator(IGenericReadRepository readRepository, ICarEngineTypeFiltersProvider filtersProvider) : base(readRepository) { _filtersProvider = filtersProvider; RuleFor(x => x.Name) .NotEmptyWithMessage() .MaxLengthWithMessage(CarEngineConstraints.NameMaxLength); RuleFor(x => x.Volume) .IsPositiveOrZeroWithMessage(); RuleFor(x => x.Power) .IsPositiveOrZeroWithMessage(); RuleFor(x => x.TypeId) .NotEmptyWithMessage() .MustExistsWithMessageAsync(EngineTypeExists); }
public SupplierPhotoCreateCommandValidator(IGenericReadRepository readRepository, ISupplierFiltersProvider supplierFiltersProvider) : base(readRepository) { _supplierFiltersProvider = supplierFiltersProvider; RuleFor(x => x.SupplierId) .NotEmptyWithMessage() .MustExistsWithMessageAsync(SupplierExists); RuleFor(x => x.Photo) .NotEmptyWithMessage() .DependentRules(() => { RuleFor(x => x.Photo) .Cascade(CascadeMode.Continue) .MustAsync(FileSizeIsValid) .WithMessage($"File size should be up to {SupplierPhotoConstraints.FileMaxSize / 1000000.0f}MB") .MustAsync(FileTypeIsValid) .WithMessage($"File type is prohibited. Allowed types - {GetSupportedFileTypesString()}"); }); }
public BrandUpdateCommandValidator(IGenericReadRepository readRepository, IBrandFiltersProvider filtersProvider) : base(readRepository) { _filtersProvider = filtersProvider; RuleFor(x => x.Id) .NotEmptyWithMessage() .MustExistsWithMessageAsync(BrandExists); RuleFor(x => x.Name) .NotEmptyWithMessage() .MaxLengthWithMessage(BrandConstraints.NameMaxLength) .MustNotExistWithMessageAsync(NameDoesNotExist); RuleFor(x => x.CountryId) .NotEmptyWithMessage() .MustExistsWithMessageAsync(CountryExists); RuleFor(x => x.SupplierId) .MustExistsWithMessageAsync(SupplierExists); }
public WorkOrderCreateCommandValidator(IGenericReadRepository readRepository, IUserFiltersProvider userFiltersProvider, IValidator <WorkOrderClientCreateCommand> clientValidator, IWorkFiltersProvider workFiltersProvider) : base(readRepository) { _userFiltersProvider = userFiltersProvider; _workFiltersProvider = workFiltersProvider; RuleFor(x => x.WorkerId) .NotEmptyWithMessage() .MustAsync(WorkerIsValid) .WithMessage($"The {{PropertyName}} is invalid. User should be Active and has ServiceMan role."); RuleFor(x => x.Client) .SetValidator(clientValidator); RuleFor(x => x.WorksIds) .NotEmptyWithMessage(); RuleForEach(x => x.WorksIds) .NotEmptyWithMessage() .MustExistsWithMessageAsync(WorkExists); }
public WorkOrderClientUpdateCommandValidator(IGenericReadRepository readRepository, IWorkOrderClientFiltersProvider filtersProvider) : base(readRepository) { _filtersProvider = filtersProvider; RuleFor(x => x.Id) .NotEmptyWithMessage() .MustExistsWithMessageAsync(ClientExists); RuleFor(x => x.FirstName) .NotEmptyWithMessage() .MaxLengthWithMessage(WorkOrderClientConstraints.FirstNameMaxLength); RuleFor(x => x.LastName) .NotEmptyWithMessage() .MaxLengthWithMessage(WorkOrderClientConstraints.LastNameMaxLength); RuleFor(x => x.Phone) .NotEmptyWithMessage() .MaxLengthWithMessage(WorkOrderClientConstraints.PhoneMaxLength) .IsValidPhoneNumberWithMessage(); }
public CarEngineGearboxAssignCommandValidator(IGenericReadRepository readRepository, ICarEngineFiltersProvider engineFiltersProvider, IGearboxFiltersProvider gearboxFiltersProvider, ICarModelFiltersProvider modelFiltersProvider, IEngineSupportsGearboxFiltersProvider engineSupportsGearboxFiltersProvider) : base(readRepository) { _engineFiltersProvider = engineFiltersProvider; _gearboxFiltersProvider = gearboxFiltersProvider; _modelFiltersProvider = modelFiltersProvider; _engineSupportsGearboxFiltersProvider = engineSupportsGearboxFiltersProvider; RuleFor(x => x.ModelId) .NotEmptyWithMessage() .MustExistsWithMessageAsync(ModelExists); RuleFor(x => x.EngineId) .NotEmptyWithMessage() .MustExistsWithMessageAsync(EngineExists); RuleFor(x => x.GearboxId) .NotEmptyWithMessage() .MustExistsWithMessageAsync(GearboxExists); RuleFor(x => x.Price) .IsPositiveOrZeroWithMessage(); }
public UserCreateCommandValidator(IGenericReadRepository readRepository, IUserRoleFiltersProvider roleFiltersProvider, IUserFiltersProvider userFiltersProvider) : base(readRepository) { _roleFiltersProvider = roleFiltersProvider; _userFiltersProvider = userFiltersProvider; RuleFor(x => x.FirstName) .NotEmptyWithMessage() .MaxLengthWithMessage(UserConstraints.FirstNameMaxLength); RuleFor(x => x.LastName) .NotEmptyWithMessage() .MaxLengthWithMessage(UserConstraints.LastNameMaxLength); RuleFor(x => x.Email) .NotEmptyWithMessage() .MaxLengthWithMessage(UserConstraints.EmailMaxLength) .IsValidEmailWithMessage() .MustNotExistWithMessageAsync(EmailDoesNotExists); RuleFor(x => x.PasswordHash) .NotEmptyWithMessage() .MaxLengthWithMessage(UserConstraints.PasswordHashLength) .IsValidMD5HashWithMessage(); RuleFor(x => x.Phone) .NotEmptyWithMessage() .MaxLengthWithMessage(UserConstraints.PhoneMaxLength) .IsValidPhoneNumberWithMessage(); RuleFor(x => x.Salary) .IsPositiveOrZeroWithMessage(); RuleFor(x => x.RoleId) .NotEmptyWithMessage() .MustExistsWithMessageAsync(RoleExists); }