79 lines
2.1 KiB
C#
79 lines
2.1 KiB
C#
|
using CaseAccountingContracts.BindingModels;
|
|||
|
using CaseAccountingContracts.ViewModels;
|
|||
|
using CaseAccountingDataModels.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 CaseAccountingDataBaseImplement.Models
|
|||
|
{
|
|||
|
public class User : IUserModel
|
|||
|
{
|
|||
|
public int Id { get; set; }
|
|||
|
|
|||
|
[Required]
|
|||
|
public string Login { get; set; } = string.Empty;
|
|||
|
|
|||
|
[Required]
|
|||
|
public string Password { get; set; } = string.Empty;
|
|||
|
|
|||
|
[Required]
|
|||
|
public int RoleId { get; set; }
|
|||
|
public virtual Role Role { get; set; } = new();
|
|||
|
|
|||
|
[ForeignKey("UserId")]
|
|||
|
public virtual List<Hearing> Hearings { get; set; } = new();
|
|||
|
|
|||
|
[ForeignKey("UserId")]
|
|||
|
public virtual List<Case> Cases { get; set; } = new();
|
|||
|
|
|||
|
[ForeignKey("UserId")]
|
|||
|
public virtual List<Specialization> Specializations { get; set; } = new();
|
|||
|
|
|||
|
[ForeignKey("UserId")]
|
|||
|
public virtual List<Lawyer> Lawyers { get; set; } = new();
|
|||
|
|
|||
|
[ForeignKey("UserId")]
|
|||
|
public virtual List<Deal> Deals { get; set; } = new();
|
|||
|
|
|||
|
[ForeignKey("UserId")]
|
|||
|
public virtual List<Contract> Contracts { get; set; } = new();
|
|||
|
|
|||
|
public static User? Create(UserBindingModel? model)
|
|||
|
{
|
|||
|
if (model == null)
|
|||
|
{
|
|||
|
return null;
|
|||
|
}
|
|||
|
return new User()
|
|||
|
{
|
|||
|
Id = model.Id,
|
|||
|
Login = model.Login,
|
|||
|
Password = model.Password,
|
|||
|
RoleId = model.RoleId
|
|||
|
};
|
|||
|
}
|
|||
|
|
|||
|
public void Update(UserBindingModel? model)
|
|||
|
{
|
|||
|
if (model == null)
|
|||
|
{
|
|||
|
return;
|
|||
|
}
|
|||
|
Password = model.Password;
|
|||
|
}
|
|||
|
|
|||
|
public UserViewModel GetViewModel => new()
|
|||
|
{
|
|||
|
Id = Id,
|
|||
|
Login = Login,
|
|||
|
Password = Password,
|
|||
|
RoleId = RoleId,
|
|||
|
};
|
|||
|
}
|
|||
|
}
|