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 CraftEmployeeValidator : AbstractValidator> { #region DI fields // The global DbContext private readonly ERPDbContext _eRPDbContext; #endregion #region Ctor /// /// Initializes a new instance of the CraftEmployeeValidator class /// /// Global DbContext. public CraftEmployeeValidator( ERPDbContext eRPDbContext) { _eRPDbContext = eRPDbContext; RuleFor(m => m.Value) .Custom((val, ctx) => { if (val.EmployeeId == 0) ctx.AddFailure("EmployeeId", "Ein Mitarbeiter muss gewählt werden."); if (val.Amount <= 0) ctx.AddFailure( String.Format("CraftEmployees[{0}].Amount", val.DictIdentifier), "'Dauer' muss größer als 0 sein."); if (val.Value <= 0) ctx.AddFailure( String.Format("CraftEmployees[{0}].Value", val.DictIdentifier), "'Wert' muss größer als 0 sein."); }); } #endregion } }