initial commit from an older template

This commit is contained in:
2025-09-20 22:33:35 +03:00
commit b6778046c2
134 changed files with 6657 additions and 0 deletions

View File

@@ -0,0 +1,15 @@
using Microsoft.AspNetCore.Identity;
using StackExchange.Redis;
namespace GamificationService.Models.Database;
public class ApplicationRole : IdentityRole<long>
{
public ApplicationRole() : base() { }
public ApplicationRole(string roleName) : base(roleName) { }
public string? Description { get; set; }
public List<UserRole> UserRoles { get; set; } = new List<UserRole>();
public List<RoleRight> RoleRights { get; set; } = new List<RoleRight>();
}

View File

@@ -0,0 +1,19 @@
using System.ComponentModel.DataAnnotations;
using GamificationService.Utils;
using Microsoft.AspNetCore.Identity;
namespace GamificationService.Models.Database;
public class ApplicationUser : IdentityUser<long>
{
[Required(ErrorMessage = "Username is required")]
[StringLength(50, ErrorMessage = "Username must be less than 50 characters")]
public string Username { get; set; } = null!;
public bool TwoFactorEnabled { get; set; }
public string? TwoFactorSecret { get; set; }
public bool EmailConfirmed { get; set; }
public List<TwoFactorProvider> TwoFactorProviders { get; set; } = new List<TwoFactorProvider>();
public List<RefreshToken> RefreshTokens { get; set; } = new List<RefreshToken>();
public List<UserRole> UserRoles { get; set; } = new List<UserRole>();
}

View File

@@ -0,0 +1,9 @@
namespace GamificationService.Models.Database;
public class AuditableEntity
{
public DateTimeOffset CreatedOn { get; set; }
public string CreatedBy { get; set; } = string.Empty;
public DateTimeOffset UpdatedOn { get; set; }
public string UpdatedBy { get; set; } = string.Empty;
}

View File

@@ -0,0 +1,29 @@
using System.ComponentModel.DataAnnotations;
namespace GamificationService.Models.Database;
public class Instruction
{
[Key]
public long Id { get; set; }
[Required(ErrorMessage = "Title is required")]
public string Title { get; set; } = null!;
public string? Description { get; set; }
public long CategoryId { get; set; }
[Required(ErrorMessage = "Category must be specified")]
public InstructionCategory Category { get; set; } = null!;
public virtual ICollection<InstructionParagraph> Paragraphs { get; set; }
public long? InstructionTestId { get; set; }
public InstructionTest? InstructionTest { get; set; }
public DateTime? AssignDate { get; set; } = DateTime.UtcNow;
public DateTime? DeadlineDate { get; set; }
public bool IsEnabled { get; set; }
}

View File

@@ -0,0 +1,13 @@
using System.ComponentModel.DataAnnotations;
namespace GamificationService.Models.Database;
public class InstructionCategory
{
[Key]
public long Id { get; set; }
[Required(ErrorMessage = "Title is required")]
public string Title { get; set; } = null!;
}

View File

@@ -0,0 +1,21 @@
using System.ComponentModel.DataAnnotations;
namespace GamificationService.Models.Database;
public class InstructionParagraph
{
[Key]
public long Id { get; set; }
public long InstructionId { get; set; }
[Required(ErrorMessage = "Must be linked to instruction")]
public int Order { get; set; }
[Required(ErrorMessage = "Paragraph text is required")]
public string Text { get; set; } = null!;
public string? ImageUrl { get; set; }
public string? VideoUrl { get; set; }
}

View File

@@ -0,0 +1,23 @@
using System.ComponentModel.DataAnnotations;
using GamificationService.Utils.Enums;
namespace GamificationService.Models.Database;
public class InstructionTest
{
[Key]
public long Id { get; set; }
// Reserved just in case
[MaxLength(300, ErrorMessage = "Title cannot be longer than 300 characters")]
public string? Title { get; set; }
public virtual ICollection<InstructionTestQuestion> Questions { get; set; }
public int MaxAttempts { get; set; } = 10;
public double MinScore { get; set; } = 0.6;
public InstructionTestScoreCalcMethod ScoreCalcMethod { get; set; } = InstructionTestScoreCalcMethod.MaxGrade;
}

View File

@@ -0,0 +1,26 @@
using System.ComponentModel.DataAnnotations;
namespace GamificationService.Models.Database;
public class InstructionTestQuestion
{
[Key]
public long Id { get; set; }
[Required(ErrorMessage = "Must be tied to an instruction test")]
public InstructionTest InstructionTest { get; set; } = null!;
public long InstructionTestId { get; set; }
public int Order { get; set; }
public bool IsMultipleAnswer { get; set; }
[Required(ErrorMessage = "Must have question text")]
public string Question { get; set; } = null!;
[Required(ErrorMessage = "Must have answer options")]
public ICollection<string> Answers { get; set; } = null!;
[Required(ErrorMessage = "Must have correct answer ids")]
public ICollection<int> CorrectAnswers { get; set; } = null!;
}

View File

@@ -0,0 +1,20 @@
using System.ComponentModel.DataAnnotations;
namespace GamificationService.Models.Database;
public class InstructionTestResult
{
[Key]
public long Id { get; set; }
public long InstructionTestId { get; set; }
[Required(ErrorMessage = "Instruction test is required")]
public virtual InstructionTest InstructionTest { get; set; } = null!;
public long UserId { get; set; }
[Required(ErrorMessage = "User is required")]
public ApplicationUser User { get; set; } = null!;
[Range(0, 100, ErrorMessage = "Score must be a number from 0 to 100")]
public int Score { get; set; }
}

25
Models/Database/RefreshToken.cs Executable file
View File

@@ -0,0 +1,25 @@
using System.ComponentModel.DataAnnotations;
namespace GamificationService.Models.Database;
public class RefreshToken
{
[Key]
public long Id { get; set; }
public long UserId { get; set; }
public ApplicationUser User { get; set; } = null!;
[Required]
public string Token { get; set; } = null!;
public DateTime Expires { get; set; }
public DateTime Created { get; set; }
public bool IsExpired => DateTime.UtcNow >= Expires;
public bool IsRevoked { get; set; }
public string? RevokedByIp { get; set; }
public DateTime? RevokedOn { get; set; }
public bool IsActive => !IsRevoked && !IsExpired;
}

18
Models/Database/Right.cs Executable file
View File

@@ -0,0 +1,18 @@
using System.ComponentModel.DataAnnotations;
namespace GamificationService.Models.Database;
public class Right
{
[Key]
public long Id { get; set; }
[Required]
[StringLength(50)]
public string Name { get; set; } = null!;
[StringLength(100)]
public string? Description { get; set; }
public List<RoleRight> RoleRights { get; set; } = new List<RoleRight>();
}

10
Models/Database/RoleRight.cs Executable file
View File

@@ -0,0 +1,10 @@
namespace GamificationService.Models.Database;
public class RoleRight
{
public long RoleId { get; set; }
public ApplicationRole Role { get; set; } = null!;
public long RightId { get; set; }
public Right Right { get; set; } = null!;
}

40
Models/Database/UserProfile.cs Executable file
View File

@@ -0,0 +1,40 @@
using System.ComponentModel.DataAnnotations;
using GamificationService.Utils.Enums;
namespace GamificationService.Models.Database;
public class UserProfile
{
[Key]
public long Id { get; set; }
[Required(ErrorMessage = "User is required")]
public long UserId { get; set; }
public ApplicationUser? User { get; set; }
[Required(ErrorMessage = "Name is required")]
[StringLength(100, ErrorMessage = "Name must be less than 100 characters")]
public string Name { get; set; } = null!;
[Required(ErrorMessage = "Surname is required")]
[StringLength(100, ErrorMessage = "Surname must be less than 100 characters")]
public string Surname { get; set; } = null!;
[StringLength(50, ErrorMessage = "Patronymic must be less than 50 characters")]
public string? Patronymic { get; set; }
[Required(ErrorMessage = "Gender is required")]
public Gender Gender { get; set; }
[Required(ErrorMessage = "Birthdate is required")]
public DateTime Birthdate { get; set; }
[EmailAddress(ErrorMessage = "Invalid email")]
public string? ContactEmail { get; set; }
[Phone(ErrorMessage = "Invalid contact phone number")]
public string? ContactPhone { get; set; }
[Url(ErrorMessage = "Invalid avatar url")]
public string? ProfilePicture { get; set; }
}

10
Models/Database/UserRole.cs Executable file
View File

@@ -0,0 +1,10 @@
namespace GamificationService.Models.Database;
public class UserRole
{
public long UserId { get; set; }
public ApplicationUser User { get; set; } = null!;
public long RoleId { get; set; }
public ApplicationRole Role { get; set; } = null!;
}