CraftValidator.cs 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. using FluentValidation;
  2. using GreenTree.Strohrmann.ERP.Domain.Model;
  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 CraftValidator : AbstractValidator<CraftModel>
  11. {
  12. #region DI fields
  13. // The global DbContext
  14. private readonly ERPDbContext _eRPDbContext;
  15. #endregion
  16. #region Ctor
  17. /// <summary>
  18. /// Initializes a new instance of the EmployeeValidator class
  19. /// </summary>
  20. /// <param name="eRPDbContext">Global DbContext.</param>
  21. public CraftValidator(
  22. ERPDbContext eRPDbContext)
  23. {
  24. _eRPDbContext = eRPDbContext;
  25. RuleFor(m => m.Name)
  26. .NotEmpty();
  27. RuleFor(m => m.CustomerId)
  28. .NotEmpty();
  29. RuleFor(m => m.CreationDate)
  30. .NotEmpty();
  31. RuleForEach(m => m.CraftEmployees)
  32. .SetValidator(new CraftEmployeeValidator(_eRPDbContext));
  33. RuleForEach(m => m.CraftMaterials)
  34. .SetValidator(new CraftMaterialValidator(_eRPDbContext));
  35. //RuleForEach(m => m.CraftEmployees)
  36. // .ChildRules(subModel =>
  37. // {
  38. // subModel
  39. // .RuleFor(x => x.Value.EmployeeId)
  40. // .GreaterThan(0);
  41. // subModel
  42. // .RuleFor(x => x.Value.Amount)
  43. // .GreaterThan(0);
  44. // subModel
  45. // .RuleFor(x => x.Value.Value)
  46. // .GreaterThan(0);
  47. // });
  48. }
  49. #endregion
  50. }
  51. }