using FluentValidation; using GreenTree.Strohrmann.ERP.Domain.Model; using GreenTree.Strohrmann.ERP.Web.Models.Business; using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; namespace GreenTree.Strohrmann.ERP.Web.Validators { public class CraftValidator : AbstractValidator { #region DI fields // The global DbContext private readonly ERPDbContext _eRPDbContext; #endregion #region Ctor /// /// Initializes a new instance of the EmployeeValidator class /// /// Global DbContext. public CraftValidator( ERPDbContext eRPDbContext) { _eRPDbContext = eRPDbContext; RuleFor(m => m.Name) .NotEmpty(); RuleFor(m => m.CustomerId) .NotEmpty(); RuleFor(m => m.CreationDate) .NotEmpty(); RuleForEach(m => m.CraftEmployees) .SetValidator(new CraftEmployeeValidator(_eRPDbContext)); RuleForEach(m => m.CraftMaterials) .SetValidator(new CraftMaterialValidator(_eRPDbContext)); //RuleForEach(m => m.CraftEmployees) // .ChildRules(subModel => // { // subModel // .RuleFor(x => x.Value.EmployeeId) // .GreaterThan(0); // subModel // .RuleFor(x => x.Value.Amount) // .GreaterThan(0); // subModel // .RuleFor(x => x.Value.Value) // .GreaterThan(0); // }); } #endregion } }