Advertisement
Guest User

Untitled

a guest
Nov 21st, 2014
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.82 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using MKGS.SKS.BusinessLogic.Models;
  7. using FluentValidation;
  8.  
  9. namespace MKGS.SKS.BusinessLogic
  10. {
  11.     public class PackageValidator : AbstractValidator<Package>
  12.     {
  13.         public PackageValidator()
  14.         {
  15.             RuleFor(package => package.PostalCode).Matches("^A-[0-9]{4}$").When(package => package.PostalCode != null);
  16.             RuleFor(package => package.Street).Matches("^[A-Za-z]+ ([1-9]+[A-Za-z]?[/]?)+$").When(package => package.Street != null);
  17.             RuleFor(package => package.City).Matches("^[A-Z][a-z- ]+$").When(package => package.City != null);
  18.             RuleFor(package => package.Country).Matches("^[A-Z][a-z- ]+$").When(package => package.Country != null);
  19.             RuleFor(package => package.FirstName).Matches("^[A-Z][a-z- ]+$").When(package => package.FirstName != null);
  20.             RuleFor(package => package.LastName).Matches("^[A-Z][a-z- ]+$").When(package => package.LastName != null);
  21.             RuleFor(package => package.Weight).GreaterThanOrEqualTo(0.0);
  22.  
  23.         }
  24.     }
  25.  
  26.     public class TrackingPointValidator : AbstractValidator<Point>
  27.     {
  28.         public TrackingPointValidator()
  29.         {
  30.             RuleFor(point => point.Code).Matches("^[A-Z0-9]{4}$").When(point => point.Code != null);
  31.             RuleFor(point => point.Name).Matches("^[A-Za-z- 0-9]+$").When(point => point.Name != null);
  32.  
  33.         }
  34.     }
  35.  
  36.     public class TrackingCodeValidator : AbstractValidator<TrackingCode>
  37.     {
  38.         public TrackingCodeValidator()
  39.         {
  40.             RuleFor(code => code.Code).Matches("^[A-Z0-9]{8}$").When(code => code.Code != null);
  41.         }
  42.     }
  43.  
  44.     public class TruckValidator : AbstractValidator<Truck>
  45.     {
  46.         public TruckValidator()
  47.         {
  48.             RuleFor(truck => truck.NumberPlate).Matches("^[A-Z0-9]{4}$").When(truck => truck.NumberPlate != null);
  49.             RuleFor(truck => truck.Longitude).NotNull();
  50.             RuleFor(truck => truck.Latitude).NotNull();
  51.             RuleFor(truck => truck.Radius).GreaterThan(0.0);
  52.             RuleFor(truck => truck.Duration).GreaterThan(0);
  53.         }
  54.     }
  55.  
  56.     public class RootobjectValidator : AbstractValidator<Warehouses>
  57.     {
  58.         public RootobjectValidator()
  59.         {
  60.             RuleFor(p => p.Name).NotEmpty().NotNull().Matches(@"^[A-Z]{1}[a-zßäöü]+([0-9A-Za-z]+\-?)([0-9A-Za-z]*)?([0-9A-Za-z]*\-?\ ?)*$");
  61.             RuleFor(p => p.Code).NotEmpty().NotNull().Length(4).Matches(@"^[0-9A-Z]{4}$");
  62.             RuleFor(p => p.ConnectedWarehouses).SetCollectionValidator(new ZentrallagerValidator());
  63.         }
  64.     }
  65.  
  66.     public class ZentrallagerValidator : AbstractValidator<ConnectedWarehouse>
  67.     {
  68.         public ZentrallagerValidator()
  69.         {
  70.             RuleFor(p => p.Name).NotEmpty().NotNull().Matches(@"^[A-Z]{1}[a-zßäöü]+([0-9A-Za-z]+\-?)([0-9A-Za-z]*)?([0-9A-Za-z]*\-?\ ?)*$"); ;
  71.             RuleFor(p => p.Code).NotEmpty().NotNull().Length(4).Matches(@"^[0-9A-Z]{4}$");
  72.             RuleFor(p => p.ConnectedWarehouses).SetCollectionValidator(new RegionallagerValidator());
  73.             RuleFor(p => p.Duration).NotEmpty().NotNull().GreaterThan(0);
  74.         }
  75.     }
  76.  
  77.     public class RegionallagerValidator : AbstractValidator<ConnectedSubWarehouses>
  78.     {
  79.         public RegionallagerValidator()
  80.         {
  81.             RuleFor(p => p.Name).NotEmpty().NotNull().Matches(@"^[A-Z]{1}[a-zßäöü]+([0-9A-Za-z]+\-?)([0-9A-Za-z]*)?([0-9A-Za-z]*\-?\ ?)*$"); ;
  82.             RuleFor(p => p.Code).NotEmpty().NotNull().Length(4).Matches(@"^[0-9A-Z]{4}$");
  83.             RuleFor(p => p.Duration).NotEmpty().NotNull().GreaterThan(0);
  84.             RuleFor(p => p.Trucks).SetCollectionValidator(new TruckValidator());
  85.         }
  86.     }
  87. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement