Employe.cs 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel.DataAnnotations;
  4. using System.Linq;
  5. using System.Web;
  6. namespace AppliWebANA.Models {
  7. public enum Poste {
  8. Stagiaire,
  9. Chef,
  10. [Display(Name = "Sous-chef")]
  11. SousChef,
  12. Grouillot
  13. }
  14. public class Employe {
  15. [Required( ErrorMessage = "Le champ {0} est obligatware !" )]
  16. [Display( Name = "N° de membre du personnel" )]
  17. [CustomValidation(typeof( Validations ), "ValiderEmployeId")]
  18. public int Id { get; set; }
  19. [Required( ErrorMessage = "Le champ {0} est obligatware !" )]
  20. [Display( Name = "Prénom NOM" )]
  21. [StringLength( 50, MinimumLength = 2 )]
  22. [RegularExpression( "^[A-Z][a-z]*(-[A-Z][a-z]*)? [A-Z]+$", ErrorMessage = "Ça correspond pas à ^[A-Z][a-z]*(-[A-Z][a-z]*)? [A-Z]+$, CRÉTIN !")]
  23. public string Nom { get; set; }
  24. [Required( ErrorMessage = "Le champ {0} est obligatware !" )]
  25. public Poste Poste { get; set; }
  26. [Required( ErrorMessage = "Le champ {0} est obligatware !" )]
  27. [Range( 0, 7000, ErrorMessage = "Un sale air conforme à la politique de l'entrepise SVP !" )]
  28. public Decimal Salaire { get; set; }
  29. public static class Validations {
  30. public static ValidationResult ValiderEmployeId( int id ) {
  31. if( id % 2 == 1 ) {
  32. return new ValidationResult( $"Valeur {id} non-autorisée" );
  33. }
  34. return null;
  35. }
  36. }
  37. }
  38. }