2023-04-08 16:56:53 +04:00
|
|
|
|
using HardwareShopContracts.BindingModels;
|
2023-04-01 17:34:07 +04:00
|
|
|
|
using HardwareShopContracts.ViewModels;
|
|
|
|
|
using HardwareShopDatabaseImplement.Models.Storekeeper;
|
|
|
|
|
using HardwareShopDatabaseImplement.Models.Worker;
|
2023-04-08 16:56:53 +04:00
|
|
|
|
using HardwareShopDataModels.Enums;
|
|
|
|
|
using HardwareShopDataModels.Models;
|
|
|
|
|
using System.ComponentModel.DataAnnotations;
|
|
|
|
|
using System.ComponentModel.DataAnnotations.Schema;
|
2023-04-01 14:32:31 +04:00
|
|
|
|
|
|
|
|
|
namespace HardwareShopDatabaseImplement.Models
|
|
|
|
|
{
|
|
|
|
|
public class User : IUserModel
|
|
|
|
|
{
|
|
|
|
|
public int Id { get; set; }
|
|
|
|
|
|
2023-04-01 17:34:07 +04:00
|
|
|
|
[Required]
|
2023-04-01 14:32:31 +04:00
|
|
|
|
public string Login { get; set; } = string.Empty;
|
|
|
|
|
|
2023-04-01 17:34:07 +04:00
|
|
|
|
[Required]
|
2023-04-01 14:32:31 +04:00
|
|
|
|
public string Email { get; set; } = string.Empty;
|
|
|
|
|
|
2023-04-01 17:34:07 +04:00
|
|
|
|
[Required]
|
2023-04-01 14:32:31 +04:00
|
|
|
|
public string Password { get; set; } = string.Empty;
|
|
|
|
|
|
2023-04-01 17:34:07 +04:00
|
|
|
|
[Required]
|
2023-04-01 14:32:31 +04:00
|
|
|
|
public UserRole Role { get; set; } = UserRole.Неизвестен;
|
2023-04-01 17:34:07 +04:00
|
|
|
|
|
2023-04-02 19:27:58 +04:00
|
|
|
|
[ForeignKey("UserId")]
|
2023-04-01 17:34:07 +04:00
|
|
|
|
public virtual List<Order> Orders { get; set; } = new();
|
|
|
|
|
|
2023-04-02 19:27:58 +04:00
|
|
|
|
[ForeignKey("UserId")]
|
2023-04-01 17:34:07 +04:00
|
|
|
|
public virtual List<Build> Builds { get; set; } = new();
|
|
|
|
|
|
2023-04-02 19:27:58 +04:00
|
|
|
|
[ForeignKey("UserId")]
|
2023-04-01 17:34:07 +04:00
|
|
|
|
public virtual List<Comment> Comments { get; set; } = new();
|
|
|
|
|
|
2023-04-02 19:27:58 +04:00
|
|
|
|
[ForeignKey("UserId")]
|
2023-04-01 17:34:07 +04:00
|
|
|
|
public virtual List<Purchase> Purchases { get; set; } = new();
|
|
|
|
|
|
2023-04-02 19:27:58 +04:00
|
|
|
|
[ForeignKey("UserId")]
|
2023-04-01 17:34:07 +04:00
|
|
|
|
public virtual List<Component> Components { get; set; } = new();
|
|
|
|
|
|
2023-04-02 19:27:58 +04:00
|
|
|
|
[ForeignKey("UserId")]
|
2023-04-01 17:34:07 +04:00
|
|
|
|
public virtual List<Good> Goods { get; set; } = new();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static User? Create(UserBindingModel? model)
|
|
|
|
|
{
|
|
|
|
|
if (model == null)
|
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
return new User()
|
|
|
|
|
{
|
|
|
|
|
Id = model.Id,
|
|
|
|
|
Login = model.Login,
|
|
|
|
|
Email = model.Email,
|
|
|
|
|
Password = model.Password,
|
|
|
|
|
Role = model.Role
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Update(UserBindingModel? model)
|
|
|
|
|
{
|
|
|
|
|
if (model == null)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
Login = model.Login;
|
|
|
|
|
Password = model.Password;
|
|
|
|
|
Email = model.Email;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public UserViewModel GetViewModel => new()
|
|
|
|
|
{
|
|
|
|
|
Id = Id,
|
|
|
|
|
Login = Login,
|
|
|
|
|
Email = Email,
|
|
|
|
|
Password = Password,
|
|
|
|
|
Role = Role,
|
|
|
|
|
};
|
2023-04-01 14:32:31 +04:00
|
|
|
|
}
|
|
|
|
|
}
|