80 lines
1.8 KiB
C#
80 lines
1.8 KiB
C#
using ComputerShopContracts.BindingModels;
|
|
using ComputerShopContracts.ViewModels;
|
|
using ComputerShopDataModels.Enums;
|
|
using ComputerShopDataModels.Models;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel.DataAnnotations;
|
|
using System.ComponentModel.DataAnnotations.Schema;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace ComputerShopDatabaseImplement.Models
|
|
{
|
|
public class User : IUserModel
|
|
{
|
|
public int Id { get; private set; }
|
|
|
|
[Required]
|
|
public string Login { get; set; } = string.Empty;
|
|
|
|
[Required]
|
|
public string Password { get; set; } = string.Empty;
|
|
|
|
[Required]
|
|
public string Email { get; set; } = string.Empty;
|
|
|
|
[Required]
|
|
public UserRole Role { get; set; }
|
|
|
|
[ForeignKey("UserId")]
|
|
public virtual List<Shipment> Shipments { get; set; } = new();
|
|
[ForeignKey("UserId")]
|
|
public virtual List<Order> Orders { get; set; } = new();
|
|
[ForeignKey("UserId")]
|
|
public virtual List<Request> Requests { get; set; } = new();
|
|
|
|
[ForeignKey("UserId")]
|
|
public virtual List<Assembly> Assemblies { get; set; } = new();
|
|
[ForeignKey("UserId")]
|
|
public virtual List<Component> Components { get; set; } = new();
|
|
|
|
[ForeignKey("UserId")]
|
|
public virtual List<Product> Proucts { get; set; } = new();
|
|
|
|
|
|
public static User Create(UserBindingModel model)
|
|
{
|
|
return new User
|
|
{
|
|
Id = model.Id,
|
|
Login = model.Login,
|
|
Password = model.Password,
|
|
Email = model.Email,
|
|
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,
|
|
Password = Password,
|
|
Email = Email,
|
|
Role = Role
|
|
};
|
|
}
|
|
}
|