Case_accounting/CaseAccounting/CaseAccountingDataBaseImplement/Models/Case.cs
2023-04-07 16:35:57 +04:00

92 lines
2.4 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; }
[Required]
public int UserId { get; set; }
[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
};
}
}