aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSyndamia <kamen.d.mladenov@protonmail.com>2020-12-08 15:56:50 +0200
committerSyndamia <kamen.d.mladenov@protonmail.com>2020-12-08 15:56:50 +0200
commite127d34d095b8d77577e647bf330f8dc2a8f5ffc (patch)
tree4dbed5e5607edee36c1eec3e68ca929ba5a352ce
parent138b1632a5a4602b83521e9972b75c89da4c8d72 (diff)
downloadDevHive-e127d34d095b8d77577e647bf330f8dc2a8f5ffc.tar
DevHive-e127d34d095b8d77577e647bf330f8dc2a8f5ffc.tar.gz
DevHive-e127d34d095b8d77577e647bf330f8dc2a8f5ffc.zip
Added initial implementation of User class
-rw-r--r--Models/Classes/User.cs72
-rw-r--r--Models/Models.csproj5
2 files changed, 74 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
+}
diff --git a/Models/Models.csproj b/Models/Models.csproj
index abb6514..e51f9c6 100644
--- a/Models/Models.csproj
+++ b/Models/Models.csproj
@@ -5,4 +5,9 @@
<RootNamespace>Models</RootNamespace>
</PropertyGroup>
+ <ItemGroup>
+ <PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="5.0.0" />
+ <PackageReference Include="System.ComponentModel.Annotations" Version="5.0.0" />
+ </ItemGroup>
+
</Project>