diff --git a/LawCompany/LawCompanyBusinessLogic/BusinessLogics/ConsultationLogic.cs b/LawCompany/LawCompanyBusinessLogic/BusinessLogics/ConsultationLogic.cs index 3049397..9dab3af 100644 --- a/LawCompany/LawCompanyBusinessLogic/BusinessLogics/ConsultationLogic.cs +++ b/LawCompany/LawCompanyBusinessLogic/BusinessLogics/ConsultationLogic.cs @@ -72,6 +72,7 @@ namespace LawCompanyBusinessLogic.BusinessLogics return list; } + public bool Update(ConsultationBindingModel model) { CheckModel(model); @@ -124,8 +125,7 @@ namespace LawCompanyBusinessLogic.BusinessLogics { throw new ArgumentNullException("Не поставлено время", nameof(model.ConsultationDate)); } - - _logger.LogInformation("Consultation. ConsultationDate:{ConsultationDate}. Id: {Id} ", model.ConsultationDate, model.Id); + _logger.LogInformation("Consultation.ConsultationDate: { ConsultationDate}. Id: {Id} ", model.ConsultationDate, model.Id); var element = _consultationStorage.GetElement(new ConsultationSearchModel { ConsultationDate = model.ConsultationDate diff --git a/LawCompany/LawCompanyBusinessLogic/BusinessLogics/ReportLogicExecutor.cs b/LawCompany/LawCompanyBusinessLogic/BusinessLogics/ReportLogicExecutor.cs index 3b40b0e..895bb43 100644 --- a/LawCompany/LawCompanyBusinessLogic/BusinessLogics/ReportLogicExecutor.cs +++ b/LawCompany/LawCompanyBusinessLogic/BusinessLogics/ReportLogicExecutor.cs @@ -7,13 +7,12 @@ using LawCompanyContracts.StoragesContracts; using LawCompanyContracts.ViewModels; using LawCompanyDatabaseImplement.Models; using LawCompanyDatabaseImplement.Implements; +using DocumentFormat.OpenXml.Office2010.Excel; namespace HotelBusinessLogic.BusinessLogics { public class ReportLogicExecutor : IReportExecutorLogic { - private readonly IHearingStorage _hearingStorage; - private readonly ILawyerStorage _lawyerStorage; private readonly IVisitStorage _visitStorage; private readonly IConsultationStorage _consultationStorage; private readonly ICaseStorage _caseStorage; @@ -22,12 +21,10 @@ namespace HotelBusinessLogic.BusinessLogics private readonly AbstractSaveToWordExecutor _saveToWord; private readonly AbstractSaveToPdfExecutor _saveToPdf; - public ReportLogicExecutor(IHearingStorage hearingStorage, ILawyerStorage lawyerStorage, + public ReportLogicExecutor( IVisitStorage visitStorage, IConsultationStorage consultationStorage, ICaseStorage caseStorage, IClientStorage clientStorage, AbstractSaveToExcelExecutor saveToExcel, AbstractSaveToWordExecutor saveToWord, AbstractSaveToPdfExecutor saveToPdf) { - _hearingStorage = hearingStorage; - _lawyerStorage = lawyerStorage; _visitStorage = visitStorage; _consultationStorage = consultationStorage; _clientStorage = clientStorage; @@ -37,138 +34,134 @@ namespace HotelBusinessLogic.BusinessLogics _saveToPdf = saveToPdf; } - public List GetClientHearing(List Ids) - { - if (Ids == null || !Ids.Any()) - { - return new List(); - } + public List GetClientHearing(List ids) + { + var cases = _caseStorage.GetFullList(); + var consultations = _consultationStorage.GetFullList(); - var clients = _clientStorage.GetFullList(); - var hearings = _hearingStorage.GetFullList(); - var visits = _visitStorage.GetFullList(); + var list = new List(); - var filteredClients = clients.Where(c => Ids.Contains(c.Id)).ToList(); - var result = new List(); - - foreach (var client in filteredClients) - { - var record = new ReportClientHearingViewModel - { - FIO = client.FIO, - Hearing = new List>() - }; - - var clientVisits = visits.Where(v => v.VisitClients.ContainsKey(client.Id)).ToList(); - foreach (var visit in clientVisits) - { - if (visit.HearingId.HasValue) - { - var hearing = hearings.FirstOrDefault(h => h.Id == visit.HearingId.Value); - if (hearing != null) - { - record.Hearing.Add(new Tuple(hearing.Judge, hearing.HearingDate)); - } - } - } - - result.Add(record); - } - - return result; - } - - public List GetClients(ReportExecutorBindingModel model) - { - var listAll = new List(); - - // Получаем список всех дел для указанного исполнителя и за указанный период - var cases = _caseStorage.GetFilteredList(new CaseSearchModel + foreach (var id in ids) { - ExecutorId = model.ExecutorId, - DateFrom = model.DateFrom, - DateTo = model.DateTo - }); + var clients = _clientStorage.GetFilteredList(new ClientSearchModel { Id = id }); - // Добавляем информацию о клиентах из дел - foreach (var _case in cases) - { - foreach (var cc in _case.CaseClients.Values) + if (clients.Count == 0) + continue; + + var client = clients.First(); + var record = new ReportClientHearingViewModel { - listAll.Add(new ReportClientsViewModel + FIO = client.FIO, + Hearing = new List>() + }; + + foreach (var cas in cases) + { + if (!cas.CaseClients.ContainsKey(client.Id)) { - FIO = cc.FIO, - Name = _case.Name, - Status = _case.Status - }); + foreach (var cons in consultations) + { + if (cons.CaseId.Equals(cas.Id)) + { + record.Hearing.Add(new Tuple(cas.Name, cons.ConsultationDate)); + } + } + } } + list.Add(record); } - // Получаем список всех консультаций для указанного исполнителя и за указанный период - var consultations = _consultationStorage.GetFilteredList(new ConsultationSearchModel - { - GuarantorId = model.ExecutorId, - DateFrom = model.DateFrom, - DateTo = model.DateTo - }); - - // Добавляем информацию о клиентах из консультаций - foreach (var consultation in consultations) - { - foreach (var cc in consultation.Case.CaseClients.Values) - { - listAll.Add(new ReportClientsViewModel - { - FIO = cc.FIO, - ConsultationDate = consultation.ConsultationDate, - Cost = consultation.Cost - }); - } - } - - return listAll; + return list; } - public void SaveClientHearingToExcelFile(ReportExecutorBindingModel model) - { - _saveToExcel.CreateReport(new ExcelInfoExecutor - { - FileName = model.FileName, - Title = "Список слушаний", - ClientHearings = GetClientHearing(model.Ids) - }); - } + public List GetClients(ReportExecutorBindingModel model) + { + var list = new List(); + var clients = _clientStorage.GetFilteredList(new ClientSearchModel + { + ExecutorId = model.ExecutorId + }); - public void SaveClientHearingToWordFile(ReportExecutorBindingModel model) - { - _saveToWord.CreateDoc(new WordInfoExecutor - { - FileName = model.FileName, - Title = "Список слушаний", - ClientHearings = GetClientHearing(model.Ids) - }); - } + var visits = _visitStorage.GetFilteredList(new VisitSearchModel + { + DateFrom = model.DateFrom, + DateTo = model.DateTo + }); - public void SaveClientsToPdfFile(ReportExecutorBindingModel model) - { - if (model.DateFrom == null) - { - throw new ArgumentException("Дата начала не задана"); - } + var cases = _caseStorage.GetFilteredList(new CaseSearchModel + { + DateFrom = model.DateFrom, + DateTo = model.DateTo + }); - if (model.DateTo == null) - { - throw new ArgumentException("Дата окончания не задана"); - } - _saveToPdf.CreateDoc(new PdfInfoExecutor - { - FileName = model.FileName, - Title = "Список клиентов", - DateFrom = model.DateFrom!.Value, - DateTo = model.DateTo!.Value, - Clients = GetClients(model) - }); - } - } + foreach (var client in clients) + { + var record = new ReportClientsViewModel + { + FIO = client.FIO, + CaseName = new List(), + VisitDate = new List() + }; + + foreach (var cas in cases) + { + if (!cas.CaseClients.ContainsKey(client.Id)) + { + record.CaseName.Add(cas.Name); + } + } + foreach (var vis in visits) + { + if (!vis.VisitClients.ContainsKey(client.Id)) + { + record.VisitDate.Add(vis.VisitDate); + } + } + list.Add(record); + } + return list; + } + + public void SaveClientHearingToExcelFile(ReportExecutorBindingModel model) + { + _saveToExcel.CreateReport(new ExcelInfoExecutor + { + FileName = model.FileName, + Title = "Список дел", + ClientHearings = GetClientHearing(model.Ids) + }); + } + + public void SaveClientHearingToWordFile(ReportExecutorBindingModel model) + { + _saveToWord.CreateDoc(new WordInfoExecutor + { + FileName = model.FileName, + Title = "Список дел", + ClientHearings = GetClientHearing(model.Ids) + }); + } + + public void SaveClientsToPdfFile(ReportExecutorBindingModel model) + { + if (model.DateFrom == null) + { + throw new ArgumentException("Дата начала не задана"); + } + + if (model.DateTo == null) + { + throw new ArgumentException("Дата окончания не задана"); + } + _saveToPdf.CreateDoc(new PdfInfoExecutor + { + FileName = model.FileName, + Title = "Список клиентов", + DateFrom = model.DateFrom!.Value, + DateTo = model.DateTo!.Value, + Clients = GetClients(model) + }); + } + } } diff --git a/LawCompany/LawCompanyBusinessLogic/BusinessLogics/ReportLogicGuarantor.cs b/LawCompany/LawCompanyBusinessLogic/BusinessLogics/ReportLogicGuarantor.cs index 0866279..66ce971 100644 --- a/LawCompany/LawCompanyBusinessLogic/BusinessLogics/ReportLogicGuarantor.cs +++ b/LawCompany/LawCompanyBusinessLogic/BusinessLogics/ReportLogicGuarantor.cs @@ -6,56 +6,182 @@ using LawCompanyContracts.SearchModels; using LawCompanyContracts.StoragesContracts; using LawCompanyContracts.ViewModels; using LawCompanyDatabaseImplement.Models; +using DocumentFormat.OpenXml.Office2010.Excel; +using LawCompanyDatabaseImplement; +using Microsoft.EntityFrameworkCore; namespace LawCompanyBusinessLogic.BusinessLogics { public class ReportLogicGuarantor : IReportGuarantorLogic { - /*private readonly IVisitStorage _visitStorage; - private readonly IClientStorage _clientStorage; - private readonly ICaseStorage _caseStorage; - private readonly IConsultationStorage _consultationStorage; - private readonly IHearingStorage _hearingStorage; - private readonly AbstractSaveToExcelGuarantor _saveToExcel; - private readonly AbstractSaveToWordGuarantor _saveToWord; - private readonly AbstractSaveToPdfGuarantor _saveToPdf; + private readonly IVisitStorage _visitStorage; + private readonly ICaseStorage _caseStorage; + private readonly IConsultationStorage _consultationStorage; + private readonly IHearingStorage _hearingStorage; + private readonly ILawyerStorage _lawyerStorage; + private readonly AbstractSaveToExcelGuarantor _saveToExcel; + private readonly AbstractSaveToWordGuarantor _saveToWord; + private readonly AbstractSaveToPdfGuarantor _saveToPdf; - public ReportLogicGuarantor(IVisitStorage visitStorage, IClientStorage clientStorage, ICaseStorage caseStorage, - IConsultationStorage consultationStorage, IHearingStorage hearingStorage, - AbstractSaveToExcelGuarantor saveToExcel, AbstractSaveToWordGuarantor saveToWord, AbstractSaveToPdfGuarantor saveToPdf) - { - _visitStorage = visitStorage; - _clientStorage = clientStorage; - _caseStorage = caseStorage; - _consultationStorage = consultationStorage; - _hearingStorage = hearingStorage; - _saveToExcel = saveToExcel; - _saveToWord = saveToWord; - _saveToPdf = saveToPdf; - }*/ - public List GetLawyerHearing(List Ids) + public ReportLogicGuarantor(IVisitStorage visitStorage, ICaseStorage caseStorage, + IConsultationStorage consultationStorage, IHearingStorage hearingStorage, ILawyerStorage lawyerStorage, + AbstractSaveToExcelGuarantor saveToExcel, AbstractSaveToWordGuarantor saveToWord, AbstractSaveToPdfGuarantor saveToPdf) { - throw new NotImplementedException(); + _visitStorage = visitStorage; + _caseStorage = caseStorage; + _consultationStorage = consultationStorage; + _hearingStorage = hearingStorage; + _lawyerStorage = lawyerStorage; + _saveToExcel = saveToExcel; + _saveToWord = saveToWord; + _saveToPdf = saveToPdf; + } + + public List GetLawyerHearing(List Ids) + { + if (Ids == null || !Ids.Any()) + { + return new List(); + } + + using var context = new LawCompanyDatabase(); + + var hearings = context.Hearings + .Include(h => h.Lawyers) + .ToList(); + + var visits = context.Visits + .ToList(); + + var hearingLawyers = context.HearingLawyers + .Include(hl => hl.Lawyer) + .Where(hl => Ids.Contains(hl.LawyerId)) + .ToList(); + + var lawyerHearingsDict = hearingLawyers + .GroupBy(hl => hl.HearingId) + .ToDictionary(g => g.Key, g => g.Select(hl => hl.LawyerId).ToList()); + + var list = new List(); + + foreach (var id in Ids) + { + var lawyer = context.Lawyers + .FirstOrDefault(l => l.Id == id); + + if (lawyer == null) + continue; + + var record = new ReportLawyerHearingViewModel + { + FIO = lawyer.FIO, + Visits = new List>() + }; + + foreach (var hearing in hearings) + { + if (lawyerHearingsDict.TryGetValue(hearing.Id, out var lawyerIds) && lawyerIds.Contains(id)) + { + foreach (var visit in visits) + { + record.Visits.Add(new Tuple(hearing.Judge, visit.VisitDate)); + } + } + } + + list.Add(record); + } + + return list; } public List GetLawyers(ReportGuarantorBindingModel model) { - throw new NotImplementedException(); + var list = new List(); + + var consultations = _consultationStorage.GetFilteredList(new ConsultationSearchModel + { + GuarantorId = model.GuarantorId, + DateFrom = model.DateFrom, + DateTo = model.DateTo + }); + + var lawyers = _lawyerStorage.GetFilteredList(new LawyerSearchModel { GuarantorId = model.GuarantorId }); + + var hearings = _hearingStorage.GetFilteredList(new HearingSearchModel + { + GuarantorId = model.GuarantorId, + DateFrom = model.DateFrom, + DateTo = model.DateTo + }); + + foreach (LawyerViewModel lawyer in lawyers) + { + var record = new ReportLawyersViewModel + { + FIO = lawyer.FIO, + Consultation = new List<(DateTime ConsultationDate, double Price)>(), + Hearing = new List<(DateTime HearingDate, string Judge)>() + }; + + foreach (var consultation in consultations) + { + if (!consultation.ConsultationLawyers.ContainsKey(lawyer.Id)) + { + record.Consultation.Add(new(consultation.ConsultationDate, consultation.Cost)); + } + } + foreach (var hearing in hearings) + { + if (!hearing.HearingLawyers.ContainsKey(lawyer.Id)) + { + record.Hearing.Add(new(hearing.HearingDate, hearing.Judge)); + } + } + list.Add(record); + } + return list; } public void SaveLawyerHearingToExcelFile(ReportGuarantorBindingModel model) - { - throw new NotImplementedException(); - } + { + _saveToExcel.CreateReport(new ExcelInfoGuarantor + { + FileName = model.FileName, + Title = "Список слушаний", + LawyerHearings = GetLawyerHearing(model.Ids) + }); + } - public void SaveLawyerHearingToWordFile(ReportGuarantorBindingModel model) - { - throw new NotImplementedException(); - } + public void SaveLawyerHearingToWordFile(ReportGuarantorBindingModel model) + { + _saveToWord.CreateDoc(new WordInfoGuarantor + { + FileName = model.FileName, + Title = "Список слушаний", + LawyerHearings = GetLawyerHearing(model.Ids) + }); + } - public void SaveLawyersToPdfFile(ReportGuarantorBindingModel model) - { - throw new NotImplementedException(); - } - } + public void SaveLawyersToPdfFile(ReportGuarantorBindingModel model) + { + if (model.DateFrom == null) + { + throw new ArgumentException("Дата начала не задана"); + } + + if (model.DateTo == null) + { + throw new ArgumentException("Дата окончания не задана"); + } + _saveToPdf.CreateDoc(new PdfInfoGuarantor + { + FileName = model.FileName, + Title = "Список клиентов", + DateFrom = model.DateFrom!.Value, + DateTo = model.DateTo!.Value, + Lawyers = GetLawyers(model) + }); + } + } } diff --git a/LawCompany/LawCompanyBusinessLogic/OfficePackage/AbstractSaveToExcelGuarantor.cs b/LawCompany/LawCompanyBusinessLogic/OfficePackage/AbstractSaveToExcelGuarantor.cs index cef2220..72e1c56 100644 --- a/LawCompany/LawCompanyBusinessLogic/OfficePackage/AbstractSaveToExcelGuarantor.cs +++ b/LawCompany/LawCompanyBusinessLogic/OfficePackage/AbstractSaveToExcelGuarantor.cs @@ -1,4 +1,6 @@ -using System; +using LawCompanyBusinessLogic.OfficePackage.HelperEnums; +using LawCompanyBusinessLogic.OfficePackage.HelperModels; +using System; using System.Collections.Generic; using System.Linq; using System.Text; @@ -6,7 +8,73 @@ using System.Threading.Tasks; namespace LawCompanyBusinessLogic.OfficePackage { - internal class AbstractSaveToExcelGuarantor + public abstract class AbstractSaveToExcelGuarantor { + public void CreateReport(ExcelInfoGuarantor info) + { + CreateExcel(info); + + InsertCellInWorksheet(new ExcelCellParameters + { + ColumnName = "A", + RowIndex = 1, + Text = info.Title, + StyleInfo = ExcelStyleInfoType.Title + }); + + MergeCells(new ExcelMergeParameters + { + CellFromName = "A1", + CellToName = "C1" + }); + + uint rowIndex = 2; + + foreach (var mc in info.LawyerHearings) + { + InsertCellInWorksheet(new ExcelCellParameters + { + ColumnName = "A", + RowIndex = rowIndex, + Text = mc.FIO, + StyleInfo = ExcelStyleInfoType.Text + }); + + rowIndex++; + + foreach (var conference in mc.Visits) + { + InsertCellInWorksheet(new ExcelCellParameters + { + ColumnName = "B", + RowIndex = rowIndex, + Text = conference.Item1, + StyleInfo = ExcelStyleInfoType.TextWithBroder + }); + + InsertCellInWorksheet(new ExcelCellParameters + { + ColumnName = "C", + RowIndex = rowIndex, + Text = conference.Item2.ToString("d"), + StyleInfo = ExcelStyleInfoType.TextWithBroder + }); + + rowIndex++; + } + + rowIndex++; + } + + SaveExcel(info); + } + + protected abstract void CreateExcel(ExcelInfoGuarantor info); + + protected abstract void InsertCellInWorksheet(ExcelCellParameters excelParams); + + protected abstract void MergeCells(ExcelMergeParameters excelParams); + + protected abstract void SaveExcel(ExcelInfoGuarantor info); } } diff --git a/LawCompany/LawCompanyBusinessLogic/OfficePackage/AbstractSaveToPdfExecutor.cs b/LawCompany/LawCompanyBusinessLogic/OfficePackage/AbstractSaveToPdfExecutor.cs index 0204484..d98e190 100644 --- a/LawCompany/LawCompanyBusinessLogic/OfficePackage/AbstractSaveToPdfExecutor.cs +++ b/LawCompany/LawCompanyBusinessLogic/OfficePackage/AbstractSaveToPdfExecutor.cs @@ -1,85 +1,67 @@ using LawCompanyBusinessLogic.OfficePackage.HelperEnums; using LawCompanyBusinessLogic.OfficePackage.HelperModels; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace LawCompanyBusinessLogic.OfficePackage { - public abstract class AbstractSaveToPdfExecutor - { - public void CreateDoc(PdfInfoExecutor info) - { - CreatePdf(info); + public abstract class AbstractSaveToPdfExecutor + { + public void CreateDoc(PdfInfoExecutor info) + { + CreatePdf(info); + CreateParagraph(new PdfParagraph + { + Text = info.Title, + Style = "NormalTitle", + ParagraphAlignment = PdfParagraphAlignmentType.Center + }); + CreateParagraph(new PdfParagraph + { + Text = $"с{info.DateFrom.ToShortDateString()} по {info.DateTo.ToShortDateString()}", + Style = "Normal", + ParagraphAlignment = PdfParagraphAlignmentType.Center + }); + CreateTable(new List { "2cm", "3cm", "6cm", "3cm" }); + CreateRow(new PdfRowParameters + { + Texts = new List {"Имя клиента", "Дело", "Дата консультации" }, + Style = "NormalTitle", + ParagraphAlignment = PdfParagraphAlignmentType.Center + }); + foreach (var client in info.Clients) + { + CreateRow(new PdfRowParameters + { + Texts = new List { client.FIO, " ", " " }, + Style = "Normal", + ParagraphAlignment = PdfParagraphAlignmentType.Center + }); + foreach (var cas in client.CaseName) + { + CreateRow(new PdfRowParameters + { + Texts = new List { " ", cas, " " }, + Style = "Normal", + ParagraphAlignment = PdfParagraphAlignmentType.Center + }); + } + foreach (var vis in client.VisitDate) + { + CreateRow(new PdfRowParameters + { + Texts = new List { " ", " ", vis.ToShortDateString() }, + Style = "Normal", + ParagraphAlignment = PdfParagraphAlignmentType.Center + }); + } + } - CreateParagraph(new PdfParagraph - { - Text = info.Title, - Style = "NormalTitle", - ParagraphAlignment = PdfParagraphAlignmentType.Center - }); + SavePdf(info); + } - CreateParagraph(new PdfParagraph - { - Text = $"с {info.DateFrom.ToShortDateString()} по {info.DateTo.ToShortDateString()}", - Style = "Normal", - ParagraphAlignment = PdfParagraphAlignmentType.Center - }); - - CreateTable(new List { "4cm", "5cm", "3cm", "4cm", "2cm" }); - - CreateRow(new PdfRowParameters - { - Texts = new List { "ФИО клиента", "Дата консультации", "Стоимость консультации", "Название дела", "Статус дела" }, - Style = "NormalTitle", - ParagraphAlignment = PdfParagraphAlignmentType.Center - }); - - foreach (var member in info.Clients) - { - bool IsDate = true; - if (member.ConsultationDate.ToShortDateString() == "01.01.0001") - { - IsDate = false; - } - - bool IsCost = true; - if (member.Cost.ToString() == "0") - { - IsCost = false; - } - - CreateRow(new PdfRowParameters - { - Texts = new List - { - member.FIO, - IsDate is true ? member.ConsultationDate.ToShortDateString() : string.Empty, - IsCost is true ? member.Cost.ToString() : string.Empty, - member.Name, - member.Status.ToString(), - }, - Style = "Normal", - ParagraphAlignment = PdfParagraphAlignmentType.Left - }); - } - - CreateParagraph(new PdfParagraph - { - Text = $"Итого: {info.Clients.Sum(x => x.Cost)}\t", - Style = "Normal", - ParagraphAlignment = PdfParagraphAlignmentType.Rigth - }); - - SavePdf(info); - } - - protected abstract void CreatePdf(PdfInfoExecutor info); - protected abstract void CreateParagraph(PdfParagraph paragraph); - protected abstract void CreateTable(List columns); - protected abstract void CreateRow(PdfRowParameters rowParameters); - protected abstract void SavePdf(PdfInfoExecutor info); - } + protected abstract void CreatePdf(PdfInfoExecutor info); + protected abstract void CreateParagraph(PdfParagraph paragraph); + protected abstract void CreateTable(List columns); + protected abstract void CreateRow(PdfRowParameters rowParameters); + protected abstract void SavePdf(PdfInfoExecutor info); + } } diff --git a/LawCompany/LawCompanyBusinessLogic/OfficePackage/AbstractSaveToPdfGuarantor.cs b/LawCompany/LawCompanyBusinessLogic/OfficePackage/AbstractSaveToPdfGuarantor.cs index 2607e7b..f3bb35f 100644 --- a/LawCompany/LawCompanyBusinessLogic/OfficePackage/AbstractSaveToPdfGuarantor.cs +++ b/LawCompany/LawCompanyBusinessLogic/OfficePackage/AbstractSaveToPdfGuarantor.cs @@ -1,4 +1,6 @@ -using System; +using LawCompanyBusinessLogic.OfficePackage.HelperEnums; +using LawCompanyBusinessLogic.OfficePackage.HelperModels; +using System; using System.Collections.Generic; using System.Linq; using System.Text; @@ -6,7 +8,93 @@ using System.Threading.Tasks; namespace LawCompanyBusinessLogic.OfficePackage { - internal class AbstractSaveToPdfGuarantor + public abstract class AbstractSaveToPdfGuarantor { + public void CreateDoc(PdfInfoGuarantor info) + { + CreatePdf(info); + + CreateParagraph(new PdfParagraph + { + Text = info.Title, + Style = "NormalTitle", + ParagraphAlignment = PdfParagraphAlignmentType.Center + }); + CreateParagraph(new PdfParagraph + { + Text = $"с{info.DateFrom.ToShortDateString()} по {info.DateTo.ToShortDateString()}", + Style = "Normal", + ParagraphAlignment = PdfParagraphAlignmentType.Center + }); + CreateTable(new List { "3cm", "5cm", "5cm" }); + CreateRow(new PdfRowParameters + { + Texts = new List { "Юрист", "Цена консультации", "Дата консультации" }, + Style = "NormalTitle", + ParagraphAlignment = PdfParagraphAlignmentType.Center + }); + + foreach (var ch in info.Lawyers) + { + CreateRow(new PdfRowParameters + { + Texts = new List { ch.FIO, " ", " " }, + Style = "Normal", + ParagraphAlignment = PdfParagraphAlignmentType.Center + + }); + foreach (var cons in ch.Consultation) + CreateRow(new PdfRowParameters + { + Texts = new List { " ", cons.Price.ToString() + " рублей", cons.ConsultationDate.ToShortDateString() }, + Style = "Normal", + ParagraphAlignment = PdfParagraphAlignmentType.Center + }); + CreateRow(new PdfRowParameters + { + Texts = new List { " ", " ", "Итого: " + ch.Consultation.Count.ToString() }, + Style = "Normal", + ParagraphAlignment = PdfParagraphAlignmentType.Rigth + }); + } + + CreateTable(new List { "3cm", "5cm", "5cm" }); + CreateRow(new PdfRowParameters + { + Texts = new List { "Юрист", "Суд", "Дата слушания" }, + Style = "NormalTitle", + ParagraphAlignment = PdfParagraphAlignmentType.Center + }); + foreach (var ch in info.Lawyers) + { + CreateRow(new PdfRowParameters + { + Texts = new List { ch.FIO, " ", " " }, + Style = "Normal", + ParagraphAlignment = PdfParagraphAlignmentType.Center + + }); + foreach (var hear in ch.Hearing) + CreateRow(new PdfRowParameters + { + Texts = new List { " ", hear.Judge, hear.HearingDate.ToShortDateString() }, + Style = "Normal", + ParagraphAlignment = PdfParagraphAlignmentType.Left + }); + CreateRow(new PdfRowParameters + { + Texts = new List { " ", " ", "Итого: " + ch.Hearing.Count.ToString() }, + Style = "Normal", + ParagraphAlignment = PdfParagraphAlignmentType.Rigth + }); + } + SavePdf(info); + } + + protected abstract void CreatePdf(PdfInfoGuarantor info); + protected abstract void CreateParagraph(PdfParagraph paragraph); + protected abstract void CreateTable(List columns); + protected abstract void CreateRow(PdfRowParameters rowParameters); + protected abstract void SavePdf(PdfInfoGuarantor info); } } diff --git a/LawCompany/LawCompanyBusinessLogic/OfficePackage/AbstractSaveToWordGuarantor.cs b/LawCompany/LawCompanyBusinessLogic/OfficePackage/AbstractSaveToWordGuarantor.cs index 5ef250f..d380ee4 100644 --- a/LawCompany/LawCompanyBusinessLogic/OfficePackage/AbstractSaveToWordGuarantor.cs +++ b/LawCompany/LawCompanyBusinessLogic/OfficePackage/AbstractSaveToWordGuarantor.cs @@ -8,73 +8,55 @@ using System.Threading.Tasks; namespace LawCompanyBusinessLogic.OfficePackage { - public class AbstractSaveToWordGuarantor + public abstract class AbstractSaveToWordGuarantor { - /*public void CreateReport(ExcelInfoGuarantor info) + public void CreateDoc(WordInfoGuarantor info) { - CreateExcel(info); - z - InsertCellInWorksheet(new ExcelCellParameters - { - ColumnName = "A", - RowIndex = 1, - Text = info.Title, - StyleInfo = ExcelStyleInfoType.Title - }); + CreateWord(info); - MergeCells(new ExcelMergeParameters + CreateParagraph(new WordParagraph { - CellFromName = "A1", - CellToName = "C1" - }); - - uint rowIndex = 2; - - foreach (var mc in info.MemberConferences) - { - InsertCellInWorksheet(new ExcelCellParameters + Texts = new List<(string, WordTextProperties)> { (info.Title, new WordTextProperties { Bold = true, Size = "24", }) }, + TextProperties = new WordTextProperties { - ColumnName = "A", - RowIndex = rowIndex, - Text = $"{mc.MemberSurname} {mc.MemberName} {mc.MemberPatronymic}", - StyleInfo = ExcelStyleInfoType.Text + Size = "24", + JustificationType = WordJustificationType.Center + } + }); + + foreach (var mc in info.LawyerHearings) + { + CreateParagraph(new WordParagraph + { + Texts = new List<(string, WordTextProperties)> + { ( mc.FIO, new WordTextProperties { Size = "20", Bold=true})}, + TextProperties = new WordTextProperties + { + Size = "24", + JustificationType = WordJustificationType.Both + } }); - rowIndex++; - - foreach (var conference in mc.ConferenceBookings) + foreach (var conference in mc.Visits) { - InsertCellInWorksheet(new ExcelCellParameters + CreateParagraph(new WordParagraph { - ColumnName = "B", - RowIndex = rowIndex, - Text = conference.Item1, - StyleInfo = ExcelStyleInfoType.TextWithBroder + Texts = new List<(string, WordTextProperties)> + { (conference.Item1 + " - ", new WordTextProperties { Size = "16", Bold=false}), + (conference.Item2.ToShortDateString(), new WordTextProperties { Size = "16", Bold=false})}, + TextProperties = new WordTextProperties + { + Size = "24", + JustificationType = WordJustificationType.Both + } }); - - InsertCellInWorksheet(new ExcelCellParameters - { - ColumnName = "C", - RowIndex = rowIndex, - Text = conference.Item2.ToString("d"), - StyleInfo = ExcelStyleInfoType.TextWithBroder - }); - - rowIndex++; } - - rowIndex++; } - - SaveExcel(info); + SaveWord(info); } - protected abstract void CreateExcel(ExcelInfoOrganiser info); - - protected abstract void InsertCellInWorksheet(ExcelCellParameters excelParams); - - protected abstract void MergeCells(ExcelMergeParameters excelParams); - - protected abstract void SaveExcel(ExcelInfoOrganiser info);*/ + protected abstract void CreateWord(WordInfoGuarantor info); + protected abstract void CreateParagraph(WordParagraph paragraph); + protected abstract void SaveWord(WordInfoGuarantor info); } } diff --git a/LawCompany/LawCompanyBusinessLogic/OfficePackage/HelperModels/ExcelInfoExecutor.cs b/LawCompany/LawCompanyBusinessLogic/OfficePackage/HelperModels/ExcelInfoExecutor.cs index 66b6866..7e5b319 100644 --- a/LawCompany/LawCompanyBusinessLogic/OfficePackage/HelperModels/ExcelInfoExecutor.cs +++ b/LawCompany/LawCompanyBusinessLogic/OfficePackage/HelperModels/ExcelInfoExecutor.cs @@ -9,8 +9,8 @@ namespace LawCompanyBusinessLogic.OfficePackage.HelperModels { public class ExcelInfoExecutor { - public string FileName { get; set; } = string.Empty; - public string Title { get; set; } = string.Empty; - public List ClientHearings { get; set; } = new(); - } + public string FileName { get; set; } = string.Empty; + public string Title { get; set; } = string.Empty; + public List ClientHearings { get; set; } = new(); + } } diff --git a/LawCompany/LawCompanyBusinessLogic/OfficePackage/HelperModels/ExcelInfoGuarantor.cs b/LawCompany/LawCompanyBusinessLogic/OfficePackage/HelperModels/ExcelInfoGuarantor.cs index 0d2e1f4..3516b73 100644 --- a/LawCompany/LawCompanyBusinessLogic/OfficePackage/HelperModels/ExcelInfoGuarantor.cs +++ b/LawCompany/LawCompanyBusinessLogic/OfficePackage/HelperModels/ExcelInfoGuarantor.cs @@ -1,4 +1,5 @@ -using System; +using LawCompanyContracts.ViewModels; +using System; using System.Collections.Generic; using System.Linq; using System.Text; @@ -10,6 +11,6 @@ namespace LawCompanyBusinessLogic.OfficePackage.HelperModels { public string FileName { get; set; } = string.Empty; public string Title { get; set; } = string.Empty; - //public List LawyerHearings { get; set; } = new(); + public List LawyerHearings { get; set; } = new(); } } diff --git a/LawCompany/LawCompanyBusinessLogic/OfficePackage/HelperModels/PdfInfoExecutor.cs b/LawCompany/LawCompanyBusinessLogic/OfficePackage/HelperModels/PdfInfoExecutor.cs index 24bc69a..0dd9d59 100644 --- a/LawCompany/LawCompanyBusinessLogic/OfficePackage/HelperModels/PdfInfoExecutor.cs +++ b/LawCompany/LawCompanyBusinessLogic/OfficePackage/HelperModels/PdfInfoExecutor.cs @@ -13,6 +13,6 @@ namespace LawCompanyBusinessLogic.OfficePackage.HelperModels public string Title { get; set; } = string.Empty; public DateTime DateFrom { get; set; } public DateTime DateTo { get; set; } - public List Clients { get; set; } = new(); - } + public List Clients { get; set; } = new(); + } } diff --git a/LawCompany/LawCompanyBusinessLogic/OfficePackage/HelperModels/PdfInfoGuarantor.cs b/LawCompany/LawCompanyBusinessLogic/OfficePackage/HelperModels/PdfInfoGuarantor.cs index 6d015c0..ea47a77 100644 --- a/LawCompany/LawCompanyBusinessLogic/OfficePackage/HelperModels/PdfInfoGuarantor.cs +++ b/LawCompany/LawCompanyBusinessLogic/OfficePackage/HelperModels/PdfInfoGuarantor.cs @@ -1,4 +1,5 @@ -using System; +using LawCompanyContracts.ViewModels; +using System; using System.Collections.Generic; using System.Linq; using System.Text; @@ -6,7 +7,12 @@ using System.Threading.Tasks; namespace LawCompanyBusinessLogic.OfficePackage.HelperModels { - internal class PdfInfoGuarantor + public class PdfInfoGuarantor { + public string FileName { get; set; } = "C:\\Reports\\pdffile.pdf"; + public string Title { get; set; } = string.Empty; + public DateTime DateFrom { get; set; } + public DateTime DateTo { get; set; } + public List Lawyers { get; set; } = new(); } } diff --git a/LawCompany/LawCompanyBusinessLogic/OfficePackage/HelperModels/WordInfoGuarantor.cs b/LawCompany/LawCompanyBusinessLogic/OfficePackage/HelperModels/WordInfoGuarantor.cs index b6c805e..332e69e 100644 --- a/LawCompany/LawCompanyBusinessLogic/OfficePackage/HelperModels/WordInfoGuarantor.cs +++ b/LawCompany/LawCompanyBusinessLogic/OfficePackage/HelperModels/WordInfoGuarantor.cs @@ -1,4 +1,5 @@ -using System; +using LawCompanyContracts.ViewModels; +using System; using System.Collections.Generic; using System.Linq; using System.Text; @@ -6,7 +7,10 @@ using System.Threading.Tasks; namespace LawCompanyBusinessLogic.OfficePackage.HelperModels { - internal class WordInfoGuarantor + public class WordInfoGuarantor { + public string FileName { get; set; } = string.Empty; + public string Title { get; set; } = string.Empty; + public List LawyerHearings { get; set; } = new(); } } diff --git a/LawCompany/LawCompanyBusinessLogic/OfficePackage/Implements/SaveToExcelGuarantor.cs b/LawCompany/LawCompanyBusinessLogic/OfficePackage/Implements/SaveToExcelGuarantor.cs index 303d51f..522187d 100644 --- a/LawCompany/LawCompanyBusinessLogic/OfficePackage/Implements/SaveToExcelGuarantor.cs +++ b/LawCompany/LawCompanyBusinessLogic/OfficePackage/Implements/SaveToExcelGuarantor.cs @@ -8,7 +8,7 @@ using DocumentFormat.OpenXml; namespace LawCompanyBusinessLogic.OfficePackage.Implements { - /*public class SaveToExcelGuarantor : AbstractSaveToExcelGuarantor + public class SaveToExcelGuarantor : AbstractSaveToExcelGuarantor { private SpreadsheetDocument? _spreadsheetDocument; private SharedStringTablePart? _shareStringPart; @@ -324,5 +324,5 @@ namespace LawCompanyBusinessLogic.OfficePackage.Implements _spreadsheetDocument.WorkbookPart!.Workbook.Save(); _spreadsheetDocument.Close(); } - }*/ + } } diff --git a/LawCompany/LawCompanyBusinessLogic/OfficePackage/Implements/SaveToPdfGuarantor.cs b/LawCompany/LawCompanyBusinessLogic/OfficePackage/Implements/SaveToPdfGuarantor.cs index f7624a9..04f1363 100644 --- a/LawCompany/LawCompanyBusinessLogic/OfficePackage/Implements/SaveToPdfGuarantor.cs +++ b/LawCompany/LawCompanyBusinessLogic/OfficePackage/Implements/SaveToPdfGuarantor.cs @@ -1,12 +1,103 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; +using LawCompanyBusinessLogic.OfficePackage.HelperEnums; +using LawCompanyBusinessLogic.OfficePackage.HelperModels; +using MigraDoc.DocumentObjectModel; +using MigraDoc.Rendering; +using MigraDoc.DocumentObjectModel.Tables; + namespace LawCompanyBusinessLogic.OfficePackage.Implements { - internal class SaveToPdfGuarantor + public class SaveToPdfGuarantor : AbstractSaveToPdfGuarantor { + private Document? _document; + private Section? _section; + private Table? _table; + + private static ParagraphAlignment GetParagraphAlignment(PdfParagraphAlignmentType type) + { + return type switch + { + PdfParagraphAlignmentType.Center => ParagraphAlignment.Center, + PdfParagraphAlignmentType.Left => ParagraphAlignment.Left, + PdfParagraphAlignmentType.Rigth => ParagraphAlignment.Right, + _ => ParagraphAlignment.Justify, + }; + } + + private static void DefineStyles(Document document) + { + var style = document.Styles["Normal"]; + style.Font.Name = "Times New Roman"; + style.Font.Size = 14; + style = document.Styles.AddStyle("NormalTitle", "Normal"); + style.Font.Bold = true; + } + + protected override void CreateParagraph(PdfParagraph pdfParagraph) + { + if (_section == null) + { + return; + } + var paragraph = _section.AddParagraph(pdfParagraph.Text); + paragraph.Format.SpaceAfter = "1cm"; + paragraph.Format.Alignment = GetParagraphAlignment(pdfParagraph.ParagraphAlignment); + paragraph.Style = pdfParagraph.Style; + } + + protected override void CreatePdf(PdfInfoGuarantor info) + { + _document = new Document(); + DefineStyles(_document); + _section = _document.AddSection(); + } + + protected override void CreateRow(PdfRowParameters rowParameters) + { + if (_table == null) + { + return; + } + var row = _table.AddRow(); + for (int i = 0; i < rowParameters.Texts.Count; ++i) + { + row.Cells[i].AddParagraph(rowParameters.Texts[i]); + if (!string.IsNullOrEmpty(rowParameters.Style)) + { + row.Cells[i].Style = rowParameters.Style; + } + Unit borderWidth = 0.5; + row.Cells[i].Borders.Left.Width = borderWidth; + row.Cells[i].Borders.Right.Width = borderWidth; + row.Cells[i].Borders.Top.Width = borderWidth; + row.Cells[i].Borders.Bottom.Width = borderWidth; + row.Cells[i].Format.Alignment = GetParagraphAlignment(rowParameters.ParagraphAlignment); + row.Cells[i].VerticalAlignment = VerticalAlignment.Center; + } + } + + protected override void CreateTable(List columns) + { + if (_document == null) + { + return; + } + _table = _document.LastSection.AddTable(); + foreach (var elem in columns) + { + _table.AddColumn(elem); + } + } + + protected override void SavePdf(PdfInfoGuarantor info) + { + var renderer = new PdfDocumentRenderer(true) + { + Document = _document + }; + System.Text.Encoding.RegisterProvider(System.Text.CodePagesEncodingProvider.Instance); + renderer.RenderDocument(); + renderer.PdfDocument.Save(info.FileName); + } } } diff --git a/LawCompany/LawCompanyBusinessLogic/OfficePackage/Implements/SaveToWordGuarantor.cs b/LawCompany/LawCompanyBusinessLogic/OfficePackage/Implements/SaveToWordGuarantor.cs index c19aa12..0659fcd 100644 --- a/LawCompany/LawCompanyBusinessLogic/OfficePackage/Implements/SaveToWordGuarantor.cs +++ b/LawCompany/LawCompanyBusinessLogic/OfficePackage/Implements/SaveToWordGuarantor.cs @@ -1,4 +1,9 @@ -using System; +using DocumentFormat.OpenXml.Packaging; +using DocumentFormat.OpenXml.Wordprocessing; +using DocumentFormat.OpenXml; +using LawCompanyBusinessLogic.OfficePackage.HelperEnums; +using LawCompanyBusinessLogic.OfficePackage.HelperModels; +using System; using System.Collections.Generic; using System.Linq; using System.Text; @@ -6,7 +11,120 @@ using System.Threading.Tasks; namespace LawCompanyBusinessLogic.OfficePackage.Implements { - internal class SaveToWordGuarantor + public class SaveToWordGuarantor : AbstractSaveToWordGuarantor { + private WordprocessingDocument? _wordDocument; + private Body? _docBody; + + private static JustificationValues GetJustificationValues(WordJustificationType type) + { + return type switch + { + WordJustificationType.Both => JustificationValues.Both, + WordJustificationType.Center => JustificationValues.Center, + _ => JustificationValues.Left, + }; + } + + private static SectionProperties CreateSectionProperties() + { + var properties = new SectionProperties(); + var pageSize = new PageSize + { + Orient = PageOrientationValues.Portrait + }; + properties.AppendChild(pageSize); + return properties; + } + + private static ParagraphProperties? CreateParagraphProperties(WordTextProperties? paragraphProperties) + { + if (paragraphProperties == null) + { + return null; + } + + var properties = new ParagraphProperties(); + + properties.AppendChild(new Justification() + { + Val = GetJustificationValues(paragraphProperties.JustificationType) + }); + + properties.AppendChild(new SpacingBetweenLines + { + LineRule = LineSpacingRuleValues.Auto + }); + + properties.AppendChild(new Indentation()); + var paragraphMarkRunProperties = new ParagraphMarkRunProperties(); + + if (!string.IsNullOrEmpty(paragraphProperties.Size)) + { + paragraphMarkRunProperties.AppendChild(new FontSize + { + Val = paragraphProperties.Size + }); + } + + properties.AppendChild(paragraphMarkRunProperties); + + return properties; + } + + protected override void CreateParagraph(WordParagraph paragraph) + { + if (_docBody == null || paragraph == null) + { + return; + } + + var docParagraph = new Paragraph(); + + docParagraph.AppendChild(CreateParagraphProperties(paragraph.TextProperties)); + + foreach (var run in paragraph.Texts) + { + var docRun = new Run(); + var properties = new RunProperties(); + properties.AppendChild(new FontSize { Val = run.Item2.Size }); + + if (run.Item2.Bold) + { + properties.AppendChild(new Bold()); + } + + docRun.AppendChild(properties); + + docRun.AppendChild(new Text + { + Text = run.Item1, + Space = SpaceProcessingModeValues.Preserve + }); + + docParagraph.AppendChild(docRun); + } + _docBody.AppendChild(docParagraph); + } + + protected override void CreateWord(WordInfoGuarantor info) + { + _wordDocument = WordprocessingDocument.Create(info.FileName, WordprocessingDocumentType.Document); + MainDocumentPart mainPart = _wordDocument.AddMainDocumentPart(); + mainPart.Document = new Document(); + _docBody = mainPart.Document.AppendChild(new Body()); + } + + protected override void SaveWord(WordInfoGuarantor info) + { + if (_docBody == null || _wordDocument == null) + { + return; + } + + _docBody.AppendChild(CreateSectionProperties()); + _wordDocument.MainDocumentPart!.Document.Save(); + _wordDocument.Close(); + } } } diff --git a/LawCompany/LawCompanyContracts/BindingModels/ConsultationBindingModel.cs b/LawCompany/LawCompanyContracts/BindingModels/ConsultationBindingModel.cs index c594fa1..fe8ab5f 100644 --- a/LawCompany/LawCompanyContracts/BindingModels/ConsultationBindingModel.cs +++ b/LawCompany/LawCompanyContracts/BindingModels/ConsultationBindingModel.cs @@ -7,7 +7,7 @@ namespace LawCompanyContracts.BindingModels public int Id { get; set; } public double Cost { get; set; } public DateTime ConsultationDate { get; set; } - public int CaseId { get; set; } + public int? CaseId { get; set; } public int GuarantorId { get; set; } public Dictionary ConsultationLawyers { get; set; } = new(); } diff --git a/LawCompany/LawCompanyContracts/BindingModels/ReportExecutorBindingModel.cs b/LawCompany/LawCompanyContracts/BindingModels/ReportExecutorBindingModel.cs index 5f9afcf..fcc6601 100644 --- a/LawCompany/LawCompanyContracts/BindingModels/ReportExecutorBindingModel.cs +++ b/LawCompany/LawCompanyContracts/BindingModels/ReportExecutorBindingModel.cs @@ -13,5 +13,5 @@ namespace LawCompanyContracts.BindingModels public DateTime? DateTo { get; set; } public List? Ids { get; set; } public int ExecutorId { get; set; } - } + } } diff --git a/LawCompany/LawCompanyContracts/BindingModels/ReportGuarantorBindingModel.cs b/LawCompany/LawCompanyContracts/BindingModels/ReportGuarantorBindingModel.cs index 2f357d6..2ad595c 100644 --- a/LawCompany/LawCompanyContracts/BindingModels/ReportGuarantorBindingModel.cs +++ b/LawCompany/LawCompanyContracts/BindingModels/ReportGuarantorBindingModel.cs @@ -9,7 +9,6 @@ namespace LawCompanyContracts.BindingModels public class ReportGuarantorBindingModel { public string FileName { get; set; } = string.Empty; - public string HearingName { get; set; } = string.Empty; public DateTime? DateFrom { get; set; } public DateTime? DateTo { get; set; } public List? Ids { get; set; } diff --git a/LawCompany/LawCompanyContracts/BusinessLogicContracts/IReportExecutorLogic.cs b/LawCompany/LawCompanyContracts/BusinessLogicContracts/IReportExecutorLogic.cs index bf62784..e1c7a82 100644 --- a/LawCompany/LawCompanyContracts/BusinessLogicContracts/IReportExecutorLogic.cs +++ b/LawCompany/LawCompanyContracts/BusinessLogicContracts/IReportExecutorLogic.cs @@ -11,7 +11,7 @@ namespace LawCompanyContracts.BusinessLogicContracts public interface IReportExecutorLogic { List GetClientHearing(List Ids); - List GetClients(ReportExecutorBindingModel model); + List GetClients(ReportExecutorBindingModel model); void SaveClientHearingToWordFile(ReportExecutorBindingModel model); void SaveClientHearingToExcelFile(ReportExecutorBindingModel model); void SaveClientsToPdfFile(ReportExecutorBindingModel model); diff --git a/LawCompany/LawCompanyContracts/ViewModels/ClientVisitCountViewModel.cs b/LawCompany/LawCompanyContracts/ViewModels/ClientVisitCountViewModel.cs new file mode 100644 index 0000000..5e12159 --- /dev/null +++ b/LawCompany/LawCompanyContracts/ViewModels/ClientVisitCountViewModel.cs @@ -0,0 +1,8 @@ +namespace LawCompanyContracts.ViewModels +{ + public class ClientVisitCountViewModel + { + public string FIO { get; set; } = string.Empty; + public int VisitCount { get; set; } + } +} diff --git a/LawCompany/LawCompanyContracts/ViewModels/ConsultationViewModel.cs b/LawCompany/LawCompanyContracts/ViewModels/ConsultationViewModel.cs index f2138f2..9f30065 100644 --- a/LawCompany/LawCompanyContracts/ViewModels/ConsultationViewModel.cs +++ b/LawCompany/LawCompanyContracts/ViewModels/ConsultationViewModel.cs @@ -1,5 +1,6 @@ using LawCompanyDataModels.Models; using System.ComponentModel; +using System.Text.Json.Serialization; namespace LawCompanyContracts.ViewModels { @@ -11,11 +12,17 @@ namespace LawCompanyContracts.ViewModels public double Cost { get; set; } [DisplayName("Дата консультации")] public DateTime ConsultationDate { get; set; } - [DisplayName("Дело")] - public string CaseName { get; set; } = string.Empty; - public int CaseId { get; set; } + public int? CaseId { get; set; } public int GuarantorId { get; set; } public Dictionary ConsultationLawyers { get; set; } = new(); public CaseViewModel Case { get; set; } - } + + public ConsultationViewModel() { } + + [JsonConstructor] + public ConsultationViewModel(Dictionary ConsultationLawyers) + { + this.ConsultationLawyers = ConsultationLawyers.ToDictionary(x => x.Key, x => x.Value as ILawyerModel); + } + } } \ No newline at end of file diff --git a/LawCompany/LawCompanyContracts/ViewModels/LawyerHearingCountViewModel.cs b/LawCompany/LawCompanyContracts/ViewModels/LawyerHearingCountViewModel.cs new file mode 100644 index 0000000..7f3c9f4 --- /dev/null +++ b/LawCompany/LawCompanyContracts/ViewModels/LawyerHearingCountViewModel.cs @@ -0,0 +1,8 @@ +namespace LawCompanyContracts.ViewModels +{ + public class LawyerHearingCountViewModel + { + public string FIO { get; set; } = string.Empty; + public int HearingCount { get; set; } + } +} diff --git a/LawCompany/LawCompanyContracts/ViewModels/ReportClientCaseViewModel.cs b/LawCompany/LawCompanyContracts/ViewModels/ReportClientCaseViewModel.cs deleted file mode 100644 index 802e613..0000000 --- a/LawCompany/LawCompanyContracts/ViewModels/ReportClientCaseViewModel.cs +++ /dev/null @@ -1,12 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace LawCompanyContracts.ViewModels -{ - internal class ReportClientCaseViewModel - { - } -} diff --git a/LawCompany/LawCompanyContracts/ViewModels/ReportClientsViewModel.cs b/LawCompany/LawCompanyContracts/ViewModels/ReportClientsViewModel.cs index 6a9d338..9a5a987 100644 --- a/LawCompany/LawCompanyContracts/ViewModels/ReportClientsViewModel.cs +++ b/LawCompany/LawCompanyContracts/ViewModels/ReportClientsViewModel.cs @@ -7,15 +7,10 @@ using System.Threading.Tasks; namespace LawCompanyContracts.ViewModels { - public class ReportClientsViewModel - { - // клиент - public string FIO { get; set; } = string.Empty; - // дело - public string Name { get; set; } = string.Empty; - public CaseStatus Status { get; set; } = CaseStatus.Неизвестен; - // консультация - public DateTime ConsultationDate { get; set; } - public double Cost { get; set; } - } -} + public class ReportClientsViewModel + { + public string FIO { get; set; } = string.Empty; + public List CaseName { get; set; } = new List(); + public List VisitDate { get; set; } = new List(); + } +} \ No newline at end of file diff --git a/LawCompany/LawCompanyContracts/ViewModels/ReportLawyerHearingViewModel.cs b/LawCompany/LawCompanyContracts/ViewModels/ReportLawyerHearingViewModel.cs index ac438d7..143a122 100644 --- a/LawCompany/LawCompanyContracts/ViewModels/ReportLawyerHearingViewModel.cs +++ b/LawCompany/LawCompanyContracts/ViewModels/ReportLawyerHearingViewModel.cs @@ -1,12 +1,8 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace LawCompanyContracts.ViewModels +namespace LawCompanyContracts.ViewModels { - public class ReportLawyerHearingViewModel + public class ReportLawyerHearingViewModel { + public string FIO { get; set; } = string.Empty; + public List> Visits { get; set; } = new(); } } diff --git a/LawCompany/LawCompanyContracts/ViewModels/ReportLawyersViewModel.cs b/LawCompany/LawCompanyContracts/ViewModels/ReportLawyersViewModel.cs index 2e78203..fc88305 100644 --- a/LawCompany/LawCompanyContracts/ViewModels/ReportLawyersViewModel.cs +++ b/LawCompany/LawCompanyContracts/ViewModels/ReportLawyersViewModel.cs @@ -1,4 +1,5 @@ -using System; +using LawCompanyDataModels.Enums; +using System; using System.Collections.Generic; using System.Linq; using System.Text; @@ -8,5 +9,8 @@ namespace LawCompanyContracts.ViewModels { public class ReportLawyersViewModel { - } + public string FIO { get; set; } = string.Empty; + public List<(DateTime ConsultationDate, double Price)> Consultation { get; set; } = new(); + public List<(DateTime HearingDate, string Judge)> Hearing { get; set; } = new(); + } } diff --git a/LawCompany/LawCompanyDataModels/Models/IConsultationModel.cs b/LawCompany/LawCompanyDataModels/Models/IConsultationModel.cs index b330211..c0c4ba9 100644 --- a/LawCompany/LawCompanyDataModels/Models/IConsultationModel.cs +++ b/LawCompany/LawCompanyDataModels/Models/IConsultationModel.cs @@ -7,7 +7,7 @@ namespace LawCompanyDataModels.Models Dictionary ConsultationLawyers { get; } double Cost { get; } DateTime ConsultationDate { get; } - public int CaseId { get; } + public int? CaseId { get; } public int GuarantorId { get; } } } diff --git a/LawCompany/LawCompanyDatabaseImplement/Implements/CaseStorage.cs b/LawCompany/LawCompanyDatabaseImplement/Implements/CaseStorage.cs index 74b0989..044204e 100644 --- a/LawCompany/LawCompanyDatabaseImplement/Implements/CaseStorage.cs +++ b/LawCompany/LawCompanyDatabaseImplement/Implements/CaseStorage.cs @@ -9,16 +9,17 @@ namespace LawCompanyDatabaseImplement.Implements { public class CaseStorage : ICaseStorage { - public List GetFullList() - { - using var context = new LawCompanyDatabase(); - return context.Cases.Include(x => x.CaseClients) - .Include(x => x.Clients).ThenInclude(x => x.Client) - .ToList() - .Select(x => x.GetViewModel) - .ToList(); - } - public List GetFilteredList(CaseSearchModel model) + public List GetFullList() + { + using var context = new LawCompanyDatabase(); + return context.Cases + .Include(x => x.Clients).ThenInclude(x => x.Client) + .ToList() + .Select(x => x.GetViewModel) + .ToList(); + } + + public List GetFilteredList(CaseSearchModel model) { if (!model.Id.HasValue && !model.DateFrom.HasValue && !model.DateTo.HasValue && !model.ExecutorId.HasValue) diff --git a/LawCompany/LawCompanyDatabaseImplement/Implements/ConsultationStorage.cs b/LawCompany/LawCompanyDatabaseImplement/Implements/ConsultationStorage.cs index d803185..4fdf730 100644 --- a/LawCompany/LawCompanyDatabaseImplement/Implements/ConsultationStorage.cs +++ b/LawCompany/LawCompanyDatabaseImplement/Implements/ConsultationStorage.cs @@ -9,9 +9,9 @@ namespace LawCompanyDatabaseImplement.Implements { public class ConsultationStorage : IConsultationStorage { - public List GetFullList() - { - using var context = new LawCompanyDatabase(); + public List GetFullList() + { + using var context = new LawCompanyDatabase(); return context.Consultations .Include(x => x.Lawyers) .ThenInclude(x => x.Lawyer) @@ -19,26 +19,13 @@ namespace LawCompanyDatabaseImplement.Implements .Select(x => x.GetViewModel) .ToList(); } - public List GetFilteredList(ConsultationSearchModel model) - { - if (!model.Id.HasValue && !model.GuarantorId.HasValue && !model.DateFrom.HasValue && !model.DateTo.HasValue - && !model.ConsultationDate.HasValue && !model.CaseId.HasValue) + public List GetFilteredList(ConsultationSearchModel model) + { + if (!model.Id.HasValue && !model.GuarantorId.HasValue) { return new(); } - if (model.GuarantorId.HasValue && model.DateFrom.HasValue && model.DateTo.HasValue) - { - using var context = new LawCompanyDatabase(); - return context.Consultations - .Include(x => x.Lawyers) - .ThenInclude(x => x.Lawyer) - .Where(x => x.GuarantorId == model.GuarantorId && x.ConsultationDate >= model.DateFrom - && x.ConsultationDate <= model.DateTo) - .ToList() - .Select(x => x.GetViewModel) - .ToList(); - } - else if (model.GuarantorId.HasValue) + if (model.GuarantorId.HasValue) { using var context = new LawCompanyDatabase(); return context.Consultations @@ -48,91 +35,76 @@ namespace LawCompanyDatabaseImplement.Implements .Select(x => x.GetViewModel) .ToList(); } - else if (!model.DateFrom.HasValue || !model.DateTo.HasValue) - { - using var context = new LawCompanyDatabase(); - return context.Consultations - .Include(x => x.Lawyers) - .ThenInclude(x => x.Lawyer) - .Where(x => x.Id == model.Id) - .ToList() - .Select(x => x.GetViewModel) - .ToList(); - } else { using var context = new LawCompanyDatabase(); return context.Consultations .Include(x => x.Lawyers) .ThenInclude(x => x.Lawyer) - .Where(x => x.ConsultationDate >= model.DateFrom && x.ConsultationDate <= model.DateTo) - .ToList() + .Where(x => x.Id == model.Id) .Select(x => x.GetViewModel) .ToList(); } + } - public ConsultationViewModel? GetElement(ConsultationSearchModel model) - { - if (!model.Id.HasValue && !model.GuarantorId.HasValue && !model.ConsultationDate.HasValue) - { - return null; - } - using var context = new LawCompanyDatabase(); - return context.Consultations. - Include(x => x.Lawyers). - ThenInclude(x => x.Lawyer) - .FirstOrDefault(x => (model.GuarantorId.HasValue && x.GuarantorId == model.GuarantorId) - || (model.Id.HasValue && x.Id == model.Id))?.GetViewModel; - } - public ConsultationViewModel? Insert(ConsultationBindingModel model) - { - using var context = new LawCompanyDatabase(); - var newConsultation = Consultation.Create(context, model); - if (newConsultation == null) - { - return null; - } - context.Consultations.Add(newConsultation); - context.SaveChanges(); - return newConsultation.GetViewModel; - } - public ConsultationViewModel? Update(ConsultationBindingModel model) - { - using var context = new LawCompanyDatabase(); - using var transaction = context.Database.BeginTransaction(); - try - { - var consultation = context.Consultations.FirstOrDefault(rec => - rec.Id == model.Id); - if (consultation == null) - { - return null; - } - consultation.Update(model); - context.SaveChanges(); - consultation.UpdateLawyers(context, model); - transaction.Commit(); - return consultation.GetViewModel; - } - catch - { - transaction.Rollback(); - throw; - } - } - public ConsultationViewModel? Delete(ConsultationBindingModel model) - { - using var context = new LawCompanyDatabase(); - var element = context.Consultations - .Include(x => x.Lawyers) - .FirstOrDefault(rec => rec.Id == model.Id); - if (element != null) - { - context.Consultations.Remove(element); - context.SaveChanges(); - return element.GetViewModel; - } - return null; - } - } + public ConsultationViewModel? GetElement(ConsultationSearchModel model) + { + if (!model.Id.HasValue) + { + return null; + } + using var context = new LawCompanyDatabase(); + return context.Consultations + .Include(x => x.Lawyers) + .ThenInclude(x => x.Lawyer) + .FirstOrDefault(x => (model.Id.HasValue && x.Id == model.Id))? + .GetViewModel; + } + public ConsultationViewModel? Insert(ConsultationBindingModel model) + { + using var context = new LawCompanyDatabase(); + var newConsult = Consultation.Create(context, model); + if (newConsult == null) + { + return null; + } + context.Consultations.Add(newConsult); + context.SaveChanges(); + return newConsult.GetViewModel; + } + public ConsultationViewModel? Update(ConsultationBindingModel model) + { + using var context = new LawCompanyDatabase(); + using var transaction = context.Database.BeginTransaction(); + try + { + var consult = context.Consultations.FirstOrDefault(rec => rec.Id == model.Id); + if (consult == null) + { + return null; + } + consult.Update(model); + context.SaveChanges(); + consult.UpdateLawyers(context, model); + transaction.Commit(); + return consult.GetViewModel; + } + catch + { + throw; + } + } + public ConsultationViewModel? Delete(ConsultationBindingModel model) + { + using var context = new LawCompanyDatabase(); + var element = context.Consultations.Include(x => x.Lawyers).FirstOrDefault(rec => rec.Id == model.Id); + if (element != null) + { + context.Consultations.Remove(element); + context.SaveChanges(); + return element.GetViewModel; + } + return null; + } + } } diff --git a/LawCompany/LawCompanyDatabaseImplement/Implements/HearingStorage.cs b/LawCompany/LawCompanyDatabaseImplement/Implements/HearingStorage.cs index 10a3c8d..413c600 100644 --- a/LawCompany/LawCompanyDatabaseImplement/Implements/HearingStorage.cs +++ b/LawCompany/LawCompanyDatabaseImplement/Implements/HearingStorage.cs @@ -100,30 +100,31 @@ namespace LawCompanyDatabaseImplement.Implements using var transaction = context.Database.BeginTransaction(); try { - var _case = context.Hearings.FirstOrDefault(rec => - rec.Id == model.Id); + var _case = context.Hearings.FirstOrDefault(rec => rec.Id == model.Id); if (_case == null) { return null; } _case.Update(model); context.SaveChanges(); - _case.UpdateLawyers(context, model); + if (model.HearingLawyers != null) + { + _case.UpdateLawyers(context, model); + } - transaction.Commit(); + transaction.Commit(); return _case.GetViewModel; } catch { - throw; + transaction.Rollback(); + throw; } } public HearingViewModel? Delete(HearingBindingModel model) { using var context = new LawCompanyDatabase(); - var element = context.Hearings - .Include(x => x.Lawyers) - .FirstOrDefault(rec => rec.Id == model.Id); + var element = context.Hearings.Include(x => x.Lawyers).FirstOrDefault(rec => rec.Id == model.Id); if (element != null) { context.Hearings.Remove(element); diff --git a/LawCompany/LawCompanyDatabaseImplement/Implements/VisitStorage.cs b/LawCompany/LawCompanyDatabaseImplement/Implements/VisitStorage.cs index ca75e74..6acece2 100644 --- a/LawCompany/LawCompanyDatabaseImplement/Implements/VisitStorage.cs +++ b/LawCompany/LawCompanyDatabaseImplement/Implements/VisitStorage.cs @@ -39,7 +39,8 @@ namespace LawCompanyDatabaseImplement.Implements { using var context = new LawCompanyDatabase(); return context.Visits - .Include(x => x.Clients).ThenInclude(x => x.Client) + .Include(x => x.Clients) + .ThenInclude(x => x.Client) .Where(x => x.ExecutorId == model.ExecutorId) .Select(x => x.GetViewModel) .ToList(); diff --git a/LawCompany/LawCompanyDatabaseImplement/Migrations/20240502102425_InitialCreate.Designer.cs b/LawCompany/LawCompanyDatabaseImplement/Migrations/20240502102425_InitialCreate.Designer.cs deleted file mode 100644 index 24f1e7f..0000000 --- a/LawCompany/LawCompanyDatabaseImplement/Migrations/20240502102425_InitialCreate.Designer.cs +++ /dev/null @@ -1,545 +0,0 @@ -// -using System; -using LawCompanyDatabaseImplement; -using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Metadata; -using Microsoft.EntityFrameworkCore.Migrations; -using Microsoft.EntityFrameworkCore.Storage.ValueConversion; - -#nullable disable - -namespace LawCompanyDatabaseImplement.Migrations -{ - [DbContext(typeof(LawCompanyDatabase))] - [Migration("20240502102425_InitialCreate")] - partial class InitialCreate - { - /// - protected override void BuildTargetModel(ModelBuilder modelBuilder) - { -#pragma warning disable 612, 618 - modelBuilder - .HasAnnotation("ProductVersion", "7.0.17") - .HasAnnotation("Relational:MaxIdentifierLength", 128); - - SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); - - modelBuilder.Entity("LawCompanyDatabaseImplement.Models.Case", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.Property("CaseType") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.Property("DateCreate") - .HasColumnType("datetime2"); - - b.Property("DateImplement") - .HasColumnType("datetime2"); - - b.Property("ExecutorId") - .HasColumnType("int"); - - b.Property("Name") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.Property("Status") - .HasColumnType("int"); - - b.HasKey("Id"); - - b.HasIndex("ExecutorId"); - - b.ToTable("Cases"); - }); - - modelBuilder.Entity("LawCompanyDatabaseImplement.Models.CaseClient", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.Property("CaseId") - .HasColumnType("int"); - - b.Property("ClientId") - .HasColumnType("int"); - - b.HasKey("Id"); - - b.HasIndex("CaseId"); - - b.HasIndex("ClientId"); - - b.ToTable("CaseClients"); - }); - - modelBuilder.Entity("LawCompanyDatabaseImplement.Models.Client", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.Property("Email") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.Property("ExecutorId") - .HasColumnType("int"); - - b.Property("FIO") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.Property("Phone") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.HasKey("Id"); - - b.HasIndex("ExecutorId"); - - b.ToTable("Clients"); - }); - - modelBuilder.Entity("LawCompanyDatabaseImplement.Models.Consultation", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.Property("CaseId") - .HasColumnType("int"); - - b.Property("ConsultationDate") - .HasColumnType("datetime2"); - - b.Property("Cost") - .HasColumnType("float"); - - b.Property("GuarantorId") - .HasColumnType("int"); - - b.HasKey("Id"); - - b.HasIndex("CaseId"); - - b.HasIndex("GuarantorId"); - - b.ToTable("Consultations"); - }); - - modelBuilder.Entity("LawCompanyDatabaseImplement.Models.ConsultationLawyer", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.Property("ConsultationId") - .HasColumnType("int"); - - b.Property("LawyerId") - .HasColumnType("int"); - - b.HasKey("Id"); - - b.HasIndex("ConsultationId"); - - b.HasIndex("LawyerId"); - - b.ToTable("ConsultationLawyers"); - }); - - modelBuilder.Entity("LawCompanyDatabaseImplement.Models.Executor", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.Property("Email") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.Property("FIO") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.Property("Password") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.HasKey("Id"); - - b.ToTable("Executors"); - }); - - modelBuilder.Entity("LawCompanyDatabaseImplement.Models.Guarantor", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.Property("Email") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.Property("FIO") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.Property("Password") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.HasKey("Id"); - - b.ToTable("Guarantors"); - }); - - modelBuilder.Entity("LawCompanyDatabaseImplement.Models.Hearing", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.Property("GuarantorId") - .HasColumnType("int"); - - b.Property("HearingDate") - .HasColumnType("datetime2"); - - b.Property("Judge") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.HasKey("Id"); - - b.HasIndex("GuarantorId"); - - b.ToTable("Hearings"); - }); - - modelBuilder.Entity("LawCompanyDatabaseImplement.Models.HearingLawyer", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.Property("HearingId") - .HasColumnType("int"); - - b.Property("LawyerId") - .HasColumnType("int"); - - b.HasKey("Id"); - - b.HasIndex("HearingId"); - - b.HasIndex("LawyerId"); - - b.ToTable("HearingLawyers"); - }); - - modelBuilder.Entity("LawCompanyDatabaseImplement.Models.Lawyer", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.Property("Email") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.Property("FIO") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.Property("GuarantorId") - .HasColumnType("int"); - - b.Property("Phone") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.HasKey("Id"); - - b.HasIndex("GuarantorId"); - - b.ToTable("Lawyers"); - }); - - modelBuilder.Entity("LawCompanyDatabaseImplement.Models.Visit", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.Property("ExecutorId") - .HasColumnType("int"); - - b.Property("HearingId") - .HasColumnType("int"); - - b.Property("VisitDate") - .HasColumnType("datetime2"); - - b.HasKey("Id"); - - b.HasIndex("ExecutorId"); - - b.HasIndex("HearingId"); - - b.ToTable("Visits"); - }); - - modelBuilder.Entity("LawCompanyDatabaseImplement.Models.VisitClient", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.Property("ClientId") - .HasColumnType("int"); - - b.Property("VisitId") - .HasColumnType("int"); - - b.HasKey("Id"); - - b.HasIndex("ClientId"); - - b.HasIndex("VisitId"); - - b.ToTable("VisitClients"); - }); - - modelBuilder.Entity("LawCompanyDatabaseImplement.Models.Case", b => - { - b.HasOne("LawCompanyDatabaseImplement.Models.Executor", null) - .WithMany("Cases") - .HasForeignKey("ExecutorId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); - - modelBuilder.Entity("LawCompanyDatabaseImplement.Models.CaseClient", b => - { - b.HasOne("LawCompanyDatabaseImplement.Models.Case", "Case") - .WithMany("Clients") - .HasForeignKey("CaseId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.HasOne("LawCompanyDatabaseImplement.Models.Client", "Client") - .WithMany("CaseClients") - .HasForeignKey("ClientId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("Case"); - - b.Navigation("Client"); - }); - - modelBuilder.Entity("LawCompanyDatabaseImplement.Models.Client", b => - { - b.HasOne("LawCompanyDatabaseImplement.Models.Executor", null) - .WithMany("Clients") - .HasForeignKey("ExecutorId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); - - modelBuilder.Entity("LawCompanyDatabaseImplement.Models.Consultation", b => - { - b.HasOne("LawCompanyDatabaseImplement.Models.Case", "Case") - .WithMany() - .HasForeignKey("CaseId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.HasOne("LawCompanyDatabaseImplement.Models.Guarantor", null) - .WithMany("Consultations") - .HasForeignKey("GuarantorId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("Case"); - }); - - modelBuilder.Entity("LawCompanyDatabaseImplement.Models.ConsultationLawyer", b => - { - b.HasOne("LawCompanyDatabaseImplement.Models.Consultation", "Consultation") - .WithMany("Lawyers") - .HasForeignKey("ConsultationId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.HasOne("LawCompanyDatabaseImplement.Models.Lawyer", "Lawyer") - .WithMany("ConsultationLawyers") - .HasForeignKey("LawyerId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("Consultation"); - - b.Navigation("Lawyer"); - }); - - modelBuilder.Entity("LawCompanyDatabaseImplement.Models.Hearing", b => - { - b.HasOne("LawCompanyDatabaseImplement.Models.Guarantor", null) - .WithMany("Hearings") - .HasForeignKey("GuarantorId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); - - modelBuilder.Entity("LawCompanyDatabaseImplement.Models.HearingLawyer", b => - { - b.HasOne("LawCompanyDatabaseImplement.Models.Hearing", "Hearing") - .WithMany("Lawyers") - .HasForeignKey("HearingId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.HasOne("LawCompanyDatabaseImplement.Models.Lawyer", "Lawyer") - .WithMany("HearingLawyers") - .HasForeignKey("LawyerId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("Hearing"); - - b.Navigation("Lawyer"); - }); - - modelBuilder.Entity("LawCompanyDatabaseImplement.Models.Lawyer", b => - { - b.HasOne("LawCompanyDatabaseImplement.Models.Guarantor", null) - .WithMany("Lawyers") - .HasForeignKey("GuarantorId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); - - modelBuilder.Entity("LawCompanyDatabaseImplement.Models.Visit", b => - { - b.HasOne("LawCompanyDatabaseImplement.Models.Executor", null) - .WithMany("Visits") - .HasForeignKey("ExecutorId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.HasOne("LawCompanyDatabaseImplement.Models.Hearing", "Hearing") - .WithMany() - .HasForeignKey("HearingId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("Hearing"); - }); - - modelBuilder.Entity("LawCompanyDatabaseImplement.Models.VisitClient", b => - { - b.HasOne("LawCompanyDatabaseImplement.Models.Client", "Client") - .WithMany("ClientVisits") - .HasForeignKey("ClientId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.HasOne("LawCompanyDatabaseImplement.Models.Visit", "Visit") - .WithMany("Clients") - .HasForeignKey("VisitId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("Client"); - - b.Navigation("Visit"); - }); - - modelBuilder.Entity("LawCompanyDatabaseImplement.Models.Case", b => - { - b.Navigation("Clients"); - }); - - modelBuilder.Entity("LawCompanyDatabaseImplement.Models.Client", b => - { - b.Navigation("CaseClients"); - - b.Navigation("ClientVisits"); - }); - - modelBuilder.Entity("LawCompanyDatabaseImplement.Models.Consultation", b => - { - b.Navigation("Lawyers"); - }); - - modelBuilder.Entity("LawCompanyDatabaseImplement.Models.Executor", b => - { - b.Navigation("Cases"); - - b.Navigation("Clients"); - - b.Navigation("Visits"); - }); - - modelBuilder.Entity("LawCompanyDatabaseImplement.Models.Guarantor", b => - { - b.Navigation("Consultations"); - - b.Navigation("Hearings"); - - b.Navigation("Lawyers"); - }); - - modelBuilder.Entity("LawCompanyDatabaseImplement.Models.Hearing", b => - { - b.Navigation("Lawyers"); - }); - - modelBuilder.Entity("LawCompanyDatabaseImplement.Models.Lawyer", b => - { - b.Navigation("ConsultationLawyers"); - - b.Navigation("HearingLawyers"); - }); - - modelBuilder.Entity("LawCompanyDatabaseImplement.Models.Visit", b => - { - b.Navigation("Clients"); - }); -#pragma warning restore 612, 618 - } - } -} diff --git a/LawCompany/LawCompanyDatabaseImplement/Migrations/20240502102425_InitialCreate.cs b/LawCompany/LawCompanyDatabaseImplement/Migrations/20240502102425_InitialCreate.cs deleted file mode 100644 index 2529ce0..0000000 --- a/LawCompany/LawCompanyDatabaseImplement/Migrations/20240502102425_InitialCreate.cs +++ /dev/null @@ -1,413 +0,0 @@ -using System; -using Microsoft.EntityFrameworkCore.Migrations; - -#nullable disable - -namespace LawCompanyDatabaseImplement.Migrations -{ - /// - public partial class InitialCreate : Migration - { - /// - protected override void Up(MigrationBuilder migrationBuilder) - { - migrationBuilder.CreateTable( - name: "Executors", - columns: table => new - { - Id = table.Column(type: "int", nullable: false) - .Annotation("SqlServer:Identity", "1, 1"), - FIO = table.Column(type: "nvarchar(max)", nullable: false), - Email = table.Column(type: "nvarchar(max)", nullable: false), - Password = table.Column(type: "nvarchar(max)", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_Executors", x => x.Id); - }); - - migrationBuilder.CreateTable( - name: "Guarantors", - columns: table => new - { - Id = table.Column(type: "int", nullable: false) - .Annotation("SqlServer:Identity", "1, 1"), - FIO = table.Column(type: "nvarchar(max)", nullable: false), - Email = table.Column(type: "nvarchar(max)", nullable: false), - Password = table.Column(type: "nvarchar(max)", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_Guarantors", x => x.Id); - }); - - migrationBuilder.CreateTable( - name: "Cases", - columns: table => new - { - Id = table.Column(type: "int", nullable: false) - .Annotation("SqlServer:Identity", "1, 1"), - Name = table.Column(type: "nvarchar(max)", nullable: false), - CaseType = table.Column(type: "nvarchar(max)", nullable: false), - DateCreate = table.Column(type: "datetime2", nullable: false), - DateImplement = table.Column(type: "datetime2", nullable: true), - Status = table.Column(type: "int", nullable: false), - ExecutorId = table.Column(type: "int", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_Cases", x => x.Id); - table.ForeignKey( - name: "FK_Cases_Executors_ExecutorId", - column: x => x.ExecutorId, - principalTable: "Executors", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - }); - - migrationBuilder.CreateTable( - name: "Clients", - columns: table => new - { - Id = table.Column(type: "int", nullable: false) - .Annotation("SqlServer:Identity", "1, 1"), - FIO = table.Column(type: "nvarchar(max)", nullable: false), - Email = table.Column(type: "nvarchar(max)", nullable: false), - Phone = table.Column(type: "nvarchar(max)", nullable: false), - ExecutorId = table.Column(type: "int", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_Clients", x => x.Id); - table.ForeignKey( - name: "FK_Clients_Executors_ExecutorId", - column: x => x.ExecutorId, - principalTable: "Executors", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - }); - - migrationBuilder.CreateTable( - name: "Hearings", - columns: table => new - { - Id = table.Column(type: "int", nullable: false) - .Annotation("SqlServer:Identity", "1, 1"), - HearingDate = table.Column(type: "datetime2", nullable: false), - Judge = table.Column(type: "nvarchar(max)", nullable: false), - GuarantorId = table.Column(type: "int", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_Hearings", x => x.Id); - table.ForeignKey( - name: "FK_Hearings_Guarantors_GuarantorId", - column: x => x.GuarantorId, - principalTable: "Guarantors", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - }); - - migrationBuilder.CreateTable( - name: "Lawyers", - columns: table => new - { - Id = table.Column(type: "int", nullable: false) - .Annotation("SqlServer:Identity", "1, 1"), - FIO = table.Column(type: "nvarchar(max)", nullable: false), - Email = table.Column(type: "nvarchar(max)", nullable: false), - Phone = table.Column(type: "nvarchar(max)", nullable: false), - GuarantorId = table.Column(type: "int", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_Lawyers", x => x.Id); - table.ForeignKey( - name: "FK_Lawyers_Guarantors_GuarantorId", - column: x => x.GuarantorId, - principalTable: "Guarantors", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - }); - - migrationBuilder.CreateTable( - name: "Consultations", - columns: table => new - { - Id = table.Column(type: "int", nullable: false) - .Annotation("SqlServer:Identity", "1, 1"), - Cost = table.Column(type: "float", nullable: false), - ConsultationDate = table.Column(type: "datetime2", nullable: false), - CaseId = table.Column(type: "int", nullable: false), - GuarantorId = table.Column(type: "int", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_Consultations", x => x.Id); - table.ForeignKey( - name: "FK_Consultations_Cases_CaseId", - column: x => x.CaseId, - principalTable: "Cases", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - table.ForeignKey( - name: "FK_Consultations_Guarantors_GuarantorId", - column: x => x.GuarantorId, - principalTable: "Guarantors", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - }); - - migrationBuilder.CreateTable( - name: "CaseClients", - columns: table => new - { - Id = table.Column(type: "int", nullable: false) - .Annotation("SqlServer:Identity", "1, 1"), - CaseId = table.Column(type: "int", nullable: false), - ClientId = table.Column(type: "int", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_CaseClients", x => x.Id); - table.ForeignKey( - name: "FK_CaseClients_Cases_CaseId", - column: x => x.CaseId, - principalTable: "Cases", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - table.ForeignKey( - name: "FK_CaseClients_Clients_ClientId", - column: x => x.ClientId, - principalTable: "Clients", - principalColumn: "Id", - onDelete: ReferentialAction.NoAction); - }); - - migrationBuilder.CreateTable( - name: "Visits", - columns: table => new - { - Id = table.Column(type: "int", nullable: false) - .Annotation("SqlServer:Identity", "1, 1"), - VisitDate = table.Column(type: "datetime2", nullable: false), - HearingId = table.Column(type: "int", nullable: false), - ExecutorId = table.Column(type: "int", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_Visits", x => x.Id); - table.ForeignKey( - name: "FK_Visits_Executors_ExecutorId", - column: x => x.ExecutorId, - principalTable: "Executors", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - table.ForeignKey( - name: "FK_Visits_Hearings_HearingId", - column: x => x.HearingId, - principalTable: "Hearings", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - }); - - migrationBuilder.CreateTable( - name: "HearingLawyers", - columns: table => new - { - Id = table.Column(type: "int", nullable: false) - .Annotation("SqlServer:Identity", "1, 1"), - HearingId = table.Column(type: "int", nullable: false), - LawyerId = table.Column(type: "int", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_HearingLawyers", x => x.Id); - table.ForeignKey( - name: "FK_HearingLawyers_Hearings_HearingId", - column: x => x.HearingId, - principalTable: "Hearings", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - table.ForeignKey( - name: "FK_HearingLawyers_Lawyers_LawyerId", - column: x => x.LawyerId, - principalTable: "Lawyers", - principalColumn: "Id", - onDelete: ReferentialAction.NoAction); - }); - - migrationBuilder.CreateTable( - name: "ConsultationLawyers", - columns: table => new - { - Id = table.Column(type: "int", nullable: false) - .Annotation("SqlServer:Identity", "1, 1"), - ConsultationId = table.Column(type: "int", nullable: false), - LawyerId = table.Column(type: "int", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_ConsultationLawyers", x => x.Id); - table.ForeignKey( - name: "FK_ConsultationLawyers_Consultations_ConsultationId", - column: x => x.ConsultationId, - principalTable: "Consultations", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - table.ForeignKey( - name: "FK_ConsultationLawyers_Lawyers_LawyerId", - column: x => x.LawyerId, - principalTable: "Lawyers", - principalColumn: "Id", - onDelete: ReferentialAction.NoAction); - }); - - migrationBuilder.CreateTable( - name: "VisitClients", - columns: table => new - { - Id = table.Column(type: "int", nullable: false) - .Annotation("SqlServer:Identity", "1, 1"), - ClientId = table.Column(type: "int", nullable: false), - VisitId = table.Column(type: "int", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_VisitClients", x => x.Id); - table.ForeignKey( - name: "FK_VisitClients_Clients_ClientId", - column: x => x.ClientId, - principalTable: "Clients", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - table.ForeignKey( - name: "FK_VisitClients_Visits_VisitId", - column: x => x.VisitId, - principalTable: "Visits", - principalColumn: "Id", - onDelete: ReferentialAction.NoAction); - }); - - migrationBuilder.CreateIndex( - name: "IX_CaseClients_CaseId", - table: "CaseClients", - column: "CaseId"); - - migrationBuilder.CreateIndex( - name: "IX_CaseClients_ClientId", - table: "CaseClients", - column: "ClientId"); - - migrationBuilder.CreateIndex( - name: "IX_Cases_ExecutorId", - table: "Cases", - column: "ExecutorId"); - - migrationBuilder.CreateIndex( - name: "IX_Clients_ExecutorId", - table: "Clients", - column: "ExecutorId"); - - migrationBuilder.CreateIndex( - name: "IX_ConsultationLawyers_ConsultationId", - table: "ConsultationLawyers", - column: "ConsultationId"); - - migrationBuilder.CreateIndex( - name: "IX_ConsultationLawyers_LawyerId", - table: "ConsultationLawyers", - column: "LawyerId"); - - migrationBuilder.CreateIndex( - name: "IX_Consultations_CaseId", - table: "Consultations", - column: "CaseId"); - - migrationBuilder.CreateIndex( - name: "IX_Consultations_GuarantorId", - table: "Consultations", - column: "GuarantorId"); - - migrationBuilder.CreateIndex( - name: "IX_HearingLawyers_HearingId", - table: "HearingLawyers", - column: "HearingId"); - - migrationBuilder.CreateIndex( - name: "IX_HearingLawyers_LawyerId", - table: "HearingLawyers", - column: "LawyerId"); - - migrationBuilder.CreateIndex( - name: "IX_Hearings_GuarantorId", - table: "Hearings", - column: "GuarantorId"); - - migrationBuilder.CreateIndex( - name: "IX_Lawyers_GuarantorId", - table: "Lawyers", - column: "GuarantorId"); - - migrationBuilder.CreateIndex( - name: "IX_VisitClients_ClientId", - table: "VisitClients", - column: "ClientId"); - - migrationBuilder.CreateIndex( - name: "IX_VisitClients_VisitId", - table: "VisitClients", - column: "VisitId"); - - migrationBuilder.CreateIndex( - name: "IX_Visits_ExecutorId", - table: "Visits", - column: "ExecutorId"); - - migrationBuilder.CreateIndex( - name: "IX_Visits_HearingId", - table: "Visits", - column: "HearingId"); - } - - /// - protected override void Down(MigrationBuilder migrationBuilder) - { - migrationBuilder.DropTable( - name: "CaseClients"); - - migrationBuilder.DropTable( - name: "ConsultationLawyers"); - - migrationBuilder.DropTable( - name: "HearingLawyers"); - - migrationBuilder.DropTable( - name: "VisitClients"); - - migrationBuilder.DropTable( - name: "Consultations"); - - migrationBuilder.DropTable( - name: "Lawyers"); - - migrationBuilder.DropTable( - name: "Clients"); - - migrationBuilder.DropTable( - name: "Visits"); - - migrationBuilder.DropTable( - name: "Cases"); - - migrationBuilder.DropTable( - name: "Hearings"); - - migrationBuilder.DropTable( - name: "Executors"); - - migrationBuilder.DropTable( - name: "Guarantors"); - } - } -} diff --git a/LawCompany/LawCompanyDatabaseImplement/Migrations/20240503003222_InitialCreate2.cs b/LawCompany/LawCompanyDatabaseImplement/Migrations/20240503003222_InitialCreate2.cs deleted file mode 100644 index f1fc2a9..0000000 --- a/LawCompany/LawCompanyDatabaseImplement/Migrations/20240503003222_InitialCreate2.cs +++ /dev/null @@ -1,59 +0,0 @@ -using Microsoft.EntityFrameworkCore.Migrations; - -#nullable disable - -namespace LawCompanyDatabaseImplement.Migrations -{ - /// - public partial class InitialCreate2 : Migration - { - /// - protected override void Up(MigrationBuilder migrationBuilder) - { - migrationBuilder.DropForeignKey( - name: "FK_Lawyers_Guarantors_GuarantorId", - table: "Lawyers"); - - migrationBuilder.AlterColumn( - name: "GuarantorId", - table: "Lawyers", - type: "int", - nullable: true, - oldClrType: typeof(int), - oldType: "int"); - - migrationBuilder.AddForeignKey( - name: "FK_Lawyers_Guarantors_GuarantorId", - table: "Lawyers", - column: "GuarantorId", - principalTable: "Guarantors", - principalColumn: "Id"); - } - - /// - protected override void Down(MigrationBuilder migrationBuilder) - { - migrationBuilder.DropForeignKey( - name: "FK_Lawyers_Guarantors_GuarantorId", - table: "Lawyers"); - - migrationBuilder.AlterColumn( - name: "GuarantorId", - table: "Lawyers", - type: "int", - nullable: false, - defaultValue: 0, - oldClrType: typeof(int), - oldType: "int", - oldNullable: true); - - migrationBuilder.AddForeignKey( - name: "FK_Lawyers_Guarantors_GuarantorId", - table: "Lawyers", - column: "GuarantorId", - principalTable: "Guarantors", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - } - } -} diff --git a/LawCompany/LawCompanyDatabaseImplement/Migrations/20240526230637_InitialCreate3.Designer.cs b/LawCompany/LawCompanyDatabaseImplement/Migrations/20240526230043_test.Designer.cs similarity index 99% rename from LawCompany/LawCompanyDatabaseImplement/Migrations/20240526230637_InitialCreate3.Designer.cs rename to LawCompany/LawCompanyDatabaseImplement/Migrations/20240526230043_test.Designer.cs index 4292e25..d4ee6de 100644 --- a/LawCompany/LawCompanyDatabaseImplement/Migrations/20240526230637_InitialCreate3.Designer.cs +++ b/LawCompany/LawCompanyDatabaseImplement/Migrations/20240526230043_test.Designer.cs @@ -12,8 +12,8 @@ using Microsoft.EntityFrameworkCore.Storage.ValueConversion; namespace LawCompanyDatabaseImplement.Migrations { [DbContext(typeof(LawCompanyDatabase))] - [Migration("20240526230637_InitialCreate3")] - partial class InitialCreate3 + [Migration("20240526230043_test")] + partial class test { /// protected override void BuildTargetModel(ModelBuilder modelBuilder) @@ -117,7 +117,8 @@ namespace LawCompanyDatabaseImplement.Migrations SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - b.Property("CaseId") + b.Property("CaseId") + .IsRequired() .HasColumnType("int"); b.Property("ConsultationDate") diff --git a/LawCompany/LawCompanyDatabaseImplement/Migrations/20240526230043_test.cs b/LawCompany/LawCompanyDatabaseImplement/Migrations/20240526230043_test.cs new file mode 100644 index 0000000..29db7cd --- /dev/null +++ b/LawCompany/LawCompanyDatabaseImplement/Migrations/20240526230043_test.cs @@ -0,0 +1,410 @@ +using System; +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace LawCompanyDatabaseImplement.Migrations +{ + /// + public partial class test : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.CreateTable( + name: "Executors", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + FIO = table.Column(type: "nvarchar(max)", nullable: false), + Email = table.Column(type: "nvarchar(max)", nullable: false), + Password = table.Column(type: "nvarchar(max)", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Executors", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "Guarantors", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + FIO = table.Column(type: "nvarchar(max)", nullable: false), + Email = table.Column(type: "nvarchar(max)", nullable: false), + Password = table.Column(type: "nvarchar(max)", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Guarantors", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "Cases", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + Name = table.Column(type: "nvarchar(max)", nullable: false), + DateCreate = table.Column(type: "datetime2", nullable: false), + DateImplement = table.Column(type: "datetime2", nullable: true), + Status = table.Column(type: "int", nullable: false), + ExecutorId = table.Column(type: "int", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Cases", x => x.Id); + table.ForeignKey( + name: "FK_Cases_Executors_ExecutorId", + column: x => x.ExecutorId, + principalTable: "Executors", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "Clients", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + FIO = table.Column(type: "nvarchar(max)", nullable: false), + Email = table.Column(type: "nvarchar(max)", nullable: false), + Phone = table.Column(type: "nvarchar(max)", nullable: false), + ExecutorId = table.Column(type: "int", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Clients", x => x.Id); + table.ForeignKey( + name: "FK_Clients_Executors_ExecutorId", + column: x => x.ExecutorId, + principalTable: "Executors", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "Hearings", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + HearingDate = table.Column(type: "datetime2", nullable: false), + Judge = table.Column(type: "nvarchar(max)", nullable: false), + GuarantorId = table.Column(type: "int", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Hearings", x => x.Id); + table.ForeignKey( + name: "FK_Hearings_Guarantors_GuarantorId", + column: x => x.GuarantorId, + principalTable: "Guarantors", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "Lawyers", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + FIO = table.Column(type: "nvarchar(max)", nullable: false), + Email = table.Column(type: "nvarchar(max)", nullable: false), + Phone = table.Column(type: "nvarchar(max)", nullable: false), + GuarantorId = table.Column(type: "int", nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_Lawyers", x => x.Id); + table.ForeignKey( + name: "FK_Lawyers_Guarantors_GuarantorId", + column: x => x.GuarantorId, + principalTable: "Guarantors", + principalColumn: "Id"); + }); + + migrationBuilder.CreateTable( + name: "Consultations", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + Cost = table.Column(type: "float", nullable: false), + ConsultationDate = table.Column(type: "datetime2", nullable: false), + CaseId = table.Column(type: "int", nullable: true), + GuarantorId = table.Column(type: "int", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Consultations", x => x.Id); + table.ForeignKey( + name: "FK_Consultations_Cases_CaseId", + column: x => x.CaseId, + principalTable: "Cases", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_Consultations_Guarantors_GuarantorId", + column: x => x.GuarantorId, + principalTable: "Guarantors", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "CaseClients", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + CaseId = table.Column(type: "int", nullable: false), + ClientId = table.Column(type: "int", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_CaseClients", x => x.Id); + table.ForeignKey( + name: "FK_CaseClients_Cases_CaseId", + column: x => x.CaseId, + principalTable: "Cases", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_CaseClients_Clients_ClientId", + column: x => x.ClientId, + principalTable: "Clients", + principalColumn: "Id", + onDelete: ReferentialAction.Restrict); + }); + + migrationBuilder.CreateTable( + name: "Visits", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + VisitDate = table.Column(type: "datetime2", nullable: false), + HearingId = table.Column(type: "int", nullable: true), + ExecutorId = table.Column(type: "int", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Visits", x => x.Id); + table.ForeignKey( + name: "FK_Visits_Executors_ExecutorId", + column: x => x.ExecutorId, + principalTable: "Executors", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_Visits_Hearings_HearingId", + column: x => x.HearingId, + principalTable: "Hearings", + principalColumn: "Id"); + }); + + migrationBuilder.CreateTable( + name: "HearingLawyers", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + HearingId = table.Column(type: "int", nullable: false), + LawyerId = table.Column(type: "int", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_HearingLawyers", x => x.Id); + table.ForeignKey( + name: "FK_HearingLawyers_Hearings_HearingId", + column: x => x.HearingId, + principalTable: "Hearings", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_HearingLawyers_Lawyers_LawyerId", + column: x => x.LawyerId, + principalTable: "Lawyers", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "ConsultationLawyers", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + ConsultationId = table.Column(type: "int", nullable: false), + LawyerId = table.Column(type: "int", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_ConsultationLawyers", x => x.Id); + table.ForeignKey( + name: "FK_ConsultationLawyers_Consultations_ConsultationId", + column: x => x.ConsultationId, + principalTable: "Consultations", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_ConsultationLawyers_Lawyers_LawyerId", + column: x => x.LawyerId, + principalTable: "Lawyers", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "VisitClients", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + ClientId = table.Column(type: "int", nullable: false), + VisitId = table.Column(type: "int", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_VisitClients", x => x.Id); + table.ForeignKey( + name: "FK_VisitClients_Clients_ClientId", + column: x => x.ClientId, + principalTable: "Clients", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_VisitClients_Visits_VisitId", + column: x => x.VisitId, + principalTable: "Visits", + principalColumn: "Id", + onDelete: ReferentialAction.Restrict); + }); + + migrationBuilder.CreateIndex( + name: "IX_CaseClients_CaseId", + table: "CaseClients", + column: "CaseId"); + + migrationBuilder.CreateIndex( + name: "IX_CaseClients_ClientId", + table: "CaseClients", + column: "ClientId"); + + migrationBuilder.CreateIndex( + name: "IX_Cases_ExecutorId", + table: "Cases", + column: "ExecutorId"); + + migrationBuilder.CreateIndex( + name: "IX_Clients_ExecutorId", + table: "Clients", + column: "ExecutorId"); + + migrationBuilder.CreateIndex( + name: "IX_ConsultationLawyers_ConsultationId", + table: "ConsultationLawyers", + column: "ConsultationId"); + + migrationBuilder.CreateIndex( + name: "IX_ConsultationLawyers_LawyerId", + table: "ConsultationLawyers", + column: "LawyerId"); + + migrationBuilder.CreateIndex( + name: "IX_Consultations_CaseId", + table: "Consultations", + column: "CaseId"); + + migrationBuilder.CreateIndex( + name: "IX_Consultations_GuarantorId", + table: "Consultations", + column: "GuarantorId"); + + migrationBuilder.CreateIndex( + name: "IX_HearingLawyers_HearingId", + table: "HearingLawyers", + column: "HearingId"); + + migrationBuilder.CreateIndex( + name: "IX_HearingLawyers_LawyerId", + table: "HearingLawyers", + column: "LawyerId"); + + migrationBuilder.CreateIndex( + name: "IX_Hearings_GuarantorId", + table: "Hearings", + column: "GuarantorId"); + + migrationBuilder.CreateIndex( + name: "IX_Lawyers_GuarantorId", + table: "Lawyers", + column: "GuarantorId"); + + migrationBuilder.CreateIndex( + name: "IX_VisitClients_ClientId", + table: "VisitClients", + column: "ClientId"); + + migrationBuilder.CreateIndex( + name: "IX_VisitClients_VisitId", + table: "VisitClients", + column: "VisitId"); + + migrationBuilder.CreateIndex( + name: "IX_Visits_ExecutorId", + table: "Visits", + column: "ExecutorId"); + + migrationBuilder.CreateIndex( + name: "IX_Visits_HearingId", + table: "Visits", + column: "HearingId"); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "CaseClients"); + + migrationBuilder.DropTable( + name: "ConsultationLawyers"); + + migrationBuilder.DropTable( + name: "HearingLawyers"); + + migrationBuilder.DropTable( + name: "VisitClients"); + + migrationBuilder.DropTable( + name: "Consultations"); + + migrationBuilder.DropTable( + name: "Lawyers"); + + migrationBuilder.DropTable( + name: "Clients"); + + migrationBuilder.DropTable( + name: "Visits"); + + migrationBuilder.DropTable( + name: "Cases"); + + migrationBuilder.DropTable( + name: "Hearings"); + + migrationBuilder.DropTable( + name: "Executors"); + + migrationBuilder.DropTable( + name: "Guarantors"); + } + } +} diff --git a/LawCompany/LawCompanyDatabaseImplement/Migrations/20240526230637_InitialCreate3.cs b/LawCompany/LawCompanyDatabaseImplement/Migrations/20240526230637_InitialCreate3.cs deleted file mode 100644 index a4db597..0000000 --- a/LawCompany/LawCompanyDatabaseImplement/Migrations/20240526230637_InitialCreate3.cs +++ /dev/null @@ -1,70 +0,0 @@ -using Microsoft.EntityFrameworkCore.Migrations; - -#nullable disable - -namespace LawCompanyDatabaseImplement.Migrations -{ - /// - public partial class InitialCreate3 : Migration - { - /// - protected override void Up(MigrationBuilder migrationBuilder) - { - migrationBuilder.DropForeignKey( - name: "FK_Visits_Hearings_HearingId", - table: "Visits"); - - migrationBuilder.DropColumn( - name: "CaseType", - table: "Cases"); - - migrationBuilder.AlterColumn( - name: "HearingId", - table: "Visits", - type: "int", - nullable: true, - oldClrType: typeof(int), - oldType: "int"); - - migrationBuilder.AddForeignKey( - name: "FK_Visits_Hearings_HearingId", - table: "Visits", - column: "HearingId", - principalTable: "Hearings", - principalColumn: "Id"); - } - - /// - protected override void Down(MigrationBuilder migrationBuilder) - { - migrationBuilder.DropForeignKey( - name: "FK_Visits_Hearings_HearingId", - table: "Visits"); - - migrationBuilder.AlterColumn( - name: "HearingId", - table: "Visits", - type: "int", - nullable: false, - defaultValue: 0, - oldClrType: typeof(int), - oldType: "int", - oldNullable: true); - - migrationBuilder.AddColumn( - name: "CaseType", - table: "Cases", - type: "nvarchar(max)", - nullable: false, - defaultValue: ""); - - migrationBuilder.AddForeignKey( - name: "FK_Visits_Hearings_HearingId", - table: "Visits", - column: "HearingId", - principalTable: "Hearings", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - } - } -} diff --git a/LawCompany/LawCompanyDatabaseImplement/Migrations/20240503003222_InitialCreate2.Designer.cs b/LawCompany/LawCompanyDatabaseImplement/Migrations/20240811194245_InitialCreate.Designer.cs similarity index 96% rename from LawCompany/LawCompanyDatabaseImplement/Migrations/20240503003222_InitialCreate2.Designer.cs rename to LawCompany/LawCompanyDatabaseImplement/Migrations/20240811194245_InitialCreate.Designer.cs index 4b6e9af..9bc6fbc 100644 --- a/LawCompany/LawCompanyDatabaseImplement/Migrations/20240503003222_InitialCreate2.Designer.cs +++ b/LawCompany/LawCompanyDatabaseImplement/Migrations/20240811194245_InitialCreate.Designer.cs @@ -12,8 +12,8 @@ using Microsoft.EntityFrameworkCore.Storage.ValueConversion; namespace LawCompanyDatabaseImplement.Migrations { [DbContext(typeof(LawCompanyDatabase))] - [Migration("20240503003222_InitialCreate2")] - partial class InitialCreate2 + [Migration("20240811194245_InitialCreate")] + partial class InitialCreate { /// protected override void BuildTargetModel(ModelBuilder modelBuilder) @@ -33,10 +33,6 @@ namespace LawCompanyDatabaseImplement.Migrations SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - b.Property("CaseType") - .IsRequired() - .HasColumnType("nvarchar(max)"); - b.Property("DateCreate") .HasColumnType("datetime2"); @@ -121,7 +117,7 @@ namespace LawCompanyDatabaseImplement.Migrations SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - b.Property("CaseId") + b.Property("CaseId") .HasColumnType("int"); b.Property("ConsultationDate") @@ -304,7 +300,7 @@ namespace LawCompanyDatabaseImplement.Migrations b.Property("ExecutorId") .HasColumnType("int"); - b.Property("HearingId") + b.Property("HearingId") .HasColumnType("int"); b.Property("VisitDate") @@ -372,20 +368,20 @@ namespace LawCompanyDatabaseImplement.Migrations modelBuilder.Entity("LawCompanyDatabaseImplement.Models.Client", b => { - b.HasOne("LawCompanyDatabaseImplement.Models.Executor", null) + b.HasOne("LawCompanyDatabaseImplement.Models.Executor", "Executor") .WithMany("Clients") .HasForeignKey("ExecutorId") .OnDelete(DeleteBehavior.Cascade) .IsRequired(); + + b.Navigation("Executor"); }); modelBuilder.Entity("LawCompanyDatabaseImplement.Models.Consultation", b => { b.HasOne("LawCompanyDatabaseImplement.Models.Case", "Case") .WithMany() - .HasForeignKey("CaseId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); + .HasForeignKey("CaseId"); b.HasOne("LawCompanyDatabaseImplement.Models.Guarantor", null) .WithMany("Consultations") @@ -460,9 +456,7 @@ namespace LawCompanyDatabaseImplement.Migrations b.HasOne("LawCompanyDatabaseImplement.Models.Hearing", "Hearing") .WithMany() - .HasForeignKey("HearingId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); + .HasForeignKey("HearingId"); b.Navigation("Hearing"); }); diff --git a/LawCompany/LawCompanyDatabaseImplement/Migrations/20240811194245_InitialCreate.cs b/LawCompany/LawCompanyDatabaseImplement/Migrations/20240811194245_InitialCreate.cs new file mode 100644 index 0000000..e2e53e9 --- /dev/null +++ b/LawCompany/LawCompanyDatabaseImplement/Migrations/20240811194245_InitialCreate.cs @@ -0,0 +1,409 @@ +using System; +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace LawCompanyDatabaseImplement.Migrations +{ + /// + public partial class InitialCreate : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.CreateTable( + name: "Executors", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + FIO = table.Column(type: "nvarchar(max)", nullable: false), + Email = table.Column(type: "nvarchar(max)", nullable: false), + Password = table.Column(type: "nvarchar(max)", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Executors", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "Guarantors", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + FIO = table.Column(type: "nvarchar(max)", nullable: false), + Email = table.Column(type: "nvarchar(max)", nullable: false), + Password = table.Column(type: "nvarchar(max)", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Guarantors", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "Cases", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + Name = table.Column(type: "nvarchar(max)", nullable: false), + DateCreate = table.Column(type: "datetime2", nullable: false), + DateImplement = table.Column(type: "datetime2", nullable: true), + Status = table.Column(type: "int", nullable: false), + ExecutorId = table.Column(type: "int", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Cases", x => x.Id); + table.ForeignKey( + name: "FK_Cases_Executors_ExecutorId", + column: x => x.ExecutorId, + principalTable: "Executors", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "Clients", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + FIO = table.Column(type: "nvarchar(max)", nullable: false), + Email = table.Column(type: "nvarchar(max)", nullable: false), + Phone = table.Column(type: "nvarchar(max)", nullable: false), + ExecutorId = table.Column(type: "int", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Clients", x => x.Id); + table.ForeignKey( + name: "FK_Clients_Executors_ExecutorId", + column: x => x.ExecutorId, + principalTable: "Executors", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "Hearings", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + HearingDate = table.Column(type: "datetime2", nullable: false), + Judge = table.Column(type: "nvarchar(max)", nullable: false), + GuarantorId = table.Column(type: "int", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Hearings", x => x.Id); + table.ForeignKey( + name: "FK_Hearings_Guarantors_GuarantorId", + column: x => x.GuarantorId, + principalTable: "Guarantors", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "Lawyers", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + FIO = table.Column(type: "nvarchar(max)", nullable: false), + Email = table.Column(type: "nvarchar(max)", nullable: false), + Phone = table.Column(type: "nvarchar(max)", nullable: false), + GuarantorId = table.Column(type: "int", nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_Lawyers", x => x.Id); + table.ForeignKey( + name: "FK_Lawyers_Guarantors_GuarantorId", + column: x => x.GuarantorId, + principalTable: "Guarantors", + principalColumn: "Id"); + }); + + migrationBuilder.CreateTable( + name: "Consultations", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + Cost = table.Column(type: "float", nullable: false), + ConsultationDate = table.Column(type: "datetime2", nullable: false), + CaseId = table.Column(type: "int", nullable: true), + GuarantorId = table.Column(type: "int", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Consultations", x => x.Id); + table.ForeignKey( + name: "FK_Consultations_Cases_CaseId", + column: x => x.CaseId, + principalTable: "Cases", + principalColumn: "Id"); + table.ForeignKey( + name: "FK_Consultations_Guarantors_GuarantorId", + column: x => x.GuarantorId, + principalTable: "Guarantors", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "CaseClients", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + CaseId = table.Column(type: "int", nullable: false), + ClientId = table.Column(type: "int", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_CaseClients", x => x.Id); + table.ForeignKey( + name: "FK_CaseClients_Cases_CaseId", + column: x => x.CaseId, + principalTable: "Cases", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_CaseClients_Clients_ClientId", + column: x => x.ClientId, + principalTable: "Clients", + principalColumn: "Id", + onDelete: ReferentialAction.Restrict); + }); + + migrationBuilder.CreateTable( + name: "Visits", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + VisitDate = table.Column(type: "datetime2", nullable: false), + HearingId = table.Column(type: "int", nullable: true), + ExecutorId = table.Column(type: "int", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Visits", x => x.Id); + table.ForeignKey( + name: "FK_Visits_Executors_ExecutorId", + column: x => x.ExecutorId, + principalTable: "Executors", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_Visits_Hearings_HearingId", + column: x => x.HearingId, + principalTable: "Hearings", + principalColumn: "Id"); + }); + + migrationBuilder.CreateTable( + name: "HearingLawyers", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + HearingId = table.Column(type: "int", nullable: false), + LawyerId = table.Column(type: "int", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_HearingLawyers", x => x.Id); + table.ForeignKey( + name: "FK_HearingLawyers_Hearings_HearingId", + column: x => x.HearingId, + principalTable: "Hearings", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_HearingLawyers_Lawyers_LawyerId", + column: x => x.LawyerId, + principalTable: "Lawyers", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "ConsultationLawyers", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + ConsultationId = table.Column(type: "int", nullable: false), + LawyerId = table.Column(type: "int", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_ConsultationLawyers", x => x.Id); + table.ForeignKey( + name: "FK_ConsultationLawyers_Consultations_ConsultationId", + column: x => x.ConsultationId, + principalTable: "Consultations", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_ConsultationLawyers_Lawyers_LawyerId", + column: x => x.LawyerId, + principalTable: "Lawyers", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "VisitClients", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + ClientId = table.Column(type: "int", nullable: false), + VisitId = table.Column(type: "int", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_VisitClients", x => x.Id); + table.ForeignKey( + name: "FK_VisitClients_Clients_ClientId", + column: x => x.ClientId, + principalTable: "Clients", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_VisitClients_Visits_VisitId", + column: x => x.VisitId, + principalTable: "Visits", + principalColumn: "Id", + onDelete: ReferentialAction.Restrict); + }); + + migrationBuilder.CreateIndex( + name: "IX_CaseClients_CaseId", + table: "CaseClients", + column: "CaseId"); + + migrationBuilder.CreateIndex( + name: "IX_CaseClients_ClientId", + table: "CaseClients", + column: "ClientId"); + + migrationBuilder.CreateIndex( + name: "IX_Cases_ExecutorId", + table: "Cases", + column: "ExecutorId"); + + migrationBuilder.CreateIndex( + name: "IX_Clients_ExecutorId", + table: "Clients", + column: "ExecutorId"); + + migrationBuilder.CreateIndex( + name: "IX_ConsultationLawyers_ConsultationId", + table: "ConsultationLawyers", + column: "ConsultationId"); + + migrationBuilder.CreateIndex( + name: "IX_ConsultationLawyers_LawyerId", + table: "ConsultationLawyers", + column: "LawyerId"); + + migrationBuilder.CreateIndex( + name: "IX_Consultations_CaseId", + table: "Consultations", + column: "CaseId"); + + migrationBuilder.CreateIndex( + name: "IX_Consultations_GuarantorId", + table: "Consultations", + column: "GuarantorId"); + + migrationBuilder.CreateIndex( + name: "IX_HearingLawyers_HearingId", + table: "HearingLawyers", + column: "HearingId"); + + migrationBuilder.CreateIndex( + name: "IX_HearingLawyers_LawyerId", + table: "HearingLawyers", + column: "LawyerId"); + + migrationBuilder.CreateIndex( + name: "IX_Hearings_GuarantorId", + table: "Hearings", + column: "GuarantorId"); + + migrationBuilder.CreateIndex( + name: "IX_Lawyers_GuarantorId", + table: "Lawyers", + column: "GuarantorId"); + + migrationBuilder.CreateIndex( + name: "IX_VisitClients_ClientId", + table: "VisitClients", + column: "ClientId"); + + migrationBuilder.CreateIndex( + name: "IX_VisitClients_VisitId", + table: "VisitClients", + column: "VisitId"); + + migrationBuilder.CreateIndex( + name: "IX_Visits_ExecutorId", + table: "Visits", + column: "ExecutorId"); + + migrationBuilder.CreateIndex( + name: "IX_Visits_HearingId", + table: "Visits", + column: "HearingId"); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "CaseClients"); + + migrationBuilder.DropTable( + name: "ConsultationLawyers"); + + migrationBuilder.DropTable( + name: "HearingLawyers"); + + migrationBuilder.DropTable( + name: "VisitClients"); + + migrationBuilder.DropTable( + name: "Consultations"); + + migrationBuilder.DropTable( + name: "Lawyers"); + + migrationBuilder.DropTable( + name: "Clients"); + + migrationBuilder.DropTable( + name: "Visits"); + + migrationBuilder.DropTable( + name: "Cases"); + + migrationBuilder.DropTable( + name: "Hearings"); + + migrationBuilder.DropTable( + name: "Executors"); + + migrationBuilder.DropTable( + name: "Guarantors"); + } + } +} diff --git a/LawCompany/LawCompanyDatabaseImplement/Migrations/LawCompanyDatabaseModelSnapshot.cs b/LawCompany/LawCompanyDatabaseImplement/Migrations/LawCompanyDatabaseModelSnapshot.cs index f2bde67..a809813 100644 --- a/LawCompany/LawCompanyDatabaseImplement/Migrations/LawCompanyDatabaseModelSnapshot.cs +++ b/LawCompany/LawCompanyDatabaseImplement/Migrations/LawCompanyDatabaseModelSnapshot.cs @@ -114,7 +114,7 @@ namespace LawCompanyDatabaseImplement.Migrations SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - b.Property("CaseId") + b.Property("CaseId") .HasColumnType("int"); b.Property("ConsultationDate") @@ -378,9 +378,7 @@ namespace LawCompanyDatabaseImplement.Migrations { b.HasOne("LawCompanyDatabaseImplement.Models.Case", "Case") .WithMany() - .HasForeignKey("CaseId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); + .HasForeignKey("CaseId"); b.HasOne("LawCompanyDatabaseImplement.Models.Guarantor", null) .WithMany("Consultations") diff --git a/LawCompany/LawCompanyDatabaseImplement/Models/Case.cs b/LawCompany/LawCompanyDatabaseImplement/Models/Case.cs index 3b3c2eb..67ef930 100644 --- a/LawCompany/LawCompanyDatabaseImplement/Models/Case.cs +++ b/LawCompany/LawCompanyDatabaseImplement/Models/Case.cs @@ -106,5 +106,5 @@ namespace LawCompanyDatabaseImplement.Models } _caseClients = null; } - } + } } diff --git a/LawCompany/LawCompanyDatabaseImplement/Models/Consultation.cs b/LawCompany/LawCompanyDatabaseImplement/Models/Consultation.cs index eb00572..2a6bc6d 100644 --- a/LawCompany/LawCompanyDatabaseImplement/Models/Consultation.cs +++ b/LawCompany/LawCompanyDatabaseImplement/Models/Consultation.cs @@ -14,12 +14,11 @@ namespace LawCompanyDatabaseImplement.Models public double Cost { get; private set; } [Required] public DateTime ConsultationDate { get; private set; } - [Required] - public int CaseId { get; private set; } + public int? CaseId { get; private set; } public Case Case { get; private set; } public int GuarantorId { get; set; } - private Dictionary? _consultationLawyers = null; + private Dictionary _consultationLawyers = null; [ForeignKey("ConsultationId")] public virtual List Lawyers { get; set; } = new(); [NotMapped] @@ -29,10 +28,7 @@ namespace LawCompanyDatabaseImplement.Models { if (_consultationLawyers == null) { - using var context = new LawCompanyDatabase(); - _consultationLawyers = Lawyers - .ToDictionary(x => x.LawyerId, x => (context.Lawyers - .FirstOrDefault(y => y.Id == x.LawyerId) as ILawyerModel)); + _consultationLawyers = Lawyers.ToDictionary(x => x.LawyerId, x => (x.Lawyer as ILawyerModel)); } return _consultationLawyers; } @@ -43,18 +39,12 @@ namespace LawCompanyDatabaseImplement.Models { return null; } - var consultations = context.Consultations.Where(x => x.CaseId == model.CaseId).ToList(); - if (consultations.Count > 0) - { - return null; - } return new Consultation() { Id = model.Id, Cost = model.Cost, ConsultationDate = model.ConsultationDate, CaseId = model.CaseId, - Case = context.Cases.First(x => x.Id == model.CaseId), GuarantorId = model.GuarantorId, Lawyers = model.ConsultationLawyers.Select(x => new ConsultationLawyer { @@ -81,34 +71,30 @@ namespace LawCompanyDatabaseImplement.Models Cost = Cost, ConsultationDate = ConsultationDate, CaseId = CaseId, - GuarantorId = GuarantorId, - ConsultationLawyers = ConsultationLawyers }; - public void UpdateLawyers(LawCompanyDatabase context, - ConsultationBindingModel model) + + public void UpdateLawyers(LawCompanyDatabase context, ConsultationBindingModel model) { - var consultationLawyers = context.ConsultationLawyers - .Where(rec => rec.ConsultationId == model.Id) - .ToList(); + var consultationLawyers = context.ConsultationLawyers.Where(rec => rec.ConsultationId == model.Id).ToList(); if (consultationLawyers != null && consultationLawyers.Count > 0) { - context.ConsultationLawyers - .RemoveRange(consultationLawyers - .Where(rec => !model.ConsultationLawyers - .ContainsKey(rec.LawyerId))); + context.ConsultationLawyers.RemoveRange(consultationLawyers.Where(rec => !model.ConsultationLawyers.ContainsKey(rec.LawyerId))); context.SaveChanges(); - } + + foreach (var updateMember in consultationLawyers) + { + model.ConsultationLawyers.Remove(updateMember.LawyerId); + } + context.SaveChanges(); + } var _consultation = context.Consultations.First(x => x.Id == Id); foreach (var pc in model.ConsultationLawyers) { - if (!ConsultationLawyers.ContainsKey(pc.Key)) + context.ConsultationLawyers.Add(new ConsultationLawyer { - context.ConsultationLawyers.Add(new ConsultationLawyer - { - Consultation = _consultation, - Lawyer = context.Lawyers.First(x => x.Id == pc.Key), - }); - } + Consultation = _consultation, + Lawyer = context.Lawyers.First(x => x.Id == pc.Key), + }); context.SaveChanges(); } _consultationLawyers = null; diff --git a/LawCompany/LawCompanyDatabaseImplement/Models/Hearing.cs b/LawCompany/LawCompanyDatabaseImplement/Models/Hearing.cs index 01ff90b..a92c8bd 100644 --- a/LawCompany/LawCompanyDatabaseImplement/Models/Hearing.cs +++ b/LawCompany/LawCompanyDatabaseImplement/Models/Hearing.cs @@ -16,7 +16,7 @@ namespace LawCompanyDatabaseImplement.Models [Required] public string Judge { get; private set; } = string.Empty; public int GuarantorId { get; set; } - private Dictionary? _hearingLawyers = null; + private Dictionary _hearingLawyers = null; [ForeignKey("HearingId")] public virtual List Lawyers { get; set; } = new(); [NotMapped] @@ -26,10 +26,7 @@ namespace LawCompanyDatabaseImplement.Models { if (_hearingLawyers == null) { - using var context = new LawCompanyDatabase(); - _hearingLawyers = Lawyers - .ToDictionary(x => x.LawyerId, x => (context.Lawyers - .FirstOrDefault(y => y.Id == x.LawyerId) as ILawyerModel)); + _hearingLawyers = Lawyers.ToDictionary(x => x.LawyerId, x => (x.Lawyer as ILawyerModel)); } return _hearingLawyers; } @@ -66,31 +63,33 @@ namespace LawCompanyDatabaseImplement.Models Id = Id, HearingDate = HearingDate, Judge = Judge, - GuarantorId = GuarantorId, - HearingLawyers = HearingLawyers + GuarantorId = GuarantorId }; public void UpdateLawyers(LawCompanyDatabase context, HearingBindingModel model) { - var hearingLawyer = context.HearingLawyers - .Where(rec => rec.HearingId == model.Id) - .ToList(); + var hearingLawyer = context.HearingLawyers.Where(rec => rec.HearingId == model.Id).ToList(); + if (hearingLawyer != null && hearingLawyer.Count > 0) { - context.HearingLawyers.RemoveRange(hearingLawyer.Where(rec - => !model.HearingLawyers.ContainsKey(rec.LawyerId))); + context.HearingLawyers.RemoveRange(hearingLawyer.Where(rec => !model.HearingLawyers.ContainsKey(rec.LawyerId))); context.SaveChanges(); - } + + foreach (var updateMember in hearingLawyer) + { + model.HearingLawyers.Remove(updateMember.LawyerId); + } + context.SaveChanges(); + } + var _hearing = context.Hearings.First(x => x.Id == Id); + foreach (var pc in model.HearingLawyers) { - if (!HearingLawyers.ContainsKey(pc.Key)) + context.HearingLawyers.Add(new HearingLawyer { - context.HearingLawyers.Add(new HearingLawyer - { - Hearing = _hearing, - Lawyer = context.Lawyers.First(x => x.Id == pc.Key), - }); - } + Hearing = _hearing, + Lawyer = context.Lawyers.First(x => x.Id == pc.Key), + }); context.SaveChanges(); } _hearingLawyers = null; diff --git a/LawCompany/LawCompanyDatabaseImplement/Models/Lawyer.cs b/LawCompany/LawCompanyDatabaseImplement/Models/Lawyer.cs index d79d066..24b4f1e 100644 --- a/LawCompany/LawCompanyDatabaseImplement/Models/Lawyer.cs +++ b/LawCompany/LawCompanyDatabaseImplement/Models/Lawyer.cs @@ -3,7 +3,6 @@ using LawCompanyContracts.ViewModels; using LawCompanyDataModels.Models; using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; -using System.ComponentModel.Design; namespace LawCompanyDatabaseImplement.Models { diff --git a/LawCompany/LawCompanyExecutorApp/Controllers/CaseController.cs b/LawCompany/LawCompanyExecutorApp/Controllers/CaseController.cs index 4c60023..df9904f 100644 --- a/LawCompany/LawCompanyExecutorApp/Controllers/CaseController.cs +++ b/LawCompany/LawCompanyExecutorApp/Controllers/CaseController.cs @@ -1,4 +1,5 @@ -using LawCompanyContracts.BindingModels; +using DocumentFormat.OpenXml.Office2010.Excel; +using LawCompanyContracts.BindingModels; using LawCompanyContracts.SearchModels; using LawCompanyContracts.ViewModels; using LawCompanyDataModels.Enums; @@ -34,7 +35,7 @@ namespace LawCompanyExecutorApp.Controllers client.Add(members, new ClientSearchModel { Id = members } as IClientModel); } - APIClient.PostRequest("api/case/createcase", new CaseBindingModel + APIClient.PostRequest("api/case/createcase", new CaseBindingModel { Name = name, DateCreate = DateTime.Now, @@ -52,7 +53,7 @@ namespace LawCompanyExecutorApp.Controllers throw new Exception("Вы как суда попали? Суда вход только авторизованным"); } - APIClient.PostRequest("api/case/deletecase", new CaseBindingModel + APIClient.PostRequest("api/case/deletecase", new CaseBindingModel { Id = id }); @@ -110,6 +111,29 @@ namespace LawCompanyExecutorApp.Controllers return Redirect("~/Home/Enter"); } return View(APIClient.GetRequest>($"api/case/getclientlisttocase?caseId={id}")); - } + } + + [HttpGet] + public IActionResult TopCases() + { + if (APIClient.Executor == null) + { + return Redirect("~/Home/Enter"); + } + var cases = APIClient.GetRequest>($"api/case/GetCaseList?executorId={APIClient.Executor.Id}"); + + var statusCounts = cases + .GroupBy(c => c.Status) + .Select(g => new + { + Status = g.Key.ToString(), + Count = g.Count() + }) + .ToList(); + + ViewBag.StatusCounts = statusCounts; + + return View(); + } } } \ No newline at end of file diff --git a/LawCompany/LawCompanyExecutorApp/Controllers/HomeController.cs b/LawCompany/LawCompanyExecutorApp/Controllers/HomeController.cs index 76f7fef..af38dc3 100644 --- a/LawCompany/LawCompanyExecutorApp/Controllers/HomeController.cs +++ b/LawCompany/LawCompanyExecutorApp/Controllers/HomeController.cs @@ -138,7 +138,7 @@ namespace LawCompanyExecutorApp.Controllers return Redirect("~/Home/Enter"); } ViewBag.Visits = APIClient.GetRequest>($"api/visit/GetVisitList?executorId={APIClient.Executor.Id}"); - ViewBag.Hearings = APIClient.GetRequest>($"api/hearing/GetHearingList"); + ViewBag.Hearings = APIClient.GetRequest>($"api/hearing/GetHearingList?guarantorId={APIClient.Executor.Id}"); return View(); } @@ -157,7 +157,7 @@ namespace LawCompanyExecutorApp.Controllers VisitDate = roomElem.VisitDate, HearingId = hearing }); - Response.Redirect("Visits"); + Response.Redirect("Index"); } [HttpGet] @@ -206,7 +206,7 @@ namespace LawCompanyExecutorApp.Controllers } else { - APIClient.PostRequest("api/report/CreateOrganiserReportToExcelFile", new ReportExecutorBindingModel + APIClient.PostRequest("api/report/CreateExecutorReportToExcelFile", new ReportExecutorBindingModel { Ids = res, FileName = "C:\\Reports\\excelfile.xlsx" @@ -291,7 +291,6 @@ namespace LawCompanyExecutorApp.Controllers _logger.LogError(ex, "Ошибка создания отчета"); throw; } - double sum = 0; string table = ""; table += "

Предварительный отчет

"; table += "
"; @@ -299,33 +298,37 @@ namespace LawCompanyExecutorApp.Controllers table += ""; table += ""; table += "Клиент"; - table += "Наименование дела"; - table += "Статус дела"; + table += "Дело"; table += "Дата консультации"; - table += "Цена консультации"; table += ""; table += ""; - foreach (var report in result) + table += ""; + + foreach (var client in result) { - bool IsCost = true; - if (report.Cost == 0) - { - IsCost = false; - } - table += ""; table += ""; - table += $"{report.FIO}"; - table += $"{report.Name}"; - table += $"{report.Status}"; - table += $"{report.ConsultationDate.ToShortDateString()}"; - table += $"{(IsCost ? report.Cost.ToString() : string.Empty)}"; + table += $"{client.FIO}"; + table += $""; + table += $""; table += ""; - table += ""; - sum += report.Cost; + foreach (var cons in client.CaseName) + { + table += ""; + table += $""; + table += $"{cons}"; + table += $""; + table += ""; + } + foreach (var hear in client.VisitDate) + { + table += ""; + table += $""; + table += $""; + table += $"{hear}"; + table += ""; + } } - table += ""; - table += $"Итого:{sum}"; - table += ""; + table += ""; table += ""; table += "
"; return table; diff --git a/LawCompany/LawCompanyExecutorApp/Controllers/VisitController.cs b/LawCompany/LawCompanyExecutorApp/Controllers/VisitController.cs index 2bb0754..0687502 100644 --- a/LawCompany/LawCompanyExecutorApp/Controllers/VisitController.cs +++ b/LawCompany/LawCompanyExecutorApp/Controllers/VisitController.cs @@ -1,6 +1,7 @@ using LawCompanyContracts.BindingModels; using LawCompanyContracts.SearchModels; using LawCompanyContracts.ViewModels; +using LawCompanyDatabaseImplement; using LawCompanyDataModels.Models; using Microsoft.AspNetCore.Mvc; @@ -69,8 +70,8 @@ namespace LawCompanyExecutorApp.Controllers { return Redirect("~/Home/Enter"); } - ViewBag.Clients = APIClient.GetRequest>($"api/client/GetClientList?executorId={APIClient.Executor.Id}"); - return View(); + ViewBag.Clients = APIClient.GetRequest>($"api/client/GetClientList?executorId={APIClient.Executor.Id}"); + return View(); } [HttpPost] @@ -92,7 +93,7 @@ namespace LawCompanyExecutorApp.Controllers client.Add(members, new ClientSearchModel { Id = members } as IClientModel); } - APIClient.PostRequest("api/visit/updatevisit", new VisitBindingModel + APIClient.PostRequest("api/visit/updatevisit", new VisitBindingModel { Id = id, VisitDate = visitDate, @@ -101,14 +102,48 @@ namespace LawCompanyExecutorApp.Controllers Response.Redirect("/Home/Visits"); } - [HttpGet] - public IActionResult VisitClients(int id) - { - if (APIClient.Executor == null) - { - return Redirect("~/Home/Enter"); - } - return View(APIClient.GetRequest>($"api/visit/getclientlisttovisit?visitId={id}")); - } - } + [HttpGet] + public IActionResult VisitClients(int id) + { + if (APIClient.Executor == null) + { + return Redirect("~/Home/Enter"); + } + return View(APIClient.GetRequest>($"api/visit/getclientlisttovisit?visitId={id}")); + } + + [HttpGet] + public IActionResult ClientVisitCounts() + { + if (APIClient.Executor == null) + { + return Redirect("~/Home/Enter"); + } + + using (var context = new LawCompanyDatabase()) + { + var clients = context.Clients + .Where(c => c.ExecutorId == APIClient.Executor.Id) + .Select(c => new ClientViewModel + { + Id = c.Id, + FIO = c.FIO, + Email = c.Email, + Phone = c.Phone, + ExecutorId = c.ExecutorId + }) + .ToList(); + + var clientVisitCounts = clients.Select(client => new ClientVisitCountViewModel + { + FIO = client.FIO, + VisitCount = context.VisitClients.Count(vc => vc.ClientId == client.Id) + }).ToList(); + + ViewBag.ClientVisitCounts = clientVisitCounts; + + return View(clientVisitCounts); + } + } + } } diff --git a/LawCompany/LawCompanyExecutorApp/Controllers/VizitController.cs b/LawCompany/LawCompanyExecutorApp/Controllers/VizitController.cs deleted file mode 100644 index e2f56c0..0000000 --- a/LawCompany/LawCompanyExecutorApp/Controllers/VizitController.cs +++ /dev/null @@ -1,12 +0,0 @@ -using Microsoft.AspNetCore.Mvc; - -namespace LawCompanyExecutorApp.Controllers -{ - public class VizitController : Controller - { - public IActionResult Index() - { - return View(); - } - } -} \ No newline at end of file diff --git a/LawCompany/LawCompanyExecutorApp/Program.cs b/LawCompany/LawCompanyExecutorApp/Program.cs index 44171da..7b0dd9e 100644 --- a/LawCompany/LawCompanyExecutorApp/Program.cs +++ b/LawCompany/LawCompanyExecutorApp/Program.cs @@ -12,7 +12,6 @@ using LawCompanyBusinessLogic.BusinessLogics; var builder = WebApplication.CreateBuilder(args); builder.Services.AddTransient(); -builder.Services.AddTransient(); builder.Services.AddTransient(); builder.Services.AddTransient(); builder.Services.AddTransient(); diff --git a/LawCompany/LawCompanyExecutorApp/Views/Case/AddClient.cshtml b/LawCompany/LawCompanyExecutorApp/Views/Case/AddClient.cshtml deleted file mode 100644 index 31f72b2..0000000 --- a/LawCompany/LawCompanyExecutorApp/Views/Case/AddClient.cshtml +++ /dev/null @@ -1,30 +0,0 @@ -@{ - ViewData["Title"] = "Добавить клиентов"; - Layout = "~/Views/Shared/_Layout.cshtml"; -} - -
-

Добавить клиентов

-
-
- -
-
Клиент
-
- -
-
-
-
Дело
-
- -
-
-
-
-
- -
-
-
\ No newline at end of file diff --git a/LawCompany/LawCompanyExecutorApp/Views/Case/TopCases.cshtml b/LawCompany/LawCompanyExecutorApp/Views/Case/TopCases.cshtml new file mode 100644 index 0000000..dcba99d --- /dev/null +++ b/LawCompany/LawCompanyExecutorApp/Views/Case/TopCases.cshtml @@ -0,0 +1,46 @@ +@using LawCompanyContracts.ViewModels; +@{ + ViewData["Title"] = "Top Cases"; + var statusCounts = ViewBag.StatusCounts; +} + + + + + + + +
+
+
+ + + diff --git a/LawCompany/LawCompanyExecutorApp/Views/Shared/_Layout.cshtml b/LawCompany/LawCompanyExecutorApp/Views/Shared/_Layout.cshtml index b910943..6b128d6 100644 --- a/LawCompany/LawCompanyExecutorApp/Views/Shared/_Layout.cshtml +++ b/LawCompany/LawCompanyExecutorApp/Views/Shared/_Layout.cshtml @@ -35,19 +35,23 @@ Личные данные + + - - diff --git a/LawCompany/LawCompanyExecutorApp/Views/Visit/AddClient.cshtml b/LawCompany/LawCompanyExecutorApp/Views/Visit/AddClient.cshtml deleted file mode 100644 index ca5a046..0000000 --- a/LawCompany/LawCompanyExecutorApp/Views/Visit/AddClient.cshtml +++ /dev/null @@ -1,30 +0,0 @@ -@{ - ViewData["Title"] = "Добавление клиентов"; - Layout = "~/Views/Shared/_Layout.cshtml"; -} - -
-

Добавить задачи

-
-
- -
-
Визит
-
- -
-
-
-
Клиент
-
- -
-
-
-
-
- -
-
-
\ No newline at end of file diff --git a/LawCompany/LawCompanyExecutorApp/Views/Visit/ClientVisitCounts.cshtml b/LawCompany/LawCompanyExecutorApp/Views/Visit/ClientVisitCounts.cshtml new file mode 100644 index 0000000..1e4e1e1 --- /dev/null +++ b/LawCompany/LawCompanyExecutorApp/Views/Visit/ClientVisitCounts.cshtml @@ -0,0 +1,44 @@ +@using LawCompanyContracts.ViewModels; + +@model List + +@{ + ViewData["Title"] = "Количество визитов клиентов"; +} + + + + + @ViewData["Title"] + + + +
+ + + + diff --git a/LawCompany/LawCompanyGuarantorApp/Controllers/ConsultationController.cs b/LawCompany/LawCompanyGuarantorApp/Controllers/ConsultationController.cs index 9d6c57a..4266327 100644 --- a/LawCompany/LawCompanyGuarantorApp/Controllers/ConsultationController.cs +++ b/LawCompany/LawCompanyGuarantorApp/Controllers/ConsultationController.cs @@ -1,12 +1,131 @@ -using Microsoft.AspNetCore.Mvc; +using LawCompanyContracts.BindingModels; +using LawCompanyContracts.SearchModels; +using LawCompanyContracts.ViewModels; +using LawCompanyDatabaseImplement.Models; +using LawCompanyDataModels.Models; +using Microsoft.AspNetCore.Mvc; namespace LawCompanyGuarantorApp.Controllers { public class ConsultationController : Controller { - public IActionResult Index() + [HttpGet] + public IActionResult ConsultationLawyers(int id) { + if (APIClient.Guarantor == null) + { + return Redirect("~/Home/Enter"); + } + return View(APIClient.GetRequest>($"api/consultation/getlawyerlisttoconsultation?conId={id}")); + } + + [HttpGet] + public IActionResult CreateConsultation() + { + if (APIClient.Guarantor == null) + { + return Redirect("~/Home/Enter"); + } + ViewBag.Lawyers = APIClient.GetRequest>($"api/lawyer/GetLawyerList?guarantorId={APIClient.Guarantor.Id}"); return View(); } - } + + [HttpPost] + public void CreateConsultation(int cost, DateTime date, List clientselect) + { + if (APIClient.Guarantor == null) + { + throw new Exception("Вы как суда попали? Суда вход только авторизованным"); + } + + Dictionary client = new Dictionary(); + foreach (int members in clientselect) + { + client.Add(members, new LawyerSearchModel { Id = members } as ILawyerModel); + } + + APIClient.PostRequest("api/consultation/createconsultation", new ConsultationBindingModel + { + Cost = cost, + ConsultationDate = date, + ConsultationLawyers = client, + GuarantorId = APIClient.Guarantor.Id, + }); + Response.Redirect("/Home/Consultations"); + } + + [HttpGet] + public IActionResult UpdateConsultation() + { + if (APIClient.Guarantor == null) + { + return Redirect("~/Home/Enter"); + } + ViewBag.Lawyers = APIClient.GetRequest>($"api/lawyer/GetLawyerList?guarantorId={APIClient.Guarantor.Id}"); + return View(); + } + + [HttpPost] + public void UpdateConsultation(int id, int cost, DateTime date, List clientselect) + { + if (APIClient.Guarantor == null) + { + throw new Exception("Вы как суда попали? Суда вход только авторизованным"); + } + + Dictionary client = new Dictionary(); + foreach (int members in clientselect) + { + client.Add(members, new LawyerSearchModel { Id = members } as ILawyerModel); + } + + APIClient.PostRequest("api/consultation/updateconsultation", new ConsultationBindingModel + { + Id = id, + Cost = cost, + ConsultationDate = date, + ConsultationLawyers = client, + GuarantorId = APIClient.Guarantor.Id, + }); + Response.Redirect("/Home/Consultations"); + } + + [HttpPost] + public void DeleteConsultation(int id) + { + if (APIClient.Guarantor == null) + { + throw new Exception("Вы как суда попали? Суда вход только авторизованным"); + } + + APIClient.PostRequest("api/consultation/deleteconsultation", new ConsultationBindingModel + { + Id = id + }); + Response.Redirect("/Home/Consultations"); + } + + [HttpGet] + public IActionResult TopConsultation() + { + if (APIClient.Guarantor == null) + { + return Redirect("~/Home/Enter"); + } + var consultation = APIClient.GetRequest>($"api/consultation/GetConsultationList?guarantorId={APIClient.Guarantor.Id}"); + + var statusCounts = consultation + .GroupBy(c => c.Cost) + .Select(g => new + { + Cost = g.Key.ToString(), + Count = g.Count() + }) + .ToList(); + + ViewBag.StatusCounts = statusCounts; + + return View(); + } + } } \ No newline at end of file diff --git a/LawCompany/LawCompanyGuarantorApp/Controllers/HearingController.cs b/LawCompany/LawCompanyGuarantorApp/Controllers/HearingController.cs index a95a2e7..4845607 100644 --- a/LawCompany/LawCompanyGuarantorApp/Controllers/HearingController.cs +++ b/LawCompany/LawCompanyGuarantorApp/Controllers/HearingController.cs @@ -1,12 +1,143 @@ -using Microsoft.AspNetCore.Mvc; +using LawCompanyContracts.BindingModels; +using LawCompanyContracts.SearchModels; +using LawCompanyContracts.ViewModels; +using LawCompanyDatabaseImplement; +using LawCompanyDataModels.Models; +using Microsoft.AspNetCore.Mvc; namespace LawCompanyGuarantorApp.Controllers { - public class HearingController : Controller - { - public IActionResult Index() - { - return View(); - } - } + public class HearingController : Controller + { + [HttpGet] + public IActionResult HearingLawyers(int id) + { + if (APIClient.Guarantor == null) + { + return Redirect("~/Home/Enter"); + } + return View(APIClient.GetRequest>($"api/hearing/getlawyerlisttohearing?hearingId={id}")); + } + + [HttpGet] + public IActionResult CreateHearing() + { + if (APIClient.Guarantor == null) + { + return Redirect("~/Home/Enter"); + } + ViewBag.Lawyers = APIClient.GetRequest>($"api/lawyer/GetLawyerList?guarantorId={APIClient.Guarantor.Id}"); + return View(); + } + + [HttpPost] + public void CreateHearing(DateTime date, string judge, List clientselect) + { + if (APIClient.Guarantor == null) + { + throw new Exception("Вы как суда попали? Суда вход только авторизованным"); + } + + Dictionary client = new Dictionary(); + foreach (int members in clientselect) + { + client.Add(members, new LawyerSearchModel { Id = members } as ILawyerModel); + } + + APIClient.PostRequest("api/hearing/createhearing", new HearingBindingModel + { + HearingDate = date, + Judge = judge, + HearingLawyers = client, + GuarantorId = APIClient.Guarantor.Id, + }); + Response.Redirect("/Home/Hearings"); + } + + [HttpGet] + public IActionResult UpdateHearing() + { + if (APIClient.Guarantor == null) + { + return Redirect("~/Home/Enter"); + } + ViewBag.Lawyers = APIClient.GetRequest>($"api/lawyer/GetLawyerList?guarantorId={APIClient.Guarantor.Id}"); + return View(); + } + + [HttpPost] + public void UpdateHearing(int id, DateTime date, string judge, List clientselect) + { + if (APIClient.Guarantor == null) + { + throw new Exception("Вы как суда попали? Суда вход только авторизованным"); + } + + Dictionary client = new Dictionary(); + foreach (int members in clientselect) + { + client.Add(members, new LawyerSearchModel { Id = members } as ILawyerModel); + } + + APIClient.PostRequest("api/hearing/updatehearing", new HearingBindingModel + { + Id = id, + HearingDate = date, + Judge = judge, + HearingLawyers = client, + GuarantorId = APIClient.Guarantor.Id, + + }); + Response.Redirect("/Home/Hearings"); + } + + [HttpPost] + public void DeleteHearing(int id) + { + if (APIClient.Guarantor == null) + { + throw new Exception("Вы как суда попали? Суда вход только авторизованным"); + } + + APIClient.PostRequest("api/hearing/deletehearing", new HearingBindingModel + { + Id = id + }); + Response.Redirect("/Home/Hearings"); + } + + [HttpGet] + public IActionResult LawyerHearingCounts() + { + if (APIClient.Guarantor == null) + { + return Redirect("~/Home/Enter"); + } + + using (var context = new LawCompanyDatabase()) + { + var lawyers = context.Lawyers + .Where(c => c.GuarantorId == APIClient.Guarantor.Id) + .Select(c => new LawyerViewModel + { + Id = c.Id, + FIO = c.FIO, + Email = c.Email, + Phone = c.Phone, + GuarantorId = c.GuarantorId + }) + .ToList(); + + var lawyerHearingCounts = lawyers.Select(lawyer => new LawyerHearingCountViewModel + { + FIO = lawyer.FIO, + HearingCount = context.HearingLawyers.Count(vc => vc.LawyerId == lawyer.Id) + }).ToList(); + + ViewBag.LawyerHearingCounts = lawyerHearingCounts; + + return View(lawyerHearingCounts); + } + } + } } \ No newline at end of file diff --git a/LawCompany/LawCompanyGuarantorApp/Controllers/HomeController.cs b/LawCompany/LawCompanyGuarantorApp/Controllers/HomeController.cs index a2510c1..7ac2a87 100644 --- a/LawCompany/LawCompanyGuarantorApp/Controllers/HomeController.cs +++ b/LawCompany/LawCompanyGuarantorApp/Controllers/HomeController.cs @@ -1,4 +1,7 @@ -using LawCompanyGuarantorApp.Models; +using LawCompanyContracts.BindingModels; +using LawCompanyContracts.BusinessLogicContracts; +using LawCompanyContracts.ViewModels; +using LawCompanyGuarantorApp.Models; using Microsoft.AspNetCore.Mvc; using System.Diagnostics; @@ -7,20 +10,338 @@ namespace LawCompanyGuarantorApp.Controllers public class HomeController : Controller { private readonly ILogger _logger; + private readonly IReportGuarantorLogic _report; - public HomeController(ILogger logger) + public HomeController(ILogger logger, IReportGuarantorLogic report) { _logger = logger; + _report = report; } public IActionResult Index() { + if (APIClient.Guarantor == null) + { + return Redirect("~/Home/Enter"); + } return View(); } + public IActionResult Register() + { + return View(); + } + + [HttpPost] + public void Register(string fio, string email, string password) + { + if (string.IsNullOrEmpty(fio) || string.IsNullOrEmpty(email) || string.IsNullOrEmpty(password)) + { + throw new Exception("Введите фио, почту и пароль"); + } + APIClient.PostRequest("api/guarantor/register", new ExecutorBindingModel + { + FIO = fio, + Email = email, + Password = password, + }); + + Response.Redirect("Enter"); + return; + } + + public IActionResult Enter() + { + return View(); + } + + [HttpPost] + public void Enter(string email, string password) + { + if (string.IsNullOrEmpty(email) || string.IsNullOrEmpty(password)) + { + throw new Exception("Введите email и пароль"); + } + APIClient.Guarantor = APIClient.GetRequest($"api/guarantor/login?login={email}&password={password}"); + if (APIClient.Guarantor == null) + { + throw new Exception("Неверный логин/пароль"); + } + Response.Redirect("Index"); + } + public IActionResult Privacy() { - return View(); + if (APIClient.Guarantor == null) + { + return Redirect("~/Home/Enter"); + } + return View(APIClient.Guarantor); + } + + [HttpPost] + public void Privacy(string fio, string email, string password) + { + if (APIClient.Guarantor == null) + { + throw new Exception("Вы как сюда попали? Сюда вход только авторизованным"); + } + if (string.IsNullOrEmpty(fio) || string.IsNullOrEmpty(email) || string.IsNullOrEmpty(password)) + { + throw new Exception("Введите фио, почту и пароль"); + } + APIClient.PostRequest("api/guarantor/updatedata", new ExecutorBindingModel + { + Id = APIClient.Guarantor.Id, + FIO = fio, + Password = password, + Email = email, + }); + + APIClient.Guarantor.FIO = fio; + APIClient.Guarantor.Email = email; + APIClient.Guarantor.Password = password; + Response.Redirect("Index"); + } + + // СТРАНИЦЫ КОНСУЛЬТАЦИЙ + public IActionResult Consultations() + { + if (APIClient.Guarantor == null) + { + return Redirect("~/Home/Enter"); + } + return View(APIClient.GetRequest>($"api/consultation/GetConsultationList?guarantorId={APIClient.Guarantor.Id}")); + } + + // СТРАНИЦА СЛУШАНИЙ + public IActionResult Hearings() + { + if (APIClient.Guarantor == null) + { + return Redirect("~/Home/Enter"); + } + return View(APIClient.GetRequest>($"api/hearing/gethearinglist?guarantorId={APIClient.Guarantor.Id}")); + } + + // СТРАНИЦА ЮРИСТОВ + public IActionResult Lawyers() + { + if (APIClient.Guarantor == null) + { + return Redirect("~/Home/Enter"); + } + return View(APIClient.GetRequest>($"api/lawyer/getlawyerlist?guarantorId={APIClient.Guarantor.Id}")); + } + + public IActionResult ConsultationCase() + { + if (APIClient.Guarantor == null) + { + return Redirect("~/Home/Enter"); + } + ViewBag.Cases = APIClient.GetRequest>($"api/case/GetCaseList?executorId={APIClient.Guarantor.Id}"); + ViewBag.Consultations = APIClient.GetRequest>($"api/consultation/getconsultationlist?guarantorId={APIClient.Guarantor.Id}"); + return View(); + } + + [HttpPost] + public void ConsultationCase(int consultation, int cases) + { + if (APIClient.Guarantor == null) + { + throw new Exception("Вы как сюда попали? Сюда вход только авторизованным"); + } + var roomElem = APIClient.GetRequest($"api/Consultation/GetConsultation?id={consultation}"); + APIClient.PostRequest("api/Consultation/UpdateConsultation", new ConsultationBindingModel + { + Id = consultation, + GuarantorId = APIClient.Guarantor.Id, + Cost = roomElem.Cost, + ConsultationDate = roomElem.ConsultationDate, + CaseId = cases + }); + Response.Redirect("Index"); + } + + [HttpGet] + public IActionResult LawyerConsultationToFile() + { + if (APIClient.Guarantor == null) + { + return Redirect("~/Home/Enter"); + } + return View(APIClient.GetRequest>($"api/lawyer/getlawyerlist?guarantorId={APIClient.Guarantor.Id}")); + } + + [HttpPost] + public void LawyerConsultationToFile(int[] Ids, string type) + { + if (APIClient.Guarantor == null) + { + throw new Exception("Вы как суда попали? Суда вход только авторизованным"); + } + + if (Ids.Length <= 0) + { + throw new Exception("Количество должно быть больше 0"); + } + + if (string.IsNullOrEmpty(type)) + { + throw new Exception("Неверный тип отчета"); + } + + List res = new List(); + + foreach (var item in Ids) + { + res.Add(item); + } + + if (type == "docx") + { + APIClient.PostRequest("api/report/CreateGuarantorReportToWordFile", new ReportGuarantorBindingModel + { + Ids = res, + FileName = "C:\\Reports\\wordfile.docx" + }); + Response.Redirect("GetWordFile"); + } + else + { + APIClient.PostRequest("api/report/CreateGuarantorReportToExcelFile", new ReportGuarantorBindingModel + { + Ids = res, + FileName = "C:\\Reports\\excelfile.xlsx" + }); + Response.Redirect("GetExcelFile"); + } + } + + [HttpGet] + public IActionResult GetWordFile() + { + return new PhysicalFileResult("C:\\Reports\\wordfile.docx", "application/vnd.openxmlformats-officedocument.wordprocessingml.document"); + } + + [HttpGet] + public IActionResult GetExcelFile() + { + return new PhysicalFileResult("C:\\Reports\\excelfile.xlsx", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"); + } + + public IActionResult GetPdfFile() + { + return new PhysicalFileResult("C:\\Reports\\pdffile.pdf", "application/pdf"); + } + + [HttpGet] + public IActionResult LawyersToPdfFile() + { + if (APIClient.Guarantor == null) + { + return Redirect("~/Home/Enter"); + } + return View("LawyersToPdfFile"); + } + + [HttpPost] + public void LawyersToPdfFile(DateTime dateFrom, DateTime dateTo, string email) + { + if (APIClient.Guarantor == null) + { + throw new Exception("Вы как суда попали? Суда вход только авторизованным"); + } + if (string.IsNullOrEmpty(email)) + { + throw new Exception("Email пуст"); + } + APIClient.PostRequest("api/report/CreateGuarantorReportToPdfFile", new ReportGuarantorBindingModel + { + DateFrom = dateFrom, + DateTo = dateTo, + GuarantorId = APIClient.Guarantor.Id + }); + APIClient.PostRequest("api/report/SendPdfToMail", new MailSendInfoBindingModel + { + MailAddress = email, + Subject = "Отчет по юристам (pdf)", + Text = "Отчет по юристам с " + dateFrom.ToShortDateString() + " до " + dateTo.ToShortDateString() + }); + Response.Redirect("LawyersToPdfFile"); + } + + [HttpGet] + public string GetLawyersReport(DateTime dateFrom, DateTime dateTo) + { + if (APIClient.Guarantor == null) + { + throw new Exception("Вы как суда попали? Суда вход только авторизованным"); + } + List result; + try + { + result = _report.GetLawyers(new ReportGuarantorBindingModel + { + GuarantorId = APIClient.Guarantor.Id, + DateFrom = dateFrom, + DateTo = dateTo + }); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка создания отчета"); + throw; + } + string table = ""; + table += "

Предварительный отчет

"; + table += "
"; + table += ""; + table += ""; + table += ""; + table += ""; + table += ""; + table += ""; + table += ""; + table += ""; + table += ""; + table += ""; + foreach (var lawyer in result) + { + table += ""; + table += ""; + table += $""; + table += $""; + table += $""; + table += $""; + table += $""; + table += ""; + foreach (var cons in lawyer.Consultation) + { + table += ""; + table += $""; + table += $""; + table += $""; + table += $""; + table += $""; + table += ""; + } + foreach (var hear in lawyer.Hearing) + { + table += ""; + table += $""; + table += $""; + table += $""; + table += $""; + table += $""; + table += ""; + } + table += ""; + } + table += "
ЮристЦена консультацииДата консультацииСудДата слушания
{lawyer.FIO}
{cons.ConsultationDate}{cons.Price}
{hear.Judge}{hear.HearingDate}
"; + table += "
"; + return table; } [ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)] diff --git a/LawCompany/LawCompanyGuarantorApp/Controllers/LawyerController.cs b/LawCompany/LawCompanyGuarantorApp/Controllers/LawyerController.cs index bbf2f71..8ccd966 100644 --- a/LawCompany/LawCompanyGuarantorApp/Controllers/LawyerController.cs +++ b/LawCompany/LawCompanyGuarantorApp/Controllers/LawyerController.cs @@ -1,12 +1,81 @@ -using Microsoft.AspNetCore.Mvc; +using LawCompanyContracts.BindingModels; +using LawCompanyContracts.ViewModels; +using Microsoft.AspNetCore.Mvc; namespace LawCompanyGuarantorApp.Controllers { public class LawyerController : Controller { - public IActionResult Index() - { - return View(); + [HttpGet] + public IActionResult CreateLawyer() + { + if (APIClient.Guarantor == null) + { + return Redirect("~/Home/Enter"); + } + return View(); + } + [HttpPost] + public void CreateLawyer(string fio, string phone, string email) + { + if (APIClient.Guarantor == null) + { + throw new Exception("Вы как суда попали? Суда вход только авторизованным"); + } + + APIClient.PostRequest("api/lawyer/createlawyer", new LawyerBindingModel + { + FIO = fio, + Phone = phone, + Email = email, + GuarantorId = APIClient.Guarantor.Id, + }); + Response.Redirect("/Home/Lawyers"); + } + + [HttpPost] + public void DeleteLawyer(int id) + { + if (APIClient.Guarantor == null) + { + throw new Exception("Вы как суда попали? Суда вход только авторизованным"); + } + + APIClient.PostRequest("api/lawyer/deletelawyer", new LawyerBindingModel + { + Id = id + }); + Response.Redirect("/Home/Lawyers"); + } + + [HttpGet] + public IActionResult UpdateLawyer(int id) + { + if (APIClient.Guarantor == null) + { + return Redirect("~/Home/Enter"); + } + var lawyer = APIClient.GetRequest($"api/lawyer/GetLawyerById/{id}"); + return View(lawyer); } - } + + [HttpPost] + public void UpdateLawyer(int id, string fio, string email, string phone) + { + if (APIClient.Guarantor == null) + { + throw new Exception("Вы как суда попали? Суда вход только авторизованным"); + } + + APIClient.PostRequest("api/lawyer/updatelawyer", new LawyerBindingModel + { + Id = id, + FIO = fio, + Email = email, + Phone = phone, + GuarantorId = APIClient.Guarantor.Id, + }); + Response.Redirect("/Home/Lawyers"); + } + } } \ No newline at end of file diff --git a/LawCompany/LawCompanyGuarantorApp/LawCompanyGuarantorApp.csproj b/LawCompany/LawCompanyGuarantorApp/LawCompanyGuarantorApp.csproj index 0866581..3f0a4da 100644 --- a/LawCompany/LawCompanyGuarantorApp/LawCompanyGuarantorApp.csproj +++ b/LawCompany/LawCompanyGuarantorApp/LawCompanyGuarantorApp.csproj @@ -11,8 +11,10 @@ + + diff --git a/LawCompany/LawCompanyGuarantorApp/Program.cs b/LawCompany/LawCompanyGuarantorApp/Program.cs index 8f51513..424a627 100644 --- a/LawCompany/LawCompanyGuarantorApp/Program.cs +++ b/LawCompany/LawCompanyGuarantorApp/Program.cs @@ -1,11 +1,24 @@ +using HotelBusinessLogic.BusinessLogics; +using LawCompanyBusinessLogic.BusinessLogics; +using LawCompanyBusinessLogic.OfficePackage.Implements; +using LawCompanyBusinessLogic.OfficePackage; +using LawCompanyContracts.BusinessLogicContracts; using LawCompanyContracts.StoragesContracts; using LawCompanyDatabaseImplement.Implements; using LawCompanyGuarantorApp; var builder = WebApplication.CreateBuilder(args); -builder.Services.AddTransient(); +builder.Services.AddTransient(); +builder.Services.AddTransient(); +builder.Services.AddTransient(); +builder.Services.AddTransient(); builder.Services.AddTransient(); builder.Services.AddTransient(); +builder.Services.AddTransient(); + +builder.Services.AddTransient(); +builder.Services.AddTransient(); +builder.Services.AddTransient(); // Add services to the container. builder.Services.AddControllersWithViews(); @@ -14,12 +27,11 @@ var app = builder.Build(); APIClient.Connect(builder.Configuration); // Configure the HTTP request pipeline. -if (!app.Environment.IsDevelopment()) -{ - app.UseExceptionHandler("/Home/Error"); - // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts. - app.UseHsts(); -} + +app.UseExceptionHandler("/Home/Error"); +// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts. +app.UseHsts(); + app.UseHttpsRedirection(); app.UseStaticFiles(); @@ -30,6 +42,6 @@ app.UseAuthorization(); app.MapControllerRoute( name: "default", - pattern: "{controller=Home}/{action=EnterGuarantor}/{id?}"); + pattern: "{controller=Home}/{action=Index}/{id?}"); app.Run(); diff --git a/LawCompany/LawCompanyGuarantorApp/Views/Consultation/AddLawyer.cshtml b/LawCompany/LawCompanyGuarantorApp/Views/Consultation/AddLawyer.cshtml deleted file mode 100644 index 79b62dc..0000000 --- a/LawCompany/LawCompanyGuarantorApp/Views/Consultation/AddLawyer.cshtml +++ /dev/null @@ -1,30 +0,0 @@ -@{ - ViewData["Title"] = "Добавление юристов"; - Layout = "~/Views/Shared/_LayoutGuarantor.cshtml"; -} - -
-

Добавить юристов

-
-
- -
-
Юрист
-
- -
-
-
-
Консультация
-
- -
-
-
-
-
- -
-
-
diff --git a/LawCompany/LawCompanyGuarantorApp/Views/Consultation/CreateConsultation.cshtml b/LawCompany/LawCompanyGuarantorApp/Views/Consultation/CreateConsultation.cshtml index 884dc71..e17320f 100644 --- a/LawCompany/LawCompanyGuarantorApp/Views/Consultation/CreateConsultation.cshtml +++ b/LawCompany/LawCompanyGuarantorApp/Views/Consultation/CreateConsultation.cshtml @@ -1,6 +1,8 @@ -@{ +@using LawCompanyContracts.ViewModels; +@using LawCompanyDataModels.Models; + +@{ ViewData["Title"] = "Создание консультацию"; - Layout = "~/Views/Shared/_LayoutGuarantor.cshtml"; }
@@ -10,19 +12,23 @@
Стоимость
- +
Дата и время
- +
-
-
Дело
+
- +
diff --git a/LawCompany/LawCompanyGuarantorApp/Views/Consultation/TopConsultation.cshtml b/LawCompany/LawCompanyGuarantorApp/Views/Consultation/TopConsultation.cshtml new file mode 100644 index 0000000..71e46f7 --- /dev/null +++ b/LawCompany/LawCompanyGuarantorApp/Views/Consultation/TopConsultation.cshtml @@ -0,0 +1,46 @@ +@using LawCompanyContracts.ViewModels; +@{ + ViewData["Title"] = "Top Consultation"; + var statusCounts = ViewBag.StatusCounts; +} + + + + + + + +
+
+
+ + + diff --git a/LawCompany/LawCompanyGuarantorApp/Views/Consultation/UpdateConsultation.cshtml b/LawCompany/LawCompanyGuarantorApp/Views/Consultation/UpdateConsultation.cshtml index 1c8a333..99f2613 100644 --- a/LawCompany/LawCompanyGuarantorApp/Views/Consultation/UpdateConsultation.cshtml +++ b/LawCompany/LawCompanyGuarantorApp/Views/Consultation/UpdateConsultation.cshtml @@ -1,4 +1,8 @@ -@{ +@using LawCompanyContracts.ViewModels; +@using LawCompanyDataModels.Models; + + +@{ ViewData["Title"] = "Обновление консультации"; Layout = "~/Views/Shared/_LayoutGuarantor.cshtml"; } @@ -10,19 +14,23 @@
Стоимость
- +
-
Дата
+
Дата и время
- +
-
-
Дело
+
- +
diff --git a/LawCompany/LawCompanyGuarantorApp/Views/Hearing/AddLawyer.cshtml b/LawCompany/LawCompanyGuarantorApp/Views/Hearing/AddLawyer.cshtml deleted file mode 100644 index 75c9453..0000000 --- a/LawCompany/LawCompanyGuarantorApp/Views/Hearing/AddLawyer.cshtml +++ /dev/null @@ -1,30 +0,0 @@ -@{ - ViewData["Title"] = "Добавить юристов"; - Layout = "~/Views/Shared/_LayoutGuarantor.cshtml"; -} - -
-

Добавить юристов

-
-
- -
-
Слушание
-
- -
-
-
-
Юрист
-
- -
-
-
-
-
- -
-
-
diff --git a/LawCompany/LawCompanyGuarantorApp/Views/Hearing/CreateHearing.cshtml b/LawCompany/LawCompanyGuarantorApp/Views/Hearing/CreateHearing.cshtml index 663944a..27d0b1b 100644 --- a/LawCompany/LawCompanyGuarantorApp/Views/Hearing/CreateHearing.cshtml +++ b/LawCompany/LawCompanyGuarantorApp/Views/Hearing/CreateHearing.cshtml @@ -1,4 +1,7 @@ -@{ +@using LawCompanyContracts.ViewModels; +@using LawCompanyDataModels.Models; + +@{ ViewData["Title"] = "Назначение слушания"; Layout = "~/Views/Shared/_LayoutGuarantor.cshtml"; } @@ -19,6 +22,16 @@
+
+
+ +
+
diff --git a/LawCompany/LawCompanyGuarantorApp/Views/Hearing/HearingLawyers.cshtml b/LawCompany/LawCompanyGuarantorApp/Views/Hearing/HearingLawyers.cshtml index e2af95a..bb39e2c 100644 --- a/LawCompany/LawCompanyGuarantorApp/Views/Hearing/HearingLawyers.cshtml +++ b/LawCompany/LawCompanyGuarantorApp/Views/Hearing/HearingLawyers.cshtml @@ -2,7 +2,6 @@ @model List @{ ViewData["Title"] = "Юристы"; - Layout = "~/Views/Shared/_LayoutGuarantor.cshtml"; }

Юристы

@@ -36,20 +35,16 @@ { - @Html.DisplayFor(modelItem => - item.Id) + @Html.DisplayFor(modelItem => item.Id) - @Html.DisplayFor(modelItem => - item.FIO) + @Html.DisplayFor(modelItem => item.FIO) - @Html.DisplayFor(modelItem => - item.Email) + @Html.DisplayFor(modelItem => item.Email) - @Html.DisplayFor(modelItem => - item.Phone) + @Html.DisplayFor(modelItem => item.Phone) } diff --git a/LawCompany/LawCompanyGuarantorApp/Views/Hearing/LawyerHearingCounts.cshtml b/LawCompany/LawCompanyGuarantorApp/Views/Hearing/LawyerHearingCounts.cshtml new file mode 100644 index 0000000..da8127e --- /dev/null +++ b/LawCompany/LawCompanyGuarantorApp/Views/Hearing/LawyerHearingCounts.cshtml @@ -0,0 +1,44 @@ +@using LawCompanyContracts.ViewModels; + +@model List + +@{ + ViewData["Title"] = "Количество слушаний юристов"; +} + + + + + @ViewData["Title"] + + + +
+ + + + diff --git a/LawCompany/LawCompanyGuarantorApp/Views/Hearing/UpdateHearing.cshtml b/LawCompany/LawCompanyGuarantorApp/Views/Hearing/UpdateHearing.cshtml index 5500197..97d77cd 100644 --- a/LawCompany/LawCompanyGuarantorApp/Views/Hearing/UpdateHearing.cshtml +++ b/LawCompany/LawCompanyGuarantorApp/Views/Hearing/UpdateHearing.cshtml @@ -1,6 +1,8 @@ -@{ +@using LawCompanyContracts.ViewModels; +@using LawCompanyDataModels.Models; + +@{ ViewData["Title"] = "UpdateHearing"; - Layout = "~/Views/Shared/_LayoutGuarantor.cshtml"; }
@@ -19,6 +21,16 @@
+
+
+ +
+
diff --git a/LawCompany/LawCompanyGuarantorApp/Views/Home/ConsultationCase.cshtml b/LawCompany/LawCompanyGuarantorApp/Views/Home/ConsultationCase.cshtml new file mode 100644 index 0000000..61de26c --- /dev/null +++ b/LawCompany/LawCompanyGuarantorApp/Views/Home/ConsultationCase.cshtml @@ -0,0 +1,22 @@ +@using LawCompanyContracts.ViewModels; + +@{ + ViewData["Title"] = "ConsultationCase"; +} + +
+

Связывание консультации и дела

+
+
+
+ + +
+
+ + +
+
+ +
+
diff --git a/LawCompany/LawCompanyGuarantorApp/Views/Home/Consultation.cshtml b/LawCompany/LawCompanyGuarantorApp/Views/Home/Consultations.cshtml similarity index 52% rename from LawCompany/LawCompanyGuarantorApp/Views/Home/Consultation.cshtml rename to LawCompany/LawCompanyGuarantorApp/Views/Home/Consultations.cshtml index 8b27d6c..f424486 100644 --- a/LawCompany/LawCompanyGuarantorApp/Views/Home/Consultation.cshtml +++ b/LawCompany/LawCompanyGuarantorApp/Views/Home/Consultations.cshtml @@ -2,7 +2,6 @@ @model List @{ ViewData["Title"] = "Create Consultation"; - Layout = "~/Views/Shared/_LayoutGuarantor.cshtml"; }

Список консультаций

@@ -11,7 +10,6 @@ @{

Назначить консультацию - Добавить юристов к консультациям

@@ -25,9 +23,6 @@ - @@ -35,25 +30,31 @@ { } diff --git a/LawCompany/LawCompanyGuarantorApp/Views/Home/EnterGuarantor.cshtml b/LawCompany/LawCompanyGuarantorApp/Views/Home/Enter.cshtml similarity index 100% rename from LawCompany/LawCompanyGuarantorApp/Views/Home/EnterGuarantor.cshtml rename to LawCompany/LawCompanyGuarantorApp/Views/Home/Enter.cshtml diff --git a/LawCompany/LawCompanyGuarantorApp/Views/Home/Hearings.cshtml b/LawCompany/LawCompanyGuarantorApp/Views/Home/Hearings.cshtml index a8146d4..9b77798 100644 --- a/LawCompany/LawCompanyGuarantorApp/Views/Home/Hearings.cshtml +++ b/LawCompany/LawCompanyGuarantorApp/Views/Home/Hearings.cshtml @@ -2,7 +2,6 @@ @model List @{ ViewData["Title"] = "Create Hearing"; - Layout = "~/Views/Shared/_LayoutGuarantor.cshtml"; }
Дата консультации - Наименование дела -
- @Html.DisplayFor(modelItem => - item.Id) + @Html.DisplayFor(modelItem => item.Id) - @Html.DisplayFor(modelItem => - item.Cost) + @Html.DisplayFor(modelItem => item.Cost) - @Html.DisplayFor(modelItem => - item.CaseName) + @Html.DisplayFor(modelItem => item.ConsultationDate) - +
+ + +
- +
+ + +
- +
+ + +
@@ -32,25 +30,31 @@ { } diff --git a/LawCompany/LawCompanyGuarantorApp/Views/Home/LawyerConsultationToFile.cshtml b/LawCompany/LawCompanyGuarantorApp/Views/Home/LawyerConsultationToFile.cshtml new file mode 100644 index 0000000..a325fe8 --- /dev/null +++ b/LawCompany/LawCompanyGuarantorApp/Views/Home/LawyerConsultationToFile.cshtml @@ -0,0 +1,73 @@ +@using LawCompanyContracts.ViewModels + +@model List + +@{ + ViewData["Title"] = "LawyerConsultationToFile"; +} + +
+
+

Создание отчёта по юристам

+
+
+ +
+
+
+ +
+ + +
+
+ + +
+
+
+
- @Html.DisplayFor(modelItem => - item.Id) + @Html.DisplayFor(modelItem => item.Id) - @Html.DisplayFor(modelItem => - item.HearingDate) + @Html.DisplayFor(modelItem => item.HearingDate) - @Html.DisplayFor(modelItem => - item.Judge) + @Html.DisplayFor(modelItem => item.Judge) - +
+ + +
- +
+ + +
- +
+ + +
+ + + + + + + + + @foreach (var item in Model) + { + + + + + + } + +
ФИОПочта
+
+ +
+
@Html.DisplayFor(modelItem => item.FIO)@Html.DisplayFor(modelItem => item.Email)
+
+
+
+ +
+ +
+ + \ No newline at end of file diff --git a/LawCompany/LawCompanyGuarantorApp/Views/Home/Lawyers.cshtml b/LawCompany/LawCompanyGuarantorApp/Views/Home/Lawyers.cshtml index 39c5889..122b539 100644 --- a/LawCompany/LawCompanyGuarantorApp/Views/Home/Lawyers.cshtml +++ b/LawCompany/LawCompanyGuarantorApp/Views/Home/Lawyers.cshtml @@ -39,27 +39,29 @@ { - @Html.DisplayFor(modelItem => - item.Id) + @Html.DisplayFor(modelItem => item.Id) - @Html.DisplayFor(modelItem => - item.FIO) + @Html.DisplayFor(modelItem => item.FIO) - @Html.DisplayFor(modelItem => - item.Phone) + @Html.DisplayFor(modelItem => item.Phone) - @Html.DisplayFor(modelItem => - item.Email) + @Html.DisplayFor(modelItem => item.Email) - - +
+ + +
+ - +
+ + +
} diff --git a/LawCompany/LawCompanyGuarantorApp/Views/Home/LawyersToPdfFile.cshtml b/LawCompany/LawCompanyGuarantorApp/Views/Home/LawyersToPdfFile.cshtml new file mode 100644 index 0000000..a47e8e6 --- /dev/null +++ b/LawCompany/LawCompanyGuarantorApp/Views/Home/LawyersToPdfFile.cshtml @@ -0,0 +1,72 @@ +@using LawCompanyContracts.ViewModels + +@{ + ViewData["Title"] = "LawyersToPdfFile"; +} + +
+
+

Отчет по юристам за период

+
+ +
+
+
+
+ + +
+
+
+
+ + +
+
+
+ +
+ + +
+ +
+
+
+ +
+
+ +
+
+
+ +
+
+ +
+
+
+ +@section Scripts { + +} \ No newline at end of file diff --git a/LawCompany/LawCompanyGuarantorApp/Views/Home/PrivacyGuarantor.cshtml b/LawCompany/LawCompanyGuarantorApp/Views/Home/Privacy.cshtml similarity index 100% rename from LawCompany/LawCompanyGuarantorApp/Views/Home/PrivacyGuarantor.cshtml rename to LawCompany/LawCompanyGuarantorApp/Views/Home/Privacy.cshtml diff --git a/LawCompany/LawCompanyGuarantorApp/Views/Home/RegisterGuarantor.cshtml b/LawCompany/LawCompanyGuarantorApp/Views/Home/Register.cshtml similarity index 100% rename from LawCompany/LawCompanyGuarantorApp/Views/Home/RegisterGuarantor.cshtml rename to LawCompany/LawCompanyGuarantorApp/Views/Home/Register.cshtml diff --git a/LawCompany/LawCompanyGuarantorApp/Views/Lawyer/CreateLawyer.cshtml b/LawCompany/LawCompanyGuarantorApp/Views/Lawyer/CreateLawyer.cshtml index 16c8aa4..88ea130 100644 --- a/LawCompany/LawCompanyGuarantorApp/Views/Lawyer/CreateLawyer.cshtml +++ b/LawCompany/LawCompanyGuarantorApp/Views/Lawyer/CreateLawyer.cshtml @@ -16,7 +16,7 @@
Номер телефона
- +
diff --git a/LawCompany/LawCompanyGuarantorApp/Views/Lawyer/UpdateLawyer.cshtml b/LawCompany/LawCompanyGuarantorApp/Views/Lawyer/UpdateLawyer.cshtml index f9a12a5..3097375 100644 --- a/LawCompany/LawCompanyGuarantorApp/Views/Lawyer/UpdateLawyer.cshtml +++ b/LawCompany/LawCompanyGuarantorApp/Views/Lawyer/UpdateLawyer.cshtml @@ -1,4 +1,7 @@ -@{ +@using LawCompanyContracts.ViewModels +@model LawyerViewModel + +@{ ViewData["Title"] = "Обновить юриста"; Layout = "~/Views/Shared/_LayoutGuarantor.cshtml"; } @@ -6,29 +9,31 @@

Изменение юриста

-
-
-
ФИО
-
- -
-
-
-
Номер телефона
-
- -
-
-
-
E-mail
-
- -
-
-
-
-
- -
-
+ + +
+
ФИО
+
+ +
+
+
+
Номер телефона
+
+ +
+
+
+
E-mail
+
+ +
+
+
+
+
+ +
+
+ diff --git a/LawCompany/LawCompanyGuarantorApp/Views/Shared/_LayoutGuarantor.cshtml b/LawCompany/LawCompanyGuarantorApp/Views/Shared/_LayoutGuarantor.cshtml index 01d2b6c..bb0cd67 100644 --- a/LawCompany/LawCompanyGuarantorApp/Views/Shared/_LayoutGuarantor.cshtml +++ b/LawCompany/LawCompanyGuarantorApp/Views/Shared/_LayoutGuarantor.cshtml @@ -20,25 +20,38 @@ diff --git a/LawCompany/LawCompanyRestApi/Controllers/ConsultationController.cs b/LawCompany/LawCompanyRestApi/Controllers/ConsultationController.cs index 92aa328..2b34540 100644 --- a/LawCompany/LawCompanyRestApi/Controllers/ConsultationController.cs +++ b/LawCompany/LawCompanyRestApi/Controllers/ConsultationController.cs @@ -23,6 +23,7 @@ namespace LawCompanyRestApi.Controllers _lawyerlogic = lawyerLogic; } + [HttpGet] public List? GetConsultationList(int guarantorId) { @@ -40,6 +41,26 @@ namespace LawCompanyRestApi.Controllers } } + [HttpGet] + public ConsultationViewModel? GetConsultation(int id) + { + try + { + var elem = _logic.ReadElement(new ConsultationSearchModel { Id = id, }); + if (elem == null) + { + return null; + } + elem.ConsultationLawyers = null!; + return elem; + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка получения списка продуктов"); + throw; + } + } + [HttpPost] public void CreateConsultation(ConsultationBindingModel model) { diff --git a/LawCompany/LawCompanyRestApi/Controllers/HearingController.cs b/LawCompany/LawCompanyRestApi/Controllers/HearingController.cs index 9671a63..6ffb20c 100644 --- a/LawCompany/LawCompanyRestApi/Controllers/HearingController.cs +++ b/LawCompany/LawCompanyRestApi/Controllers/HearingController.cs @@ -16,8 +16,7 @@ namespace LawCompanyRestApi.Controllers private readonly IHearingLogic _logic; private readonly ILawyerLogic _lawyerlogic; - public HearingController(IHearingLogic logic, ILogger - logger, ILawyerLogic lawyerlogic) + public HearingController(IHearingLogic logic, ILogger logger, ILawyerLogic lawyerlogic) { _logger = logger; _logic = logic; diff --git a/LawCompany/LawCompanyRestApi/Controllers/LawyerController.cs b/LawCompany/LawCompanyRestApi/Controllers/LawyerController.cs index 7e44f4a..cbc344c 100644 --- a/LawCompany/LawCompanyRestApi/Controllers/LawyerController.cs +++ b/LawCompany/LawCompanyRestApi/Controllers/LawyerController.cs @@ -34,6 +34,20 @@ namespace LawCompanyRestApi.Controllers } } + [HttpGet("{id}")] + public LawyerViewModel? GetLawyerById(int id) + { + try + { + return _logic.ReadElement(new LawyerSearchModel { Id = id }); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка получения данных клиента"); + throw; + } + } + [HttpPost] public void CreateLawyer(LawyerBindingModel model) { diff --git a/LawCompany/LawCompanyRestApi/Controllers/ReportController.cs b/LawCompany/LawCompanyRestApi/Controllers/ReportController.cs index b305fa5..562cca4 100644 --- a/LawCompany/LawCompanyRestApi/Controllers/ReportController.cs +++ b/LawCompany/LawCompanyRestApi/Controllers/ReportController.cs @@ -42,20 +42,6 @@ namespace HotelRestApi.Controllers } } - [HttpPost] - public void SendPdfToMail(MailSendInfoBindingModel model) - { - try - { - _mailWorker.MailSendAsync(model); - } - catch (Exception ex) - { - _logger.LogError(ex, "Ошибка отправки письма"); - throw; - } - } - [HttpPost] public void CreateExecutorReportToWordFile(ReportExecutorBindingModel model) { @@ -71,7 +57,7 @@ namespace HotelRestApi.Controllers } [HttpPost] - public void CreateOrganiserReportToExcelFile(ReportExecutorBindingModel model) + public void CreateExecutorReportToExcelFile(ReportExecutorBindingModel model) { try { @@ -84,12 +70,12 @@ namespace HotelRestApi.Controllers } } - /*[HttpPost] - public void CreateHeadwaiterReportToWordFile(ReportHeadwaiterBindingModel model) + [HttpPost] + public void CreateGuarantorReportToWordFile(ReportGuarantorBindingModel model) { try { - _reportHeadwaiterLogic.SaveLunchRoomToWordFile(model); + _reportGuarantorLogic.SaveLawyerHearingToWordFile(model); } catch (Exception ex) { @@ -99,11 +85,11 @@ namespace HotelRestApi.Controllers } [HttpPost] - public void CreateHeadwaiterReportToExcelFile(ReportHeadwaiterBindingModel model) + public void CreateGuarantorReportToExcelFile(ReportGuarantorBindingModel model) { try { - _reportHeadwaiterLogic.SaveLunchRoomToExcelFile(model); + _reportGuarantorLogic.SaveLawyerHearingToExcelFile(model); } catch (Exception ex) { @@ -113,16 +99,16 @@ namespace HotelRestApi.Controllers } [HttpPost] - public void CreateHeadwaiterReportToPdfFile(ReportHeadwaiterBindingModel model) + public void CreateGuarantorReportToPdfFile(ReportGuarantorBindingModel model) { try { - _reportHeadwaiterLogic.SaveLunchesToPdfFile(new ReportHeadwaiterBindingModel + _reportGuarantorLogic.SaveLawyersToPdfFile(new ReportGuarantorBindingModel { FileName = "C:\\Reports\\pdffile.pdf", DateFrom = model.DateFrom, DateTo = model.DateTo, - HeadwaiterId = model.HeadwaiterId, + GuarantorId = model.GuarantorId, }); } catch (Exception ex) @@ -130,6 +116,20 @@ namespace HotelRestApi.Controllers _logger.LogError(ex, "Ошибка создания отчета"); throw; } - }*/ + } + + [HttpPost] + public void SendPdfToMail(MailSendInfoBindingModel model) + { + try + { + _mailWorker.MailSendAsync(model); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка отправки письма"); + throw; + } + } } } diff --git a/LawCompany/LawCompanyRestApi/Controllers/VisitController.cs b/LawCompany/LawCompanyRestApi/Controllers/VisitController.cs index 93c83c2..7075f54 100644 --- a/LawCompany/LawCompanyRestApi/Controllers/VisitController.cs +++ b/LawCompany/LawCompanyRestApi/Controllers/VisitController.cs @@ -40,12 +40,17 @@ namespace LawCompanyRestApi.Controllers } } - [HttpGet("{id}")] - public VisitViewModel? GetVisit(int id) + [HttpGet] + public VisitViewModel GetVisit(int id) { try { - return _logic.ReadElement(new VisitSearchModel { Id = id, }); + var elem = _logic.ReadElement(new VisitSearchModel { Id = id, }); + if (elem == null) + { + return null; + } + return elem; } catch (Exception ex) { diff --git a/LawCompany/LawCompanyRestApi/Program.cs b/LawCompany/LawCompanyRestApi/Program.cs index 4300e1e..b05c6ba 100644 --- a/LawCompany/LawCompanyRestApi/Program.cs +++ b/LawCompany/LawCompanyRestApi/Program.cs @@ -46,6 +46,10 @@ builder.Services.AddTransient(); builder.Services.AddTransient(); builder.Services.AddTransient(); +builder.Services.AddTransient(); +builder.Services.AddTransient(); +builder.Services.AddTransient(); + builder.Services.AddSingleton(); builder.Services.AddControllers();