CraftEmployeeValidator.cs 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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 CraftEmployeeValidator : AbstractValidator<KeyValuePair<string, CraftEmployeeModel>>
  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 CraftEmployeeValidator class
  19. /// </summary>
  20. /// <param name="eRPDbContext">Global DbContext.</param>
  21. public CraftEmployeeValidator(
  22. ERPDbContext eRPDbContext)
  23. {
  24. _eRPDbContext = eRPDbContext;
  25. RuleFor(m => m.Value)
  26. .Custom((val, ctx) =>
  27. {
  28. if (val.EmployeeId == 0)
  29. ctx.AddFailure("EmployeeId", "Ein Mitarbeiter muss gewählt werden.");
  30. if (val.Amount <= 0)
  31. ctx.AddFailure(
  32. String.Format("CraftEmployees[{0}].Amount", val.DictIdentifier), "'Dauer' muss größer als 0 sein.");
  33. if (val.Value <= 0)
  34. ctx.AddFailure(
  35. String.Format("CraftEmployees[{0}].Value", val.DictIdentifier), "'Wert' muss größer als 0 sein.");
  36. });
  37. }
  38. #endregion
  39. }
  40. }