Skip to content

Commit

Permalink
[Added] check email and username unique validation
Browse files Browse the repository at this point in the history
  • Loading branch information
nobir committed Jul 17, 2022
1 parent e8976db commit 04e417b
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 0 deletions.
28 changes: 28 additions & 0 deletions Models/UniqueEmailValidation.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.ComponentModel.DataAnnotations;
using ERPSystemTimologio.EF;

namespace ERPSystemTimologio.Models
{
public class UniqueEmailValidation : ValidationAttribute
{
protected override ValidationResult IsValid(object value, ValidationContext validationContext)
{
if(value != null)
{
var db = new TimologioEntities();

int isExists = db.Users.Where(u => u.Email.Equals(value.ToString())).Count();
if (isExists > 0)
{
return new ValidationResult("The email is already is registered");
}
}

return ValidationResult.Success;
}
}
}
29 changes: 29 additions & 0 deletions Models/UniqueUsernameValidation.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.ComponentModel.DataAnnotations;
using ERPSystemTimologio.EF;

namespace ERPSystemTimologio.Models
{
public class UniqueUsernameValidation : ValidationAttribute
{
protected override ValidationResult IsValid(object value, ValidationContext validationContext)
{

if(value != null)
{
var db = new TimologioEntities();

int isExists = db.Users.Where(u => u.Username.Equals(value.ToString())).Count();
if (isExists > 0)
{
return new ValidationResult("The username is already is registered");
}
}

return ValidationResult.Success;
}
}
}

0 comments on commit 04e417b

Please sign in to comment.