78 lines
2.2 KiB
C#
78 lines
2.2 KiB
C#
using ForumContracts.BindingModels;
|
|
using ForumContracts.ViewModels;
|
|
using ForumDataModels;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel.DataAnnotations;
|
|
using System.ComponentModel.DataAnnotations.Schema;
|
|
using System.Drawing;
|
|
using System.Linq;
|
|
using System.Reflection;
|
|
using System.Runtime.ConstrainedExecution;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace ForumDatabase.Models
|
|
{
|
|
public class User : IUserModel
|
|
{
|
|
[Required]
|
|
public string Username { get; set; } = string.Empty;
|
|
[Required]
|
|
public string Email { get; set; } = string.Empty;
|
|
[Required]
|
|
public string Password { get; set; } = string.Empty;
|
|
[Required]
|
|
public DateTime RegistrationDate { get; set; } = DateTime.SpecifyKind(DateTime.MinValue, DateTimeKind.Utc);
|
|
|
|
public int Id { get; private set; }
|
|
|
|
[Required]
|
|
public int RoleId { get; set; }
|
|
|
|
[ForeignKey("CategoryId")]
|
|
List<Category> Categories { get; set; } = new();
|
|
|
|
[ForeignKey("TopicId")]
|
|
List<Topic> Topics { get; set; } = new();
|
|
|
|
[ForeignKey("MessageId")]
|
|
List<Message> Messages { get; set; } = new();
|
|
|
|
public static User? Create(UserBindingModel model)
|
|
{
|
|
if (model == null)
|
|
{
|
|
return null;
|
|
}
|
|
return new User()
|
|
{
|
|
Id = model.Id,
|
|
Username = model.Username,
|
|
Email = model.Email,
|
|
Password = model.Password,
|
|
RegistrationDate = model.RegistrationDate,
|
|
};
|
|
}
|
|
public void Update(UserBindingModel model)
|
|
{
|
|
if (model == null)
|
|
{
|
|
return;
|
|
}
|
|
Username = model.Username;
|
|
Email = model.Email;
|
|
Password = model.Password;
|
|
RegistrationDate = model.RegistrationDate;
|
|
}
|
|
public UserViewModel GetViewModel => new()
|
|
{
|
|
Id = Id,
|
|
Username = Username,
|
|
Email = Email,
|
|
Password = Password,
|
|
RegistrationDate = RegistrationDate,
|
|
};
|
|
}
|
|
}
|