консультации заработали

This commit is contained in:
a.puchkina 2024-05-30 02:16:12 +04:00
parent 27966925d0
commit c8483118d5
4 changed files with 46 additions and 20 deletions

View File

@ -9,16 +9,16 @@ namespace LawFirmDatabaseImplement.Models
{
public class Case : ICaseModel
{
public int Id { get; private set; }
public int Id { get; set; }
[Required]
public string Name { get; private set; } = String.Empty;
public string Name { get; set; } = String.Empty;
[Required]
public string CaseType { get; private set; } = String.Empty;
public string CaseType { get; set; } = String.Empty;
[Required]
public DateTime DateCreate { get; private set; }
public DateTime? DateImplement { get; private set; }
public DateTime DateCreate { get; set; }
public DateTime? DateImplement { get; set; }
[Required]
public CaseStatus Status { get; private set; }
public CaseStatus Status { get; set; }
private Dictionary<int, IClientModel>? _caseClients = null;
public int ExecutorId { get; set; }

View File

@ -8,14 +8,14 @@ namespace LawFirmDatabaseImplement.Models
{
public class Consultation : IConsultationModel
{
public int Id { get; private set; }
public int Id { get; set; }
[Required]
public double Cost { get; private set; }
public double Cost { get; set; }
[Required]
public DateTime ConsultationDate { get; private set; }
public DateTime ConsultationDate { get; set; }
[Required]
public int CaseId { get; private set; }
public Case Case { get; private set; }
public int CaseId { get; set; }
public virtual Case Case { get; set; }
public int GuarantorId { get; set; }
private Dictionary<int, ILawyerModel>? _consultationLawyers = null;
@ -42,11 +42,11 @@ namespace LawFirmDatabaseImplement.Models
{
return null;
}
var consultations = context.Consultations.Where(x => x.CaseId == model.CaseId).ToList();
/*var consultations = context.Consultations.Where(x => x.CaseId == model.CaseId).ToList();
if (consultations.Count > 0)
{
return null;
}
}*/
return new Consultation()
{
Id = model.Id,
@ -80,6 +80,7 @@ namespace LawFirmDatabaseImplement.Models
Cost = Cost,
ConsultationDate = ConsultationDate,
CaseId = CaseId,
CaseName = Case?.Name ?? string.Empty,
GuarantorId = GuarantorId,
ConsultationLawyers = ConsultationLawyers
};

View File

@ -1,4 +1,5 @@
using LawFirmContracts.BindingModels;
using LawFimDataModels.Models;
using LawFirmContracts.BindingModels;
using LawFirmContracts.SearchModels;
using LawFirmContracts.ViewModels;
using Microsoft.AspNetCore.Mvc;
@ -43,23 +44,34 @@ namespace LawFirmGuarantorApp.Controllers
[HttpGet]
public IActionResult CreateConsultation()
{
ViewBag.Cases = APIClient.GetRequest<List<CaseViewModel>>($"api/case/getcaselist?executorId={APIClient.Guarantor.Id}");
ViewBag.Cases = APIClient.GetRequest<List<CaseViewModel>>($"api/case/getcaselist?executorId=1");
return View();
}
[HttpPost]
public void CreateConsultation(int cost, DateTime date)
public void CreateConsultation(int cost, DateTime consultationDate, int caseId, List<int> lawyers)
{
if (APIClient.Guarantor == null)
{
throw new Exception("Вы как суда попали? Суда вход только авторизованным");
}
if (cost <= 0)
{
throw new Exception("За бесплатно не отдаем!");
}
Dictionary<int, ILawyerModel> a = new Dictionary<int, ILawyerModel>();
foreach (int lawyer in lawyers)
{
a.Add(lawyer, new LawyerSearchModel { Id = lawyer } as ILawyerModel);
}
APIClient.PostRequest("api/consultation/createconsultation", new
ConsultationBindingModel
{
GuarantorId = APIClient.Guarantor.Id,
ConsultationDate = date,
ConsultationDate = consultationDate,
Cost = cost,
CaseId = caseId,
ConsultationLawyers = a
});
Response.Redirect("/Home/Consultations");
@ -70,12 +82,21 @@ namespace LawFirmGuarantorApp.Controllers
return View();
}
[HttpPost]
public void UpdateConsultation(int id, int cost, DateTime date)
public void UpdateConsultation(int id, int cost, DateTime date, List<int> lawyers)
{
if (APIClient.Guarantor == null)
{
throw new Exception("Вы как суда попали? Суда вход только авторизованным");
}
if (cost <= 0)
{
throw new Exception("За бесплатно не отдаем!");
}
Dictionary<int, ILawyerModel> a = new Dictionary<int, ILawyerModel>();
foreach (int lawyer in lawyers)
{
a.Add(lawyer, new LawyerSearchModel { Id = lawyer } as ILawyerModel);
}
APIClient.PostRequest("api/consultation/updateconsultation", new
ConsultationBindingModel
@ -83,8 +104,8 @@ namespace LawFirmGuarantorApp.Controllers
Id = id,
GuarantorId = APIClient.Guarantor.Id,
ConsultationDate = date,
Cost = cost
Cost = cost,
ConsultationLawyers = a
});
Response.Redirect("/Home/Consultations");
}

View File

@ -51,6 +51,10 @@
</td>
<td>
@Html.DisplayFor(modelItem =>
item.ConsultationDate)
</td>
<td>
@Html.DisplayFor(modelItem =>
item.CaseName)
</td>
<td>