Further major refactoring of code
This is another commit to mostly version the code. There have been a considerable number of changes and there is functionality that I am still determining whether it should lie within the manager or the model class itself. It makes the most sense to possibly add the "Update" or database manipulation functions on the models themselves. On the other hand, instead of creating and generating the ID in the model, the current design is to create the entry in the database first, get the last insert row ID and create a new and complete model that is returned back by the function. This allows us to leverage the autoincrement functionality of the database rather than trying to design a function and/ or make an additional call to the database. **NOTE: Code is non-functional due to some classes not having their errors resolved.
This commit is contained in:
49
OpheliasOasis/Validation.cs
Normal file
49
OpheliasOasis/Validation.cs
Normal file
@@ -0,0 +1,49 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Globalization;
|
||||
|
||||
namespace Ophelias.Expressions
|
||||
{
|
||||
internal static class Expressions
|
||||
{
|
||||
internal static Regex CardRx = new Regex(@"^[0-9]{16}$", RegexOptions.Compiled);
|
||||
internal static Regex ExpriationRx = new Regex(@"^(0?[1-9]|1[012])/2[0-9]{1}$", RegexOptions.Compiled);
|
||||
internal static Regex CCVRx = new Regex(@"^[0-9]{3}$", RegexOptions.Compiled);
|
||||
}
|
||||
internal static class Validation
|
||||
{
|
||||
internal static bool ValidateCreditCard(string CreditCard)
|
||||
{
|
||||
if (Expressions.CardRx.IsMatch(CreditCard))
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
internal static bool ValidateExpirationDate(string Expiration)
|
||||
{
|
||||
if (Expressions.ExpriationRx.IsMatch(Expiration))
|
||||
{
|
||||
DateTime dt = DateTime.ParseExact(Expiration, "MM/yy", CultureInfo.InvariantCulture);
|
||||
if (dt.Year >= DateTime.Now.Year)
|
||||
if (dt.Month >= DateTime.Now.Month)
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
internal static bool ValidateEmail(string email)
|
||||
{
|
||||
EmailAddressAttribute EmailChecker = new EmailAddressAttribute();
|
||||
return EmailChecker.IsValid(email);
|
||||
}
|
||||
internal static bool ValidateCCV(string CCV)
|
||||
{
|
||||
if (Expressions.CCVRx.IsMatch(CCV))
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user