public IEnumerable <ValidationResult> Validate(ValidationContext validationContext) { if (String.IsNullOrEmpty(ToolID)) { yield return(new ValidationResult($"Инструмент необходимо выбрать", new[] { nameof(ToolID) })); } if (!PassportCheck.Validate(this.Passport)) { yield return(new ValidationResult($"Паспорт более не действителен", new[] { nameof(Passport) })); } if (this.DateOfBirth < new DateTime(1920, 1, 1)) { yield return(new ValidationResult($"Некорректная дата рождения", new[] { nameof(DateOfBirth) })); } }
internal void Save(ClaimsPrincipal user, ApplicationDbContext appContext) { Client client = appContext.Clients.FirstOrDefault(o => String.Equals(o.PhoneNumber, this.PhoneNumber, StringComparison.InvariantCultureIgnoreCase)); if (client == null) { client = new Client() { PhoneNumber = this.PhoneNumber, Name = this.ClientName, DateOfBirth = this.DateOfBirth, Passport = this.Passport }; appContext.Clients.Add(client); } else { // need to revalidate passport if (!String.IsNullOrEmpty(client.Passport) && false == PassportCheck.Validate(client.Passport)) { throw new Exception("Паспорт более не действителен"); } } var order = new Order() { ClientID = client.ID, Client = client, ToolID = ToolID, //Tool = tool, ContractNumber = ContractNumber, PaidPledge = PaidPledge, Description = Description, CreatedBy = user.Identity.Name, // have to fill as not nullable ClientName = client.Name, ClientPhoneNumber = client.PhoneNumber }; appContext.Orders.Add(order); }
public override bool IsValid(object value) { return(PassportCheck.Validate(value as string)); }
public void InvalidKurskPassport() { Assert.IsFalse(PassportCheck.Validate("3804246970"), "The passport has to be invalid"); }