Case_accounting/CaseAccounting/CaseAccountingDataBaseImplement/Models/Case.cs

98 lines
2.6 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.Net;
using System.Text;
using System.Threading.Tasks;
namespace CaseAccountingDataBaseImplement.Models
{
public class Case : ICaseModel
{
public int Id { get; set; }
[Required]
public string Name { get; set; } = string.Empty;
[Required]
public string Applicant { get; set; } = string.Empty;
[Required]
public string Defendant { get; set; } = string.Empty;
[Required]
public string Annotation { get; set; } = string.Empty;
[Required]
public DateTime Date { get; set; }
[Required]
public int SpecializationId { get; set; }
public virtual Specialization Specialization { get; set; } = new();
[Required]
public int UserId { get; set; }
public virtual User User { get; set; } = new();
[ForeignKey("CaseId")]
public virtual List<Hearing> Hearings { get; set; } = new();
[ForeignKey("CaseId")]
public virtual List<CaseLawyer> Lawyers { get; set; } = new();
[ForeignKey("CaseId")]
public virtual List<CaseDeal> Deals { get; set; } = new();
public static Case? Create(CaseBindingModel model)
{
if (model == null)
{
return null;
}
return new Case()
{
Id = model.Id,
Name = model.Name,
Applicant = model.Applicant,
Defendant = model.Defendant,
Annotation = model.Annotation,
Date = model.Date,
SpecializationId = model.SpecializationId,
UserId = model.UserId
};
}
public void Update(CaseBindingModel model)
{
if (model == null)
{
return;
}
Name = model.Name;
Annotation = model.Annotation;
Date = model.Date;
}
public CaseViewModel GetViewModel => new()
{
Id = Id,
Name = Name,
Applicant = Applicant,
Defendant = Defendant,
Annotation = Annotation,
Date = Date,
SpecializationId = SpecializationId,
UserId = UserId
};
Dictionary<int, ILawyerModel> ICaseModel.Lawyers => throw new NotImplementedException();
}
}