aboutsummaryrefslogtreecommitdiff
path: root/Data
diff options
context:
space:
mode:
authortranstrike <transtrike@gmail.com>2020-12-11 14:35:39 +0200
committertranstrike <transtrike@gmail.com>2020-12-11 14:35:39 +0200
commit6a85255c78a448256fab68cd361983ffc85f2b03 (patch)
treee4b4c3071a59fecf120d8ebddb7d366bdc653628 /Data
parenteb7c817329bcdd9eb520c6760bacf84d6f45f20d (diff)
downloadDevHive-6a85255c78a448256fab68cd361983ffc85f2b03.tar
DevHive-6a85255c78a448256fab68cd361983ffc85f2b03.tar.gz
DevHive-6a85255c78a448256fab68cd361983ffc85f2b03.zip
Renamed Models to Data
Diffstat (limited to 'Data')
-rw-r--r--Data/Data.csproj14
-rw-r--r--Data/Models/Classes/Language.cs7
-rw-r--r--Data/Models/Classes/Roles.cs9
-rw-r--r--Data/Models/Classes/Technology.cs7
-rw-r--r--Data/Models/Classes/User.cs93
-rw-r--r--Data/Models/DTOs/UserDTO.cs11
-rw-r--r--Data/Models/Interfaces/Database/IRepository.cs24
-rw-r--r--Data/Models/Profiles/UserProfile.cs14
8 files changed, 179 insertions, 0 deletions
diff --git a/Data/Data.csproj b/Data/Data.csproj
new file mode 100644
index 0000000..373fbc4
--- /dev/null
+++ b/Data/Data.csproj
@@ -0,0 +1,14 @@
+<Project Sdk="Microsoft.NET.Sdk">
+
+ <PropertyGroup>
+ <TargetFramework>net5.0</TargetFramework>
+ <RootNamespace>Data</RootNamespace>
+ </PropertyGroup>
+
+ <ItemGroup>
+ <PackageReference Include="AutoMapper" Version="10.1.1" />
+ <PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="5.0.0" />
+ <PackageReference Include="System.ComponentModel.Annotations" Version="5.0.0" />
+ </ItemGroup>
+
+</Project>
diff --git a/Data/Models/Classes/Language.cs b/Data/Models/Classes/Language.cs
new file mode 100644
index 0000000..116b451
--- /dev/null
+++ b/Data/Models/Classes/Language.cs
@@ -0,0 +1,7 @@
+namespace Data.Models.Classes
+{
+ public class Language
+ {
+ public int Id { get; set; }
+ }
+}
diff --git a/Data/Models/Classes/Roles.cs b/Data/Models/Classes/Roles.cs
new file mode 100644
index 0000000..1f8c9f2
--- /dev/null
+++ b/Data/Models/Classes/Roles.cs
@@ -0,0 +1,9 @@
+using Microsoft.AspNetCore.Identity;
+
+namespace Data.Models.Classes
+{
+ public class Roles : IdentityRole<int>
+ {
+
+ }
+} \ No newline at end of file
diff --git a/Data/Models/Classes/Technology.cs b/Data/Models/Classes/Technology.cs
new file mode 100644
index 0000000..ccdc425
--- /dev/null
+++ b/Data/Models/Classes/Technology.cs
@@ -0,0 +1,7 @@
+namespace Data.Models.Classes
+{
+ public class Technology
+ {
+ public int Id { get; set; }
+ }
+}
diff --git a/Data/Models/Classes/User.cs b/Data/Models/Classes/User.cs
new file mode 100644
index 0000000..525d725
--- /dev/null
+++ b/Data/Models/Classes/User.cs
@@ -0,0 +1,93 @@
+using System;
+using System.ComponentModel.DataAnnotations;
+using System.ComponentModel.DataAnnotations.Schema;
+using Microsoft.AspNetCore.Identity;
+using System.Collections.Generic;
+
+namespace Data.Models.Classes
+{
+ [Table("Users")]
+ public class User : 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> 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}.");
+
+ foreach (char character in value) // more efficient than Linq
+ {
+ if (!Char.IsLetter(character))
+ if (!(Char.IsDigit(character) && canBeDigit))
+ 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);
+ }
+ }
+}
diff --git a/Data/Models/DTOs/UserDTO.cs b/Data/Models/DTOs/UserDTO.cs
new file mode 100644
index 0000000..d0b8642
--- /dev/null
+++ b/Data/Models/DTOs/UserDTO.cs
@@ -0,0 +1,11 @@
+namespace Data.Models.DTOs
+{
+ public class UserDTO
+ {
+ public int Id { get; set; }
+ public string UserName { get; set; }
+ public string Email { get; set; }
+ public string FirstName { get; set; }
+ public string LastName { get; set; }
+ }
+} \ No newline at end of file
diff --git a/Data/Models/Interfaces/Database/IRepository.cs b/Data/Models/Interfaces/Database/IRepository.cs
new file mode 100644
index 0000000..81a1a35
--- /dev/null
+++ b/Data/Models/Interfaces/Database/IRepository.cs
@@ -0,0 +1,24 @@
+using System.Collections.Generic;
+using System.Threading.Tasks;
+
+namespace Data.Models.Interfaces.Database
+{
+ public interface IRepository<TEntity>
+ where TEntity : class
+ {
+ //Add Entity to database
+ Task AddAsync(TEntity entity);
+
+ //Return *count* instances of Entity from the database
+ IEnumerable<TEntity> Query(int count);
+
+ //Find entity by id
+ Task<TEntity> FindByIdAsync(object id);
+
+ //Modify Entity from database
+ Task EditAsync(object id, TEntity newEntity);
+
+ //Delete Entity from database
+ Task DeleteAsync(object id);
+ }
+} \ No newline at end of file
diff --git a/Data/Models/Profiles/UserProfile.cs b/Data/Models/Profiles/UserProfile.cs
new file mode 100644
index 0000000..048deed
--- /dev/null
+++ b/Data/Models/Profiles/UserProfile.cs
@@ -0,0 +1,14 @@
+using Data.Models.Classes;
+using Data.Models.DTOs;
+using AutoMapper;
+
+namespace Data.Models.Profiles
+{
+ public class UserProfile : Profile
+ {
+ public UserProfile()
+ {
+ CreateMap<UserDTO, User>();
+ }
+ }
+}