-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Added] check email and username unique validation
- Loading branch information
Showing
2 changed files
with
57 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} | ||
} |