Case_accounting/CaseAccounting/CaseAccountingDataBaseImplement/Models/User.cs
2023-05-18 01:15:02 +04:00

79 lines
2.0 KiB
C#

using CaseAccountingContracts.BindingModels;
using CaseAccountingContracts.ViewModels;
using CaseAccountingDataModels.Enum;
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 Role Role { get; set; }
[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,
Role = model.Role
};
}
public void Update(UserBindingModel? model)
{
if (model == null)
{
return;
}
Password = model.Password;
}
public UserViewModel GetViewModel => new()
{
Id = Id,
Login = Login,
Password = Password,
Role = Role,
};
}
}