MaterialValidator.cs 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. using FluentValidation;
  2. using GreenTree.Strohrmann.ERP.Services.Geolocator;
  3. using GreenTree.Strohrmann.ERP.Web.Models.Business;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Linq;
  7. using System.Threading.Tasks;
  8. namespace GreenTree.Strohrmann.ERP.Web.Validators
  9. {
  10. public class MaterialValidator : AbstractValidator<MaterialModel>
  11. {
  12. #region Ctor
  13. /// <summary>
  14. /// Initializes a new instance of the MaterialValidator class
  15. /// </summary>
  16. public MaterialValidator()
  17. {
  18. RuleFor(m => m.Name)
  19. .NotEmpty();
  20. RuleFor(m => m.Description)
  21. .NotEmpty();
  22. RuleFor(m => m.ItemNumber)
  23. .NotEmpty();
  24. RuleFor(m => m.NetValue)
  25. .GreaterThanOrEqualTo(0);
  26. RuleFor(m => m.DefaultUnit)
  27. .NotNull()
  28. .DependentRules(() =>
  29. {
  30. RuleFor(x => x.Height)
  31. .GreaterThan(0);
  32. RuleFor(x => x.Width)
  33. .GreaterThan(0);
  34. RuleFor(x => x.Depth)
  35. .GreaterThan(0);
  36. });
  37. RuleFor(m => m.Supplier)
  38. .NotNull();
  39. }
  40. #endregion
  41. }
  42. }