7. Логика привязки статей затрат, логика отчетов, заглушка для роли Worker, имитация роли Worker
This commit is contained in:
parent
c48df11a64
commit
83232b242d
42
LawFirm/LawFirmBusinessLogic/BusinessLogics/ReportLogic.cs
Normal file
42
LawFirm/LawFirmBusinessLogic/BusinessLogics/ReportLogic.cs
Normal file
@ -0,0 +1,42 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using LawFirmContracts.BindingModels;
|
||||
using LawFirmContracts.BusinessLogicsContracts;
|
||||
using LawFirmContracts.SearchModels;
|
||||
using LawFirmContracts.StorageContracts;
|
||||
using LawFirmContracts.ViewModels;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace LawFirmBusinessLogic.BusinessLogics
|
||||
{
|
||||
public class ReportLogic : IReportLogic
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly IServiceStorage _serviceStorage;
|
||||
public ReportLogic(ILogger logger, IServiceStorage serviceStorage)
|
||||
{
|
||||
_logger = logger;
|
||||
_serviceStorage = serviceStorage;
|
||||
}
|
||||
public List<ReportLawServicesViewModel> GetRequestsByServices(ReportBindingModel model)
|
||||
{
|
||||
_logger.LogInformation("Reading requests by services");
|
||||
return _serviceStorage.GetServicesWithRequest(new() { SelectedServicesIds = model.SelectedServices });
|
||||
}
|
||||
public void SaveComponentsToWordFile(ReportBindingModel model)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
public void SaveManufactureComponentToExcelFile(ReportBindingModel model)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
public void SaveOrdersToPdfFile(ReportBindingModel model)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,76 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using LawFirmContracts.BusinessLogicsContracts;
|
||||
|
||||
namespace LawFirmBusinessLogic.BusinessLogics
|
||||
{
|
||||
public class WorkerRoleImitationLogic
|
||||
{
|
||||
private readonly IWorkerLogic _workerLogic;
|
||||
private readonly IServiceLogic _serviceLogic;
|
||||
public WorkerRoleImitationLogic(IWorkerLogic workerLogic, IServiceLogic serviceLogic)
|
||||
{
|
||||
_workerLogic = workerLogic;
|
||||
_serviceLogic = serviceLogic;
|
||||
}
|
||||
private bool GenerateWorkerData()
|
||||
{
|
||||
if (_workerLogic.ReadList(null)?.Count != 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
using (StreamReader sr = new("workers.txt"))
|
||||
{
|
||||
string? currentString;
|
||||
while ((currentString = sr.ReadLine()) != null)
|
||||
{
|
||||
var workerRecData = currentString.Split(',');
|
||||
_workerLogic.Create(new()
|
||||
{
|
||||
Login = workerRecData[0],
|
||||
Password = workerRecData[1],
|
||||
Name = workerRecData[2],
|
||||
Surname = workerRecData[3]
|
||||
});
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
public bool GenerateServices()
|
||||
{
|
||||
var ServicesList = _serviceLogic.ReadList(null);
|
||||
if (ServicesList == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (ServicesList.Count == 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
var RequestList = _serviceLogic.ReadList(null);
|
||||
if (RequestList == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (RequestList.Count == 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
Random r = new();
|
||||
for (int i = 0; i < 2; i++)
|
||||
{
|
||||
_serviceLogic.Create(new()
|
||||
{
|
||||
Id = r.Next(0, RequestList.Count),
|
||||
CaseId = r.Next(0, ServicesList.Count),
|
||||
ItemId = r.Next(0, ServicesList.Count)
|
||||
});
|
||||
}
|
||||
return true;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
@ -12,7 +12,7 @@ namespace LawFirmContracts.BindingModels
|
||||
/// <summary>
|
||||
/// Выбранные работы для отчета по заявкам
|
||||
/// </summary>
|
||||
public List<int>? SelectedWorks { get; set; }
|
||||
public List<int>? SelectedServices { get; set; }
|
||||
/// <summary>
|
||||
/// Начало периода для отчета по оплатам
|
||||
/// </summary>
|
||||
|
@ -0,0 +1,34 @@
|
||||
using LawFirmContracts.BindingModels;
|
||||
using LawFirmContracts.ViewModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace LawFirmContracts.BusinessLogicsContracts
|
||||
{
|
||||
public interface IReportLogic
|
||||
{
|
||||
/// <summary>
|
||||
/// Получение списка
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
List<ReportLawServicesViewModel> GetRequestsByServices(ReportBindingModel model);
|
||||
/// <summary>
|
||||
/// Сохранение в файл-Word
|
||||
/// </summary>
|
||||
/// <param name="model"></param>
|
||||
void SaveComponentsToWordFile(ReportBindingModel model);
|
||||
/// <summary>
|
||||
/// Сохранение в файл-Excel
|
||||
/// </summary>
|
||||
/// <param name="model"></param>
|
||||
void SaveManufactureComponentToExcelFile(ReportBindingModel model);
|
||||
/// <summary>
|
||||
/// Сохранение заказов в файл-Pdf
|
||||
/// </summary>
|
||||
/// <param name="model"></param>
|
||||
void SaveOrdersToPdfFile(ReportBindingModel model);
|
||||
}
|
||||
}
|
@ -9,5 +9,7 @@ namespace LawFirmContracts.SearchModels
|
||||
public class ServiceSearchModel
|
||||
{
|
||||
public int? Id { get; set; }
|
||||
public string? Name { get; set; }
|
||||
public List<int>? SelectedServicesIds { get; set; }
|
||||
}
|
||||
}
|
||||
|
@ -13,6 +13,7 @@ namespace LawFirmContracts.StorageContracts
|
||||
{
|
||||
List<ServiceViewModel> GetFullList();
|
||||
List<ServiceViewModel> GetFilteredList(ServiceSearchModel model);
|
||||
List<ReportLawServicesViewModel> GetServicesWithRequest(ServiceSearchModel model);
|
||||
ServiceViewModel? GetElement(ServiceSearchModel model);
|
||||
ServiceViewModel? Insert(ServiceBindingModel model);
|
||||
ServiceViewModel? Update(ServiceBindingModel model);
|
||||
|
@ -11,5 +11,9 @@ namespace LawFirmContracts.ViewModels
|
||||
/// </summary>
|
||||
public class ReportCasesViewModel
|
||||
{
|
||||
public int CaseRequestId { get; set; }
|
||||
public DateTime CaseRequestDateCreated { get; set; } = DateTime.Now;
|
||||
public string CustomerName { get; set; } = string.Empty;
|
||||
public string WorkerName { get; set; } = string.Empty;
|
||||
}
|
||||
}
|
||||
|
@ -11,5 +11,7 @@ namespace LawFirmContracts.ViewModels
|
||||
/// </summary>
|
||||
public class ReportLawServicesViewModel
|
||||
{
|
||||
public string ServiceName { get; set; } = string.Empty;
|
||||
public List<ReportCasesViewModel> LawServices { get; set; } = new();
|
||||
}
|
||||
}
|
||||
|
@ -85,5 +85,20 @@ namespace LawFirmDatabase.Implements
|
||||
context.SaveChanges();
|
||||
return service.GetViewModel;
|
||||
}
|
||||
public List<ReportLawServicesViewModel> GetServicesWithRequest(ServiceSearchModel model)
|
||||
{
|
||||
if (model.SelectedServicesIds == null)
|
||||
{
|
||||
return new();
|
||||
}
|
||||
using var context = new LawFirmDBContext();
|
||||
return context.Services.Select(x => x.GetViewModel)
|
||||
.Where(w => model.SelectedServicesIds.Contains(w.Id))
|
||||
.Select(w => new ReportLawServicesViewModel()
|
||||
{
|
||||
ServiceName = w.Name
|
||||
})
|
||||
.ToList();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user