diff options
| author | Syndamia <kamen.d.mladenov@protonmail.com> | 2020-12-08 15:56:50 +0200 |
|---|---|---|
| committer | Syndamia <kamen.d.mladenov@protonmail.com> | 2020-12-08 15:56:50 +0200 |
| commit | e127d34d095b8d77577e647bf330f8dc2a8f5ffc (patch) | |
| tree | 4dbed5e5607edee36c1eec3e68ca929ba5a352ce /Models/Classes | |
| parent | 138b1632a5a4602b83521e9972b75c89da4c8d72 (diff) | |
| download | DevHive-e127d34d095b8d77577e647bf330f8dc2a8f5ffc.tar DevHive-e127d34d095b8d77577e647bf330f8dc2a8f5ffc.tar.gz DevHive-e127d34d095b8d77577e647bf330f8dc2a8f5ffc.zip | |
Added initial implementation of User class
Diffstat (limited to 'Models/Classes')
| -rw-r--r-- | Models/Classes/User.cs | 72 |
1 files changed, 69 insertions, 3 deletions
diff --git a/Models/Classes/User.cs b/Models/Classes/User.cs index 97f79b7..2549f81 100644 --- a/Models/Classes/User.cs +++ b/Models/Classes/User.cs @@ -1,7 +1,73 @@ +using System; +using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; +using Microsoft.AspNetCore.Identity; +using System.Collections.Generic; + namespace Models.Classes { - public class User + [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; + } + } + + [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 List<User<T>> Friends { get; set; } + + 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."); + } + } + + private static void ValidateURL(string urlValue) { + // Throws an error is URL is invalid + Uri validatedUri; + Uri.TryCreate(urlValue, UriKind.Absolute, out validatedUri); + } } -}
\ No newline at end of file +} |
