DatabaseImplement -> Models,

RoleViewModel;
This commit is contained in:
Артём Алейкин 2023-04-07 16:35:57 +04:00
parent 0d95ebcaa0
commit ff005cfc71
14 changed files with 694 additions and 1 deletions

View File

@ -0,0 +1,18 @@
using CaseAccountingDataModels.Models;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace CaseAccountingContracts.ViewModels
{
public class RoleViewModel : IRoleModel
{
public int Id { get; set; }
[DisplayName("Название роли")]
public string Name { get; set; } = string.Empty;
}
}

View File

@ -8,7 +8,11 @@
<ItemGroup>
<Folder Include="Implements\" />
<Folder Include="Models\" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\CaseAccountingContracts\CaseAccountingContracts.csproj" />
<ProjectReference Include="..\CaseAccountingDataModels\CaseAccountingDataModels.csproj" />
</ItemGroup>
</Project>

View File

@ -0,0 +1,91 @@
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
};
}
}

View File

@ -0,0 +1,22 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace CaseAccountingDataBaseImplement.Models
{
public class CaseDeal
{
public int Id { get; set; }
[Required]
public int CaseId { get; set; }
public virtual Case Case { get; set; } = new();
[Required]
public int DealId { get; set; }
public virtual Deal Deal { get; set; } = new();
}
}

View File

@ -0,0 +1,22 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace CaseAccountingDataBaseImplement.Models
{
public class CaseLawyer
{
public int Id { get; set; }
[Required]
public int CaseId { get; set; }
public virtual Case Case { get; set; } = new();
[Required]
public int LawyerId { get; set; }
public virtual Lawyer Lawyer { get; set; } = new();
}
}

View File

@ -0,0 +1,73 @@
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.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace CaseAccountingDataBaseImplement.Models
{
public class Contract : IContractModel
{
public int Id { get; set; }
[Required]
public string Service { get; set; } = string.Empty;
[Required]
public decimal Coast { get; set; }
[Required]
public DateTime Date { get; set; }
[Required]
public int UserId { get; set; }
[ForeignKey("ContractId")]
public virtual List<LawyerContracts> LawyerContracts { get; set; } = new();
[ForeignKey("ContractId")]
public virtual List<DealContract> DealContracts { get; set; } = new();
public static Contract? Create(ContractBindingModel? model)
{
if (model == null)
{
return null;
}
return new Contract()
{
Id = model.Id,
Service = model.Service,
Coast = model.Coast,
Date = model.Date,
UserId = model.UserId
};
}
public void Update(ContractBindingModel? model)
{
if (model == null)
{
return;
}
Service = model.Service;
Coast = model.Coast;
Date = model.Date;
}
public ContractViewModel GetViewModel => new()
{
Id = Id,
Service = Service,
Coast = Coast,
Date = Date,
UserId = UserId
};
}
}

View File

@ -0,0 +1,72 @@
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 Deal : IDealModel
{
public int Id { get; set; }
[Required]
public string Subject { get; set; } = string.Empty;
[Required]
public string Responsibilities { get; set; } = string.Empty;
[Required]
public DateTime Date { get; set; }
[Required]
public int UserId { get; set; }
[ForeignKey("DealId")]
public virtual List<CaseDeal> CaseDeals { get; set; } = new();
[ForeignKey("DealId")]
public virtual List<DealContract> Contracts { get; set; } = new();
public static Deal? Create(DealBindingModel? model)
{
if (model == null)
{
return null;
}
return new Deal()
{
Id = model.Id,
Subject = model.Subject,
Responsibilities = model.Responsibilities,
Date = model.Date,
UserId = model.UserId,
};
}
public void Update(DealBindingModel? model)
{
if (model == null)
{
return;
}
Subject = model.Subject;
Responsibilities = model.Responsibilities;
Date = model.Date;
}
public DealViewModel GetViewModel => new()
{
Id = Id,
Subject = Subject,
Responsibilities = Responsibilities,
Date = Date,
UserId = UserId
};
}
}

View File

@ -0,0 +1,22 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace CaseAccountingDataBaseImplement.Models
{
public class DealContract
{
public int Id { get; set; }
[Required]
public int DealId { get; set; }
public virtual Deal Deal { get; set; } = new();
[Required]
public int ContractId { get; set; }
public virtual Contract Contract { get; set; } = new();
}
}

View File

@ -0,0 +1,67 @@
using CaseAccountingContracts.BindingModels;
using CaseAccountingContracts.ViewModels;
using CaseAccountingDataModels.Models;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace CaseAccountingDataBaseImplement.Models
{
public class Hearing : IHearingModel
{
public int Id { get; set; }
[Required]
public string Information { get; set; } = string.Empty;
[Required]
public DateTime Date { get; set; }
[Required]
public int CaseId { get; set; }
public virtual Case Case { get; set; } = new();
[Required]
public int UserId { get; set; }
public virtual User User { get; set; } = new();
public static Hearing? Create (HearingBindingModel? model)
{
if (model == null)
{
return null;
}
return new Hearing()
{
Id = model.Id,
Information = model.Information,
Date = model.Date,
CaseId = model.CaseId,
UserId = model.UserId
};
}
public void Update (HearingBindingModel? model)
{
if (model == null)
{
return;
}
Information = model.Information;
Date = model.Date;
}
public HearingViewModel GetViewModel => new()
{
Id = Id,
Information = Information,
Date = Date,
CaseId = CaseId,
UserId = UserId
};
}
}

View File

@ -0,0 +1,86 @@
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 Lawyer : ILawyerModel
{
public int Id { get; set; }
[Required]
public string Name { get; set; } = string.Empty;
[Required]
public string Surname { get; set; } = string.Empty;
[Required]
public string Patronymic { get; set; } = string.Empty;
[Required]
public int Experience { 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("LawyerId")]
public virtual List<CaseLawyer> CaseLawyers { get; set; } = new();
[ForeignKey("LawyerId")]
public virtual List<LawyerContracts> Contracts { get; set; } = new();
public static Lawyer? Create(LawyerBindingModel? model)
{
if (model == null)
{
return null;
}
return new Lawyer()
{
Id = model.Id,
Name = model.Name,
Surname = model.Surname,
Patronymic = model.Patronymic,
Experience = model.Experience,
SpecializationId = model.SpecializationId,
UserId = model.UserId
};
}
public void Update(LawyerBindingModel? model)
{
if (model == null)
{
return;
}
Name = model.Name;
Surname = model.Surname;
Patronymic = model.Patronymic;
Experience = model.Experience;
SpecializationId = model.SpecializationId;
}
public LawyerViewModel GetViewModel => new()
{
Id = Id,
Name = Name,
Surname = Surname,
Patronymic = Patronymic,
Experience = Experience,
SpecializationId = SpecializationId,
UserId = UserId
};
}
}

View File

@ -0,0 +1,22 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace CaseAccountingDataBaseImplement.Models
{
public class LawyerContracts
{
public int Id { get; set; }
[Required]
public int LawyerId { get; set; }
public virtual Lawyer Lawyer { get; set; } = new();
[Required]
public int ContractId { get; set; }
public virtual Contract Contract { get; set; } = new();
}
}

View File

@ -0,0 +1,53 @@
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;
using System.Threading.Tasks.Dataflow;
namespace CaseAccountingDataBaseImplement.Models
{
public class Role : IRoleModel
{
public int Id { get; set; }
[Required]
public string Name { get; set; } = string.Empty;
[ForeignKey("RoleId")]
public virtual List<User> Users { get; set; } = new();
public static Role? Create(RoleBindingModel? model)
{
if (model == null)
{
return null;
}
return new Role()
{
Id = model.Id,
Name = model.Name,
};
}
public void Update(RoleBindingModel? model)
{
if (model == null)
{
return;
}
Name = model.Name;
}
public RoleViewModel GetViewModel => new()
{
Id = Id,
Name = Name,
};
}
}

View File

@ -0,0 +1,63 @@
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.Security.Cryptography.X509Certificates;
using System.Text;
using System.Threading.Tasks;
namespace CaseAccountingDataBaseImplement.Models
{
public class Specialization : ISpecializationModel
{
public int Id { get; set; }
[Required]
public string Name { get; set; } = string.Empty;
[Required]
public int UserId { get; set; }
public virtual User User { get; set; } = new();
[ForeignKey("SpecializationId")]
public virtual List<Lawyer> Lawyers { get; set; } = new();
[ForeignKey("SpecializationId")]
public virtual List<Case> Cases { get; set; } = new();
public static Specialization? Create (SpecializationBindingModel? model)
{
if (model == null)
{
return null;
}
return new Specialization()
{
Id = model.Id,
Name = model.Name,
UserId = model.UserId,
};
}
public void Update(SpecializationBindingModel? model)
{
if (model == null)
{
return;
}
Name = model.Name;
}
public SpecializationViewModel GetViewModel => new()
{
Id = Id,
Name = Name,
UserId = UserId
};
}
}

View File

@ -0,0 +1,78 @@
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,
};
}
}