diff options
| author | transtrike <transtrike@gmail.com> | 2020-12-08 17:44:55 +0200 |
|---|---|---|
| committer | transtrike <transtrike@gmail.com> | 2020-12-08 17:44:55 +0200 |
| commit | 179856fe5dc1d4d3ac32bf95fc1194f069bb2134 (patch) | |
| tree | a63af8cb89be4336404f0333dc517f24976b8ba4 /Models | |
| parent | dbc382f9ea7afa5a7db4adc94b466c47f6b0deb0 (diff) | |
| parent | ca9d36e8625d916ff2a38b60cbca084e9318deb6 (diff) | |
| download | DevHive-179856fe5dc1d4d3ac32bf95fc1194f069bb2134.tar DevHive-179856fe5dc1d4d3ac32bf95fc1194f069bb2134.tar.gz DevHive-179856fe5dc1d4d3ac32bf95fc1194f069bb2134.zip | |
Merge branch 'user-class' of github.com:team-kaleidoscope/DevHive into user-class
Diffstat (limited to 'Models')
| -rw-r--r-- | Models/Classes/User.cs | 128 |
1 files changed, 64 insertions, 64 deletions
diff --git a/Models/Classes/User.cs b/Models/Classes/User.cs index 4903679..70f9c59 100644 --- a/Models/Classes/User.cs +++ b/Models/Classes/User.cs @@ -6,76 +6,76 @@ using System.Collections.Generic; namespace Models.Classes { - [Table("Users")] + [Table("Users")] public class User<T> : IdentityUser<int> { - private string firstName; - private string lastName; - private string profilePicture; - - [Required] - [Range(3, 50)] - [Display(Name = "Username")] - public override string UserName { - get => base.UserName; - set { - ValidateString("Username", 3, 50, value, true); - base.UserName = value; - } - } - - [Required] - [Range(3, 30)] - public string FirstName { - get => this.firstName; - set { - ValidateString("FirstName", 3, 30, value, false); - this.firstName = value; - } - } + private string firstName; + private string lastName; + private string profilePicture; - [Required] - [Range(3, 30)] - public string LastName { - get => this.lastName; - set { - ValidateString("LastName", 3, 30, value, false); - this.lastName = value; - } - } + [Required] + [Range(3, 50)] + [Display(Name = "Username")] + public override string UserName { + get => base.UserName; + set { + ValidateString("Username", 3, 50, value, true); + base.UserName = value; + } + } + + [Required] + [Range(3, 30)] + public string FirstName { + get => this.firstName; + set { + ValidateString("FirstName", 3, 30, value, false); + this.firstName = value; + } + } + + [Required] + [Range(3, 30)] + public string LastName { + get => this.lastName; + set { + ValidateString("LastName", 3, 30, value, false); + this.lastName = value; + } + } - public string ProfilePicture { - get => this.profilePicture; - set { - ValidateURL(value); - this.profilePicture = value; - } - } + public string ProfilePicture { + get => this.profilePicture; + set { + ValidateURL(value); + this.profilePicture = value; + } + } + + public List<User<T>> Friends { get; set; } - public List<User<T>> Friends { get; set; } - - /// <summary> - /// Throws an argument exception if the given value is not composed only of letters, and if specified, also of digits. - /// Does nothing otherwise. - /// </summary> - private static void ValidateString(string name, int minLength, int maxLength, string value, bool canBeDigit) { - if (value.Length < minLength || value.Length > maxLength) - throw new ArgumentException($"{name} length cannot be less than {minLength} and more than {maxLength}."); + /// <summary> + /// Throws an argument exception if the given value is not composed only of letters, and if specified, also of digits. + /// Does nothing otherwise. + /// </summary> + private static void ValidateString(string name, int minLength, int maxLength, string value, bool canBeDigit) { + if (value.Length < minLength || value.Length > maxLength) + throw new ArgumentException($"{name} length cannot be less than {minLength} and more than {maxLength}."); - foreach (char character in value) { // more efficient than Linq - if (!Char.IsLetter(character) || (canBeDigit && !Char.IsDigit(character))) - throw new ArgumentException($"{name} contains invalid characters."); - } - } + foreach (char character in value) { // more efficient than Linq + if (!Char.IsLetter(character) || (canBeDigit && !Char.IsDigit(character))) + throw new ArgumentException($"{name} contains invalid characters."); + } + } - /// <summary> - /// Throws an exception if the absolute url isn't valid. - /// Does nothing otherwise. - /// </summary> - private static void ValidateURL(string urlValue) { - // Throws an error is URL is invalid - Uri validatedUri; - Uri.TryCreate(urlValue, UriKind.Absolute, out validatedUri); - } + /// <summary> + /// Throws an exception if the absolute url isn't valid. + /// Does nothing otherwise. + /// </summary> + private static void ValidateURL(string urlValue) { + // Throws an error is URL is invalid + Uri validatedUri; + Uri.TryCreate(urlValue, UriKind.Absolute, out validatedUri); + } } } |
