Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using MKGS.SKS.BusinessLogic.Models;
- using FluentValidation;
- namespace MKGS.SKS.BusinessLogic
- {
- public class PackageValidator : AbstractValidator<Package>
- {
- public PackageValidator()
- {
- RuleFor(package => package.PostalCode).Matches("^A-[0-9]{4}$").When(package => package.PostalCode != null);
- RuleFor(package => package.Street).Matches("^[A-Za-z]+ ([1-9]+[A-Za-z]?[/]?)+$").When(package => package.Street != null);
- RuleFor(package => package.City).Matches("^[A-Z][a-z- ]+$").When(package => package.City != null);
- RuleFor(package => package.Country).Matches("^[A-Z][a-z- ]+$").When(package => package.Country != null);
- RuleFor(package => package.FirstName).Matches("^[A-Z][a-z- ]+$").When(package => package.FirstName != null);
- RuleFor(package => package.LastName).Matches("^[A-Z][a-z- ]+$").When(package => package.LastName != null);
- RuleFor(package => package.Weight).GreaterThanOrEqualTo(0.0);
- }
- }
- public class TrackingPointValidator : AbstractValidator<Point>
- {
- public TrackingPointValidator()
- {
- RuleFor(point => point.Code).Matches("^[A-Z0-9]{4}$").When(point => point.Code != null);
- RuleFor(point => point.Name).Matches("^[A-Za-z- 0-9]+$").When(point => point.Name != null);
- }
- }
- public class TrackingCodeValidator : AbstractValidator<TrackingCode>
- {
- public TrackingCodeValidator()
- {
- RuleFor(code => code.Code).Matches("^[A-Z0-9]{8}$").When(code => code.Code != null);
- }
- }
- public class TruckValidator : AbstractValidator<Truck>
- {
- public TruckValidator()
- {
- RuleFor(truck => truck.NumberPlate).Matches("^[A-Z0-9]{4}$").When(truck => truck.NumberPlate != null);
- RuleFor(truck => truck.Longitude).NotNull();
- RuleFor(truck => truck.Latitude).NotNull();
- RuleFor(truck => truck.Radius).GreaterThan(0.0);
- RuleFor(truck => truck.Duration).GreaterThan(0);
- }
- }
- public class RootobjectValidator : AbstractValidator<Warehouses>
- {
- public RootobjectValidator()
- {
- RuleFor(p => p.Name).NotEmpty().NotNull().Matches(@"^[A-Z]{1}[a-zßäöü]+([0-9A-Za-z]+\-?)([0-9A-Za-z]*)?([0-9A-Za-z]*\-?\ ?)*$");
- RuleFor(p => p.Code).NotEmpty().NotNull().Length(4).Matches(@"^[0-9A-Z]{4}$");
- RuleFor(p => p.ConnectedWarehouses).SetCollectionValidator(new ZentrallagerValidator());
- }
- }
- public class ZentrallagerValidator : AbstractValidator<ConnectedWarehouse>
- {
- public ZentrallagerValidator()
- {
- RuleFor(p => p.Name).NotEmpty().NotNull().Matches(@"^[A-Z]{1}[a-zßäöü]+([0-9A-Za-z]+\-?)([0-9A-Za-z]*)?([0-9A-Za-z]*\-?\ ?)*$"); ;
- RuleFor(p => p.Code).NotEmpty().NotNull().Length(4).Matches(@"^[0-9A-Z]{4}$");
- RuleFor(p => p.ConnectedWarehouses).SetCollectionValidator(new RegionallagerValidator());
- RuleFor(p => p.Duration).NotEmpty().NotNull().GreaterThan(0);
- }
- }
- public class RegionallagerValidator : AbstractValidator<ConnectedSubWarehouses>
- {
- public RegionallagerValidator()
- {
- RuleFor(p => p.Name).NotEmpty().NotNull().Matches(@"^[A-Z]{1}[a-zßäöü]+([0-9A-Za-z]+\-?)([0-9A-Za-z]*)?([0-9A-Za-z]*\-?\ ?)*$"); ;
- RuleFor(p => p.Code).NotEmpty().NotNull().Length(4).Matches(@"^[0-9A-Z]{4}$");
- RuleFor(p => p.Duration).NotEmpty().NotNull().GreaterThan(0);
- RuleFor(p => p.Trucks).SetCollectionValidator(new TruckValidator());
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement