2023-09-06 22:02:39 +04:00
|
|
|
|
using BlogContracts.BindingModels;
|
|
|
|
|
using BlogContracts.ViewModels;
|
|
|
|
|
using BlogDataModels;
|
2023-09-06 21:16:28 +04:00
|
|
|
|
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 BlogDatabase.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; }
|
|
|
|
|
|
|
|
|
|
public int Id { get; 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 virtual Role Role { get; set; }
|
|
|
|
|
|
|
|
|
|
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,
|
|
|
|
|
RoleId = model.RoleId,
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
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,
|
|
|
|
|
RoleId = RoleId,
|
|
|
|
|
RoleName = Role == null ? string.Empty : Role.Name,
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
}
|