This commit is contained in:
dimazhelovanov 2023-05-24 17:44:09 +04:00
parent a3cdfef49d
commit c8f23dc834
10 changed files with 60 additions and 38 deletions

View File

@ -127,7 +127,10 @@ namespace LawFirmBusinessLogic.BusinessLogics
return false;
}
if(element.CaseClients.ContainsKey(client.Id))
{
return false;
}
element.CaseClients[client.Id] = client;
_caseStorage.Update(new()

View File

@ -20,10 +20,6 @@
<a asp-controller="Case" asp-action="AddClient">Добавить клиентов к делам</a>
</p>
<br/>
<p>
<a asp-controller="Case" asp-action="AddClient">Добавить клиентов к делам</a>
</p>
<table class="table">
<thead>
<tr>

View File

@ -1,4 +1,5 @@
using LawFirmDataModels.Models;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.ComponentModel;
@ -15,5 +16,12 @@ namespace LawFirmContracts.ViewModels
public double Cost { get; set; }
public int Id { get; set; }
public int? CompanyId { get; set; }
public ConsultationViewModel() { }
[JsonConstructor]
public ConsultationViewModel(Dictionary<int, LawyerViewModel> ConsultationLawyers)
{
this.ConsultationLawyers = ConsultationLawyers.ToDictionary(x => x.Key, x => x.Value as ILawyerModel);
}
}
}

View File

@ -98,7 +98,7 @@ namespace LawFirmDatabaseImplement.Implements
}
catch
{
transaction.Rollback();
throw;
}
}

View File

@ -17,11 +17,11 @@ namespace LawFirmDatabaseImplement
if (optionsBuilder.IsConfigured == false)
{
// optionsBuilder.UseSqlServer(@"Data Source=DESKTOP-ON2V3BB\SQLEXPRESS;Initial Catalog=LawFirmDatabase;
//Integrated Security=True;MultipleActiveResultSets=True;;TrustServerCertificate=True");
optionsBuilder.UseSqlServer(@"Data Source=DESKTOP-ON2V3BB\SQLEXPRESS;Initial Catalog=LawFirmDatabase;
Integrated Security=True;MultipleActiveResultSets=True;;TrustServerCertificate=True");
optionsBuilder.UseSqlServer(@"Data Source=DESKTOP-7A1PHA0\SQLEXPRESS;Initial Catalog=LawFirmDatabase;
Integrated Security=True;MultipleActiveResultSets=True;;TrustServerCertificate=True");
/* optionsBuilder.UseSqlServer(@"Data Source=DESKTOP-7A1PHA0\SQLEXPRESS;Initial Catalog=LawFirmDatabase;
Integrated Security=True;MultipleActiveResultSets=True;;TrustServerCertificate=True");*/
}
base.OnConfiguring(optionsBuilder);
}

View File

@ -111,16 +111,18 @@ namespace LawFirmDatabaseImplement.Models
var _case = context.Cases.First(x => x.Id == Id);
foreach (var pc in model.CaseClients)
{
context.CaseClients.Add(new CaseClient
if (!CaseClients.ContainsKey(pc.Key))
{
Case = _case,
Client = context.Clients.First(x => x.Id == pc.Key),
});
context.SaveChanges();
context.CaseClients.Add(new CaseClient
{
Case = _case,
Client = context.Clients.First(x => x.Id == pc.Key),
});
}
context.SaveChanges();
}

View File

@ -26,9 +26,11 @@ namespace LawFirmDatabaseImplement.Models
{
if (_consultationLawyers == null)
{
_consultationLawyers = Lawyers
.ToDictionary(recPC => recPC.LawyerId, recPC => recPC.Lawyer as ILawyerModel);
}
using var context = new LawFirmDatabase();
_consultationLawyers = Lawyers
.ToDictionary(x => x.LawyerId, x => (context.Lawyers
.FirstOrDefault(y => y.Id == x.LawyerId) as ILawyerModel));
}
return _consultationLawyers;
}
}
@ -66,7 +68,8 @@ namespace LawFirmDatabaseImplement.Models
{
Id = Id,
Cost = Cost,
CompanyId = CompanyId
CompanyId = CompanyId,
ConsultationLawyers = ConsultationLawyers
};
public void UpdateLawyers(LawFirmDatabase context,
ConsultationBindingModel model)
@ -82,11 +85,14 @@ namespace LawFirmDatabaseImplement.Models
var _consult = context.Consultations.First(x => x.Id == Id);
foreach (var pc in model.ConsultationLawyers)
{
context.ConsultationLawyers.Add(new ConsultationLawyer
if (!ConsultationLawyers.ContainsKey(pc.Key))
{
Consultation = _consult,
Lawyer = context.Lawyers.First(x => x.Id == pc.Key),
});
context.ConsultationLawyers.Add(new ConsultationLawyer
{
Consultation = _consult,
Lawyer = context.Lawyers.First(x => x.Id == pc.Key),
});
}
context.SaveChanges();
}
_consult = null;

View File

@ -81,7 +81,9 @@ namespace LawFirmDatabaseImplement.Models
HearingDate = HearingDate,
Court = Court,
Judge = Judge,
CompanyId = CompanyId
CompanyId = CompanyId,
HearingLawyers = HearingLawyers
};
public void UpdateLawyers(LawFirmDatabase context,
HearingBindingModel model)
@ -97,11 +99,14 @@ namespace LawFirmDatabaseImplement.Models
var _hear = context.Hearings.First(x => x.Id == Id);
foreach (var pc in model.HearingLawyers)
{
context.HearingLawyers.Add(new HearingLawyer
if (!HearingLawyers.ContainsKey(pc.Key))
{
Hearing = _hear,
Lawyer = context.Lawyers.First(x => x.Id == pc.Key),
});
context.HearingLawyers.Add(new HearingLawyer
{
Hearing = _hear,
Lawyer = context.Lawyers.First(x => x.Id == pc.Key),
});
}
context.SaveChanges();
}
_hearingLawyers = null;

View File

@ -100,12 +100,14 @@ namespace LawFirmDatabaseImplement.Models
var _visit = context.Visits.First(x => x.Id == Id);
foreach (var pc in model.VisitClients)
{
context.VisitClients.Add(new VisitClient
if (!VisitClients.ContainsKey(pc.Key))
{
Visit = _visit,
Client = context.Clients.First(x => x.Id == pc.Key),
});
VisitClients.Add(model.Id, context.Clients.First(x => x.Id == pc.Key));
context.VisitClients.Add(new VisitClient
{
Visit = _visit,
Client = context.Clients.First(x => x.Id == pc.Key),
});
}
context.SaveChanges();
}
_visitClients = null;

View File

@ -26,7 +26,7 @@ builder.Services.AddTransient<IConsultationStorage, ConsultationStorage>();
builder.Services.AddTransient<ILawyerStorage, LawyerStorage>();
builder.Services.AddTransient<IHearingStorage, HearingStorage>();
builder.Services.AddTransient<IClientModel, ClientBindingModel>();
builder.Services.AddTransient<ICaseLogic, CaseLogic>();
builder.Services.AddTransient<IVisitLogic, VisitLogic>();
builder.Services.AddTransient<IClientLogic, ClientLogic>();