This commit is contained in:
sofiaivv 2024-05-01 17:18:19 +04:00
commit 68a5cb6d71
24 changed files with 120 additions and 46 deletions

View File

@ -10,5 +10,6 @@ namespace LawCompanyDataModels.Models
string CaseType { get; }
DateTime DateCreate { get; }
DateTime? DateImplement { get; }
}
public int ExecutorId { get; }
}
}

View File

@ -5,5 +5,6 @@
string FIO { get; }
string Phone { get; }
string Email { get; }
}
public int ExecutorId { get; }
}
}

View File

@ -5,5 +5,6 @@
Dictionary<int, IClientModel> VisitClients { get; }
DateTime VisitDate { get; }
int HearingId { get; }
}
public int ExecutorId { get; }
}
}

View File

@ -135,7 +135,8 @@ namespace LawCompanyBusinessLogic.BusinessLogics
Name = element.Name,
DateCreate = element.DateCreate,
Status = element.Status,
CaseClients = element.CaseClients
CaseClients = element.CaseClients,
ExecutorId = element.ExecutorId,
});
return true;

View File

@ -141,7 +141,8 @@ namespace LawCompanyBusinessLogic.BusinessLogics
{
FIO = model.FIO,
Phone = model.Phone,
Email = model.Email
Email = model.Email,
ExecutorId = model.ExecutorId,
});
if (element != null && element.Id != model.Id)

View File

@ -104,7 +104,8 @@ namespace LawCompanyBusinessLogic.BusinessLogics
Id = element.Id,
VisitDate = element.VisitDate,
HearingId = element.HearingId,
VisitClients = element.VisitClients
VisitClients = element.VisitClients,
ExecutorId = element.ExecutorId,
});
return true;

View File

@ -10,9 +10,9 @@
<PackageReference Include="Microsoft.Extensions.Logging" Version="8.0.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\LawCompanyDataModels\LawCompanyDataModels.csproj" />
<ItemGroup>
<ProjectReference Include="..\LawCompanyContracts\LawCompanyContracts.csproj" />
<ProjectReference Include="..\LawCompany\LawCompanyDataModels.csproj" />
</ItemGroup>
</Project>

View File

@ -12,5 +12,6 @@ namespace LawCompanyContracts.BindingModels
public DateTime DateCreate { get; set; }
public DateTime? DateImplement { get; set; }
public Dictionary<int, IClientModel> CaseClients { get; set; } = new();
public int ExecutorId { get; set; }
}
}

View File

@ -8,5 +8,6 @@ namespace LawCompanyContracts.BindingModels
public string FIO { get; set; } = string.Empty;
public string Phone { get; set; } = string.Empty;
public string Email { get; set; } = string.Empty;
public int ExecutorId { get; set; }
}
}

View File

@ -8,5 +8,6 @@ namespace LawCompanyContracts.BindingModels
public DateTime VisitDate { get; set; }
public int HearingId { get; set; }
public Dictionary<int, IClientModel> VisitClients { get; set; } = new();
public int ExecutorId { get; set; }
}
}

View File

@ -7,5 +7,6 @@
public string? CaseType { get; set; }
public DateTime? DateFrom { get; set; }
public DateTime? DateTo { get; set; }
public int? ExecutorId { get; set; }
}
}

View File

@ -6,5 +6,6 @@
public string? FIO { get; set; }
public string? Phone { get; set; }
public string? Email { get; set; }
public int? ExecutorId { get; set; }
}
}

View File

@ -13,5 +13,6 @@ namespace LawCompanyContracts.SearchModels
public DateTime? DateFrom { get; set; }
public DateTime? DateTo { get; set; }
public int? HearingId { get; set; }
public int? ExecutorId { get; set; }
}
}

View File

@ -18,5 +18,6 @@ namespace LawCompanyContracts.ViewModels
[DisplayName("Дата выполнения")]
public DateTime? DateImplement { get; set; }
public Dictionary<int, IClientModel> CaseClients { get; set; } = new();
public int ExecutorId { get; set; }
}
}

View File

@ -12,5 +12,6 @@ namespace LawCompanyContracts.ViewModels
public string Email { get; set; } = string.Empty;
[DisplayName("Телефон клиента")]
public string Phone { get; set; } = string.Empty;
public int ExecutorId { get; set; }
}
}

View File

@ -10,5 +10,6 @@ namespace LawCompanyContracts.ViewModels
public DateTime VisitDate { get; set; }
public int HearingId { get; set; }
public Dictionary<int, IClientModel> VisitClients { get; set; } = new();
public int ExecutorId { get; set; }
}
}

View File

@ -13,23 +13,33 @@ namespace LawCompanyDatabaseImplement.Implements
{
using var context = new LawCompanyDatabase();
return context.Cases.Include(x => x.CaseClients)
.Include(x => x.Clients).ThenInclude(x => x.Client)
.Include(x => x.Clients).ThenInclude(x => x.Client)
.ToList()
.Select(x => x.GetViewModel)
.ToList();
}
public List<CaseViewModel> GetFilteredList(CaseSearchModel model)
{
if (!model.DateFrom.HasValue && !model.DateTo.HasValue)
if (!model.DateFrom.HasValue && !model.DateTo.HasValue
&& !model.ExecutorId.HasValue)
{
return new();
}
if (!model.DateFrom.HasValue || !model.DateTo.HasValue)
if (model.ExecutorId.HasValue)
{
using var context = new LawCompanyDatabase();
return context.Cases
.Include(x => x.Clients).ThenInclude(x => x.Client)
.Where(x => x.ExecutorId == model.ExecutorId).ToList()
.Select(x => x.GetViewModel)
.ToList();
}
else if (!model.DateFrom.HasValue || !model.DateTo.HasValue)
{
using var context = new LawCompanyDatabase();
return context.Cases.Include(x => x.CaseClients)
.Include(x => x.Clients).ThenInclude(x => x.Client)
.Include(x => x.Clients).ThenInclude(x => x.Client)
.Where(x => x.Id == model.Id)
.Select(x => x.GetViewModel).ToList()
.ToList();
@ -46,15 +56,14 @@ namespace LawCompanyDatabaseImplement.Implements
}
public CaseViewModel? GetElement(CaseSearchModel model)
{
if (!model.Id.HasValue && string.IsNullOrEmpty(model.Name))
if (!model.Id.HasValue && !model.ExecutorId.HasValue && string.IsNullOrEmpty(model.Name))
{
return null;
}
using var context = new LawCompanyDatabase();
return context.Cases.Include(x => x.Clients).ThenInclude(x => x.Client)
.FirstOrDefault(x => model.Id.HasValue && x.Id == model.Id)
?.GetViewModel; //имя дела не должно повторяться, уникальное должно быть
?.GetViewModel;
}
public CaseViewModel? Insert(CaseBindingModel model)
{

View File

@ -18,7 +18,7 @@ namespace LawCompanyDatabaseImplement.Implements
public List<ClientViewModel> GetFilteredList(ClientSearchModel model)
{
if (string.IsNullOrEmpty(model.Email) && !model.Id.HasValue && string.IsNullOrEmpty(model.FIO)
&& string.IsNullOrEmpty(model.Phone))
&& string.IsNullOrEmpty(model.Phone) && !model.ExecutorId.HasValue)
{
return new();
}
@ -30,6 +30,22 @@ namespace LawCompanyDatabaseImplement.Implements
.Select(x => x.GetViewModel)
.ToList();
}
else if (model.ExecutorId.HasValue && model.Id.HasValue)
{
using var context = new LawCompanyDatabase();
return context.Clients
.Where(x => x.Id == model.Id)
.Select(x => x.GetViewModel)
.ToList();
}
else if (model.ExecutorId.HasValue)
{
using var context = new LawCompanyDatabase();
return context.Clients
.Where(x => x.ExecutorId == model.ExecutorId)
.Select(x => x.GetViewModel)
.ToList();
}
else
{
using var context = new LawCompanyDatabase();
@ -42,7 +58,7 @@ namespace LawCompanyDatabaseImplement.Implements
public ClientViewModel? GetElement(ClientSearchModel model)
{
if (string.IsNullOrEmpty(model.Email) && !model.Id.HasValue && string.IsNullOrEmpty(model.FIO)
&& string.IsNullOrEmpty(model.Phone))
&& string.IsNullOrEmpty(model.Phone) && !model.ExecutorId.HasValue)
{
return null;
}
@ -50,7 +66,8 @@ namespace LawCompanyDatabaseImplement.Implements
return context.Clients
.FirstOrDefault(x => (!string.IsNullOrEmpty(model.Email)
&& x.Email == model.Email) || (model.Id.HasValue && x.Id == model.Id))
&& x.Email == model.Email) || (model.Id.HasValue && x.Id == model.Id) || (model.ExecutorId.HasValue
&& x.ExecutorId == model.ExecutorId))
?.GetViewModel;
}
public ClientViewModel? Insert(ClientBindingModel model)

View File

@ -13,7 +13,7 @@ namespace LawCompanyDatabaseImplement.Implements
{
using var context = new LawCompanyDatabase();
return context.Visits
.Include(x => x.Clients)
.Include(x => x.Clients)
.ThenInclude(x => x.Client)
.ToList()
.Select(x => x.GetViewModel)
@ -21,38 +21,30 @@ namespace LawCompanyDatabaseImplement.Implements
}
public List<VisitViewModel> GetFilteredList(VisitSearchModel model)
{
if (!model.Id.HasValue && !model.DateFrom.HasValue && !model.DateTo.HasValue
if (!model.Id.HasValue && !model.DateFrom.HasValue && !model.DateTo.HasValue && !model.ExecutorId.HasValue
&& !model.VisitDate.HasValue && !model.HearingId.HasValue)
{
return new();
}
if (!model.DateFrom.HasValue || !model.DateTo.HasValue)
if (model.ExecutorId.HasValue && model.DateFrom.HasValue && model.DateTo.HasValue)
{
using var context = new LawCompanyDatabase();
return context.Visits
.Include(x => x.Clients).ThenInclude(x => x.Client)
.Where(x => x.Id == model.Id)
.Include(x => x.Clients).ThenInclude(x => x.Client)
.Where(x => x.ExecutorId == model.ExecutorId && x.VisitDate >= model.DateFrom && x.VisitDate <= model.DateTo)
.Select(x => x.GetViewModel)
.ToList();
}
else
else if (model.ExecutorId.HasValue)
{
using var context = new LawCompanyDatabase();
return context.Visits
.Include(x => x.Clients).ThenInclude(x => x.Client)
.Where(x => x.VisitDate >= model.DateFrom && x.VisitDate <= model.DateTo)
.Include(x => x.Clients).ThenInclude(x => x.Client)
.Where(x => x.ExecutorId == model.ExecutorId)
.Select(x => x.GetViewModel)
.ToList();
}
}
public List<VisitViewModel> GetFilteredDateList(VisitSearchModel model)
{
if (!model.Id.HasValue && !model.DateFrom.HasValue && !model.DateTo.HasValue)
{
return new();
}
if (!model.DateFrom.HasValue || !model.DateTo.HasValue)
else if (!model.DateFrom.HasValue || !model.DateTo.HasValue)
{
using var context = new LawCompanyDatabase();
return context.Visits
@ -71,16 +63,44 @@ namespace LawCompanyDatabaseImplement.Implements
.ToList();
}
}
public List<VisitViewModel> GetFilteredDateList(VisitSearchModel model)
{
if (!model.Id.HasValue && !model.DateFrom.HasValue && !model.DateTo.HasValue && !model.ExecutorId.HasValue)
{
return new();
}
if (!model.DateFrom.HasValue || !model.DateTo.HasValue)
{
using var context = new LawCompanyDatabase();
return context.Visits
.Include(x => x.Clients).ThenInclude(x => x.Client)
.Where(x => x.Id == model.Id)
.Select(x => x.GetViewModel)
.ToList();
}
else
{
using var context = new LawCompanyDatabase();
return context.Visits
.Include(x => x.Clients).ThenInclude(x => x.Client)
.Where(x => x.VisitDate >= model.DateFrom && x.VisitDate <= model.DateTo)
.Select(x => x.GetViewModel)
.ToList();
}
}
public VisitViewModel? GetElement(VisitSearchModel model)
{
if (!model.Id.HasValue && !model.VisitDate.HasValue && !model.HearingId.HasValue)
if (!model.Id.HasValue && !model.VisitDate.HasValue
&& !model.HearingId.HasValue)
{
return new();
}
using var context = new LawCompanyDatabase();
return context.Visits.Include(x => x.Clients).ThenInclude(x => x.Client)
.FirstOrDefault(x => (model.HearingId.HasValue && x.Hearing == model.HearingId)
|| (model.Id.HasValue && x.Id == model.Id))
.FirstOrDefault(x => (model.HearingId.HasValue && x.HearingId == model.HearingId) || (model.Id.HasValue
&& x.Id == model.Id) || (model.ExecutorId.HasValue
&& x.ExecutorId == model.ExecutorId))
?.GetViewModel;
}
public VisitViewModel? Insert(VisitBindingModel model)

View File

@ -11,8 +11,8 @@
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\LawCompanyDataModels\LawCompanyDataModels.csproj" />
<ProjectReference Include="..\LawCompanyContracts\LawCompanyContracts.csproj" />
<ProjectReference Include="..\LawCompany\LawCompanyDataModels.csproj" />
</ItemGroup>
</Project>

View File

@ -20,6 +20,7 @@ namespace LawCompanyDatabaseImplement.Models
[Required]
public CaseStatus Status { get; private set; }
private Dictionary<int, IClientModel>? _caseClients = null;
public int ExecutorId { get; set; }
[NotMapped]
public Dictionary<int, IClientModel> CaseClients
@ -38,8 +39,6 @@ namespace LawCompanyDatabaseImplement.Models
}
[ForeignKey("CaseId")]
public virtual List<CaseClient> Clients { get; set; } = new();
[ForeignKey("CaseId")]
public virtual List<Hearing> Hearings { get; set; } = new();
public static Case Create(LawCompanyDatabase context, CaseBindingModel model)
{
if (model == null)
@ -53,6 +52,7 @@ namespace LawCompanyDatabaseImplement.Models
DateCreate = model.DateCreate,
DateImplement = model.DateImplement,
Status = model.Status,
ExecutorId = model.ExecutorId,
Clients = model.CaseClients.Select(x => new CaseClient
{
Client = context.Clients.First(y => y.Id == x.Key)
@ -72,7 +72,6 @@ namespace LawCompanyDatabaseImplement.Models
if (model.DateImplement.HasValue) DateImplement = model.DateImplement;
if (!model.CompanyId.HasValue) CompanyId = model.CompanyId;
}
public CaseViewModel GetViewModel => new()
{
@ -81,6 +80,7 @@ namespace LawCompanyDatabaseImplement.Models
CaseType = CaseType,
DateCreate = DateCreate,
DateImplement = DateImplement,
ExecutorId = ExecutorId,
Status = Status,
CaseClients = CaseClients,
};

View File

@ -19,6 +19,7 @@ namespace LawCompanyDatabaseImplement.Models
public virtual List<CaseClient> CaseClients { get; set; } = new();
[ForeignKey("ClientId")]
public virtual List<VisitClient> ClientVisits { get; set; } = new();
public int ExecutorId { get; set; }
public static Client? Create(ClientBindingModel? model)
{
@ -32,6 +33,7 @@ namespace LawCompanyDatabaseImplement.Models
FIO = model.FIO,
Email = model.Email,
Phone = model.Phone,
ExecutorId = model.ExecutorId,
};
}
public static Client Create(ClientViewModel model)
@ -42,6 +44,7 @@ namespace LawCompanyDatabaseImplement.Models
FIO = model.FIO,
Email = model.Email,
Phone = model.Phone,
ExecutorId = model.ExecutorId,
};
}
public void Update(ClientBindingModel? model)
@ -60,6 +63,7 @@ namespace LawCompanyDatabaseImplement.Models
FIO = FIO,
Email = Email,
Phone = Phone,
ExecutorId = ExecutorId,
};
}
}

View File

@ -2,6 +2,7 @@
using LawCompanyContracts.BindingModels;
using LawCompanyContracts.ViewModels;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
namespace LawCompanyDatabaseImplement.Models
{
@ -15,6 +16,13 @@ namespace LawCompanyDatabaseImplement.Models
[Required]
public string Password { get; private set; } = string.Empty;
[ForeignKey("ExecutorId")]
public virtual List<Case> Cases { get; set; } = new();
[ForeignKey("ExecutorId")]
public virtual List<Client> Clients { get; set; } = new();
[ForeignKey("ExecutorId")]
public virtual List<Visit> Visits { get; set; } = new();
public static Executor? Create(ExecutorBindingModel? model)
{
if (model == null)

View File

@ -16,7 +16,7 @@ namespace LawCompanyDatabaseImplement.Models
public int HearingId { get; private set; }
public Hearing Hearing { get; set; } = null!;
//---
public int? CompanyId { get; set; }
public int ExecutorId { get; set; }
private Dictionary<int, IClientModel>? _visitClients = null;
[NotMapped]
@ -37,8 +37,7 @@ namespace LawCompanyDatabaseImplement.Models
}
[ForeignKey("VisitId")]
public virtual List<VisitClient> Clients { get; set; } = new();
public static Visit? Create(LawCompanyDatabase context,
VisitBindingModel? model)
public static Visit? Create(LawCompanyDatabase context, VisitBindingModel? model)
{
if (model == null)
{
@ -54,6 +53,7 @@ namespace LawCompanyDatabaseImplement.Models
Id = model.Id,
VisitDate = model.VisitDate,
HearingId = model.HearingId,
ExecutorId = model.ExecutorId,
Hearing = context.Hearings.First(x => x.Id == model.HearingId),
Clients = model.VisitClients.Select(x => new VisitClient
{
@ -78,7 +78,8 @@ namespace LawCompanyDatabaseImplement.Models
Id = Id,
VisitDate = VisitDate,
HearingId = HearingId,
VisitClients = VisitClients
VisitClients = VisitClients,
ExecutorId = ExecutorId,
};
public void UpdateClients(LawCompanyDatabase context,
VisitBindingModel model)