/*Created : 01 Sept 2017 Tumelo
*
* */
using BuddyFinance.Integration.Models.Profiles;
using FluentValidation;
using System;
using System.Collections.Generic;
using System.Linq;
namespace BuddyFinance.Integration.Models.Registration
{
public class NewProfileModel
{
#region Step 1
public string EmailAddress { get; set; }
public string Password { get; set; }
public string ConfirmPassword { get; set; }
#endregion
#region Step 2
public int ProfileTypeId { get; set; }
public string Name { get; set; }
public string Surname { get; set; }
public string IdentificationNumber { get; set; }
public string ContactNumber { get; set; }
public DateTime? DateOfBirth { get; set; }
public int? GenderId { get; set; }
public EmploymentDetail EmploymentDetail { get; set; }
public BankingDetail BankingDetail { get; set; }
public NextOfKin NextOfKin { get; set; }
#endregion
#region Step 3
public string Otp { get; set; }
public List
Addresses { get; set; }
public List Documents { get; set; }
#endregion
//public string Title { get; set; }
//public int CountryOfBirthId { get; set; }
//public int? EthnicityId { get; set; }
//public int? IdentificationTypeId { get; set; }
//public bool? TaxRegistered { get; set; }
//public TaxInformation TaxInformation { get; set; }
//public int? SourceOfIncomeId { get; set; }
//public string OtherSourceOfIncome { get; set; }
public string VerifyUrl { get; set; }
}
public class AddressValidator : AbstractValidator
{
public AddressValidator()
{
RuleFor(m => m.AddressTypeId).NotEqual(0).WithMessage("Address Type is required");
RuleFor(m => m.ProvinceId).NotEqual(0).WithMessage("Province is required");
//RuleFor(m => m.CountryId).NotEqual(0).WithMessage("Country is required");
RuleFor(m => m.Line1).NotNull().NotEmpty().WithMessage("Address line 1 is required");
RuleFor(m => m.City).NotNull().NotEmpty().WithMessage("City is required");
RuleFor(m => m.PostalCode).NotNull().WithMessage("Postal Code is required")
.NotEmpty().WithMessage("Postal Code is required");
}
}
public class DocumentValidor : AbstractValidator
{
public DocumentValidor()
{
//RuleFor(m => m.
}
}
public class TaxInfoValidator : AbstractValidator
{
public TaxInfoValidator()
{
//RuleFor(m => m.TaxIdentificationTypeId).NotEqual(0)
// .WithMessage("Invalid Tax identification type");
//RuleFor(m => m.TaxNumber).NotNull().WithMessage("Tax Number required")
// .NotEmpty().WithMessage("Tax Number required");
//RuleFor(m => m.TaxCountryId).NotEqual(0).WithMessage("Tax country is required");
}
}
public class EmploymentDetailValidator : AbstractValidator
{
public EmploymentDetailValidator()
{
//RuleFor(m => m.EmploymentStatus).NotNull().NotEmpty()
// .WithMessage("Employment details are required");
//RuleFor(m => m.EmployerName).NotNull().NotEmpty()
// .WithMessage("Employer name is required");
//.When(m => IsEmployed(m.EmploymentStatus));
//RuleFor(m => m.EmployerName).NotNull().NotEmpty()
// .WithMessage("Company name is required");
//.When(m => IsSelfEmployed(m.EmploymentStatus));
//RuleFor(m => m.EmployerNumber).NotNull().NotEmpty()
// .WithMessage("Employer number is required");
//.When(m => IsEmployed(m.EmploymentStatus));
//RuleFor(m => m.EmployerContactNumber).NotNull().NotEmpty()
// .WithMessage("Employer contact number is required");
// .When(m => IsEmployed(m.EmploymentStatus));
//RuleFor(m => m.EmploymentStartDate).NotNull().NotEmpty()
// .WithMessage("Employment start date required")
// .Must(BeValidDate).WithMessage("invalid date specified");
// .When(m => IsEmployed(m.EmploymentStatus));
//RuleFor(m => m.SalaryDay).NotEqual(0).WithMessage("Employment salary day is required");
// .When(m => IsEmployed(m.EmploymentStatus));
//RuleFor(m => m.EmploymentDetail.EmploymentEndDate).NotNull().NotEmpty()
// .WithMessage("Employment end date required")
//
}
//public bool IsEmployed(string employmentStatus)
//{
// if (employmentStatus != "" && (employmentStatus != "Student"
// && employmentStatus != "Unemployed"
// && employmentStatus != "SelfEmployed"))
// {
// return true;
// }
// else
// {
// return false;
// }
//}
//public bool IsSelfEmployed(string status)
//{
// return status == "SelfEmployed";
//}
public bool BeValidDate(DateTime date)
{
return !date.Equals(default(DateTime));
}
}
public class NewProfileModelValidator : AbstractValidator
{
public bool IsSelfEmployed(string status)
{
return status == "SelfEmployed";
}
public bool IsEmployed(string employmentStatus)
{
if (employmentStatus != "" && (employmentStatus != "Student"
&& employmentStatus != "Unemployed"
&& employmentStatus != "SelfEmployed"))
{
return true;
}
else
{
return false;
}
}
public NewProfileModelValidator()
{
RuleSet("userAccountInfo", () =>
{
//RuleFor(m => m.Name).NotEmpty().WithMessage("Name is required");
//RuleFor(m => m.Surname).NotEmpty().NotEmpty().WithMessage("Surname is required");
RuleFor(m => m.EmailAddress).NotNull().NotEmpty().WithMessage("Email Address is required")
.EmailAddress().WithMessage("Invalid email address");
RuleFor(m => m.Password).NotEmpty().WithMessage("Password is required")
.MinimumLength(6).WithMessage("Password must be at least 6 characters");
RuleFor(m => m.ConfirmPassword).NotEmpty().WithMessage("Password confirmation is required")
.Equal(m => m.Password).WithMessage("Password do not match");
});
RuleSet("personalDetails", () =>
{
RuleFor(m => m.ProfileTypeId).NotEqual(0).WithMessage("Please select Profile Type");
//RuleFor(m => m.Title).NotEmpty().WithMessage("Title is required");
RuleFor(m => m.Name).NotEmpty().WithMessage("Name is required");
RuleFor(m => m.Surname).NotEmpty().WithMessage("Surname is required");
//RuleFor(m => m.EmailAddress).NotNull().NotEmpty().WithMessage("Email Address is required")
// .EmailAddress().WithMessage("Invalid email address");
RuleFor(m => m.ContactNumber).NotNull().NotEmpty().WithMessage("Contact number is required.")
.Matches(@"\+?[\d]{9,}").WithMessage("Please provide a valid SA phone number");
//RuleFor(m => m.DateOfBirth).NotNull().NotEmpty().WithMessage("Date Of Birth is required")
// .Must(BeValidDate).WithMessage("invalid date specified");
//RuleFor(m => m.GenderId).NotEqual(0).WithMessage("Please select your Gender");
//.Must(m => m.Equals("Male") || m.Equals("Female")).WithMessage("invalid gender. must Male or Female");
//RuleFor(m => m.CountryOfBirthId).NotEqual(0).WithMessage("Country Of Birth is required");
//RuleFor(m => m.EthnicityId).NotEqual(0).WithMessage("Ethnicity is required");
//RuleFor(m => m.IdentificationTypeId).NotEqual(0).WithMessage("Identification Type is required");
RuleFor(m => m.IdentificationNumber).NotNull().WithMessage("Identification Number is required")
.NotEmpty().WithMessage("Identification Number is required");
//.Matches(@"(((\d{2}((0[13578]|1[02])(0[1-9]|[12]\d|3[01])|(0[13456789]|1[012])(0[1-9]|[12]\d|30)|02(0[1-9]|1\d|2[0-8])))|([02468][048]|[13579][26])0229))(( |-)(\d{4})( |-)(\d{3})|(\d{7}))");
//RuleFor(m => m.EmploymentStatusId).NotEqual(0).NotEmpty()
// .WithMessage("Employment status is required");
//RuleFor(m => m.SourceOfIncomeId).NotEqual(0).WithMessage("Invalid source of income specified");
//RuleFor(m => m.OtherSourceOfIncome).NotNull().WithMessage("Other source of income is required").When(m => m.SourceOfIncomeId == 3)
// .NotEmpty().WithMessage("Other source of income is required").When(m => m.SourceOfIncomeId == 3);
RuleFor(m => m.EmploymentDetail)
.SetValidator(new EmploymentDetailValidator());
//RuleFor(m => m.TaxInformation).SetValidator(new TaxInfoValidator()).When(m => m.TaxRegistered);
});
RuleSet("addressAndDocs", () =>
{
RuleFor(m => m.Addresses).SetCollectionValidator(new AddressValidator()).
When(m => m.Addresses.Any());
RuleFor(m => m.Documents).SetCollectionValidator(new DocumentValidor()).
When(m => m.Documents.Any());
});
//RuleSet("incomeAndTax", () =>
//{
// RuleFor(m => m.SourceOfIncomeId).NotEqual(0).WithMessage("Invalid source of income specified");
// //RuleFor(m => m.OtherSourceOfIncome).NotNull().WithMessage("Other source of income is required")
// // .NotEmpty().WithMessage("Other source of income is required");
// RuleFor(m => m.TaxInformation.TaxIdentificationTypeId).NotEqual(0).When(m => m.TaxRegistered)
// .WithMessage("Invalid Tax identification type");
// RuleFor(m => m.TaxInformation.TaxNumber).NotNull().When(m => m.TaxRegistered)
// .WithMessage("Tax Number required")
// .NotEmpty().When(m => m.TaxRegistered)
// .WithMessage("Tax Number required");
// RuleFor(m => m.TaxInformation.TaxCountryId).NotEqual(0).When(m => m.TaxRegistered)
// .WithMessage("Tax country is required");
//});
//RuleSet("bankingDetails", () =>
//{
// RuleFor(m => m.BankingDetail).NotNull().WithMessage("Banking details are required");
// RuleFor(m => m.BankingDetail.AccountName).NotNull().NotEmpty()
// .WithMessage("Account name is required");
// RuleFor(m => m.BankingDetail.AccountName).NotNull().NotEmpty()
// .WithMessage("Account name is required");
// RuleFor(m => m.BankingDetail.AccountType).NotNull().NotEmpty()
// .WithMessage("Account type is required");
// RuleFor(m => m.BankingDetail.AccountNumber).NotNull().NotEmpty()
// .WithMessage("Account number is required");
// RuleFor(m => m.BankingDetail.BankName).NotNull().NotEmpty()
// .WithMessage("Bank name is required");
// RuleFor(m => m.BankingDetail.BranchCode).NotNull().NotEmpty()
// .WithMessage("Branch code is required");
// RuleFor(m => m.BankingDetail.BranchName).NotNull().NotEmpty()
// .WithMessage("Branch name is required");
//});
//RuleSet("employmentDetails", () =>
//{
// RuleFor(m => m.EmploymentDetail.EmploymentStatus).NotNull().NotEmpty()
// .WithMessage("Employment details are required");
// RuleFor(m => m.EmploymentDetail.EmployerName).NotNull().NotEmpty()
// .WithMessage("Employer name is required");
// RuleFor(m => m.EmploymentDetail.EmployerNumber).NotNull().NotEmpty()
// .WithMessage("Employer number is required");
// RuleFor(m => m.EmploymentDetail.EmployerContactNumber).NotNull().NotEmpty()
// .WithMessage("Employer contact number is required");
// RuleFor(m => m.EmploymentDetail.EmploymentStartDate).NotNull().NotEmpty()
// .WithMessage("Employment start date required")
// .Must(beValidDate).WithMessage("invalid date specified");
// RuleFor(m => m.EmploymentDetail.SalaryDay).NotNull().NotEmpty()
// .WithMessage("Employment salary day is required")
// .Must(beValidDate).WithMessage("invalid date specified");
// //RuleFor(m => m.EmploymentDetail.EmploymentEndDate).NotNull().NotEmpty()
// // .WithMessage("Employment end date required")
// // .Must(beValidDate).WithMessage("invalid date specified");
//});
}
//private bool EqualPassword(string arg)
//{
// return string.Equals(
//}
public bool BeValidDate(DateTime date)
{
return !date.Equals(default(DateTime));
}
}
}