Имитация сотрудника и отчеты
This commit is contained in:
parent
e78b2309d2
commit
608609bb45
@ -0,0 +1,131 @@
|
||||
using ZooContracts.BusinessLogicsContracts;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using ZooContracts.BusinessLogicsContracts;
|
||||
|
||||
namespace ZooBusinessLogic.BusinessLogics
|
||||
{
|
||||
/// <summary>
|
||||
/// Замена сотрудника
|
||||
/// </summary>
|
||||
public class EmployeeRoleImitationaLogic
|
||||
{
|
||||
private readonly IEmployeeLogic _employeeLogic;
|
||||
private readonly IReserveLogic _ReserveLogic;
|
||||
private readonly ICostLogic _CostLogic;
|
||||
private readonly IRouteLogic _RouteLogic;
|
||||
private readonly IRouteCostLogic _RouteCostLogic;
|
||||
|
||||
public EmployeeRoleImitationaLogic(IEmployeeLogic employeeLogic,
|
||||
IReserveLogic ReserveLogic, ICostLogic CostLogic,
|
||||
IRouteLogic RouteLogic, IRouteCostLogic RouteCostLogic)
|
||||
{
|
||||
_employeeLogic = employeeLogic;
|
||||
_ReserveLogic = ReserveLogic;
|
||||
_CostLogic = CostLogic;
|
||||
_RouteLogic = RouteLogic;
|
||||
_RouteCostLogic = RouteCostLogic;
|
||||
}
|
||||
private bool GenerateEmployeeData()
|
||||
{
|
||||
if (_employeeLogic.ReadList(null)?.Count != 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
using (StreamReader sr = new("employees.txt"))
|
||||
{
|
||||
string? currentString;
|
||||
while ((currentString = sr.ReadLine()) != null)
|
||||
{
|
||||
var employeeRecData = currentString.Split(',');
|
||||
_employeeLogic.Create(new()
|
||||
{
|
||||
EmployeeEmail = employeeRecData[0],
|
||||
EmployeePassword = employeeRecData[1],
|
||||
EmployeeName = employeeRecData[2],
|
||||
EmployeePhone = employeeRecData[3]
|
||||
});
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
private bool GenerateReserveData()
|
||||
{
|
||||
if (_ReserveLogic.ReadList(null)?.Count != 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
using (StreamReader sr = new("Reserves.txt"))
|
||||
{
|
||||
string? currentString;
|
||||
while ((currentString = sr.ReadLine()) != null)
|
||||
{
|
||||
var ReserveRecData = currentString.Split(',');
|
||||
_ReserveLogic.Create(new()
|
||||
{
|
||||
ReserveName = Convert.ToString(ReserveRecData[0]),
|
||||
ReservePrice = Convert.ToDouble(ReserveRecData[1])
|
||||
});
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
public bool GenerateCost()
|
||||
{
|
||||
if (_CostLogic.ReadList(null)?.Count != 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
using (StreamReader sr = new("Costs.txt"))
|
||||
{
|
||||
string? currentString;
|
||||
while ((currentString = sr.ReadLine()) != null)
|
||||
{
|
||||
var CostRecData = currentString.Split(',');
|
||||
_CostLogic.Create(new()
|
||||
{
|
||||
CostName = Convert.ToString(CostRecData[0]),
|
||||
Sum = Convert.ToDouble(CostRecData[1]),
|
||||
Count = Convert.ToInt32(CostRecData[2]),
|
||||
EmployeeId = Convert.ToInt32(CostRecData[3])
|
||||
});
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
public bool GenerateRouteCost()
|
||||
{
|
||||
var CostList = _CostLogic.ReadList(null);
|
||||
if (CostList == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (CostList.Count == 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
var RouteList = _RouteLogic.ReadList(null);
|
||||
if (RouteList == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (RouteList.Count == 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
Random rnd = new Random();
|
||||
for (int i = 0; i < 2; i++)
|
||||
{
|
||||
_RouteCostLogic.Create(new()
|
||||
{
|
||||
CostId = rnd.Next(0, CostList.Count),
|
||||
RouteId = rnd.Next(0, RouteList.Count)
|
||||
});
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,33 +1,42 @@
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.Identity.Client;
|
||||
using ZooContracts.BusinessLogicsContracts;
|
||||
using ZooContracts.StoragesContracts;
|
||||
using ZooContracts.ViewModels;
|
||||
using ZooDatabaseImplement.Models;
|
||||
using ZooDataModels.Models;
|
||||
using ZooContracts.BindingModels;
|
||||
using ZooContracts.BusinessLogicsContracts;
|
||||
|
||||
namespace ZooBusinessLogic.BusinessLogics
|
||||
namespace ZooContracts.BusinessLogics
|
||||
{
|
||||
public class ReportLogic : IReportLogic
|
||||
{
|
||||
private readonly IRouteStorage _RouteStorage;
|
||||
private readonly ILogger _logger;
|
||||
private readonly IRouteCostStorage _RouteCostStorage;
|
||||
|
||||
public ReportLogic(ILogger _logger, IRouteStorage RouteStorage)
|
||||
public ReportLogic(ILogger logger, IRouteStorage RouteStorage,
|
||||
IRouteCostStorage RouteCostStorage)
|
||||
{
|
||||
//_logger = logger;
|
||||
_logger = logger;
|
||||
_RouteStorage = RouteStorage;
|
||||
_RouteCostStorage = RouteCostStorage;
|
||||
}
|
||||
/// <summary>
|
||||
/// Получение списка кружков с указанием списка затрат по ним за определенное время
|
||||
/// получение заповедников в маршруте
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public List<ReportRouteReservesViewModel> GetReserveRoutes(ReportBindingModel model)
|
||||
{
|
||||
return _RouteStorage.GetReserveRoutes(new() { SelectedRoutesIds = model.SelectedRoutes });
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// получение затрат по маршруту
|
||||
/// </summary>
|
||||
public List<ReportCostsInRoutesViewModel> GetCosts(ReportBindingModel model)
|
||||
{
|
||||
return _RouteCostStorage.GetCostsInRoutes(new() { DateFrom = model.DateFrom, DateTo = model.DateTo });
|
||||
}
|
||||
public void SaveComponentsToWordFile(ReportBindingModel model)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
@ -43,4 +52,4 @@ namespace ZooBusinessLogic.BusinessLogics
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,12 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ZooBusinessLogic.BusinessLogics
|
||||
{
|
||||
internal class ReportReserveLogic
|
||||
{
|
||||
}
|
||||
}
|
@ -12,5 +12,7 @@ namespace ZooContracts.BindingModels
|
||||
public int Id { get; set; }
|
||||
public double Sum { get; set; }
|
||||
public string CostName { get; set; }
|
||||
public int Count { get; set; }
|
||||
public int EmployeeId { get; set; }
|
||||
}
|
||||
}
|
||||
|
@ -13,6 +13,5 @@ namespace ZooContracts.BindingModels
|
||||
public DateTime DateStart { get; set; } = DateTime.Now;
|
||||
public int ClientId { get; set; }
|
||||
public int ReserveId { get; set; }
|
||||
public double Remains { get; set; }
|
||||
}
|
||||
}
|
||||
|
@ -10,10 +10,16 @@ namespace ZooContracts.BusinessLogicsContracts
|
||||
public interface IReportLogic
|
||||
{
|
||||
/// <summary>
|
||||
/// Получение списка Маршрутов по заповедникам
|
||||
/// Получение списка маршрутов по заповедникам
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
List<ReportRouteReservesViewModel> GetReserveRoutes(ReportBindingModel model);
|
||||
List<ReportRouteRoutesViewModel> GetRouteRoutes(ReportBindingModel model);
|
||||
/// <summary>
|
||||
/// Получение списка затрат за определенный период
|
||||
/// </summary>
|
||||
/// <param name="model"></param>
|
||||
/// <returns></returns>
|
||||
List<ReportCostsInRoutesViewModel> GetCosts(ReportBindingModel model);
|
||||
/// <summary>
|
||||
/// Сохранение компонент в файл-Word
|
||||
/// </summary>
|
||||
@ -23,7 +29,7 @@ namespace ZooContracts.BusinessLogicsContracts
|
||||
/// Сохранение компонент с указаеним продуктов в файл-Excel
|
||||
/// </summary>
|
||||
/// <param name="model"></param>
|
||||
void SaveComponentToExcelFile(ReportBindingModel model);
|
||||
void SaveManufactureComponentToExcelFile(ReportBindingModel model);
|
||||
/// <summary>
|
||||
/// Сохранение заказов в файл-Pdf
|
||||
/// </summary>
|
||||
|
@ -9,5 +9,7 @@ namespace ZooContracts.SearchModel
|
||||
public class RouteCostSearchModel
|
||||
{
|
||||
public int? Id { get; set; }
|
||||
public DateTime? DateTo { get; set; }
|
||||
public DateTime? DateFrom { get; set; }
|
||||
}
|
||||
}
|
||||
|
@ -17,5 +17,6 @@ namespace ZooContracts.StoragesContracts
|
||||
RouteCostViewModel? Insert(RouteCostBindingModel model);
|
||||
RouteCostViewModel? Update(RouteCostBindingModel model);
|
||||
RouteCostViewModel? Delete(RouteCostBindingModel model);
|
||||
List<ReportCostsInRoutesViewModel> GetExpensesInCircles(RouteCostSearchModel model);
|
||||
}
|
||||
}
|
||||
|
@ -12,5 +12,7 @@ namespace ZooContracts.ViewModels
|
||||
public int Id { get; set; }
|
||||
public string CostName { get; set; }
|
||||
public double Sum { get; set; }
|
||||
public int Count { get; set; }
|
||||
public int EmployeeId { get; set; }
|
||||
}
|
||||
}
|
||||
|
@ -7,11 +7,17 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace ZooContracts.ViewModels
|
||||
{
|
||||
public class ReportCostViewModel
|
||||
public class ReportCostsInRoutesViewModel
|
||||
{
|
||||
[DisplayName("Название затраты")]
|
||||
public string CostName { get; set; } = string.Empty;
|
||||
[DisplayName("Сумма")]
|
||||
public double Sum { get; set; }
|
||||
[DisplayName("Номер маршрута")]
|
||||
public int CircleId { get; set; }
|
||||
[DisplayName("Имя сотрудника")]
|
||||
public string EmployeeName { get; set; }
|
||||
[DisplayName("Кол-во затрат")]
|
||||
public int Count { get; set; }
|
||||
}
|
||||
}
|
@ -8,7 +8,17 @@ namespace ZooContracts.ViewModels
|
||||
{
|
||||
public class ReportReserveRoutesViewModel
|
||||
{
|
||||
public int ReserveId { get; set; }
|
||||
public int RoutesCount { get; set; }
|
||||
/// <summary>
|
||||
/// Номер заповедника
|
||||
/// </summary>
|
||||
public int ReserveId { get; set; }
|
||||
/// <summary>
|
||||
/// Имя работника
|
||||
/// </summary>
|
||||
public string EmployeeName { get; set; } = string.Empty;
|
||||
/// <summary>
|
||||
/// Стоимость
|
||||
/// </summary>
|
||||
public double Sum { get; set; }
|
||||
}
|
||||
}
|
||||
|
@ -15,6 +15,6 @@ namespace ZooContracts.ViewModels
|
||||
/// <summary>
|
||||
/// Заповедник в Маршруте
|
||||
/// </summary>
|
||||
public List<ReportReserveRouteViewModel> RouteLessons { get; set; } = new();
|
||||
public List<ReportReserveRouteViewModel> Lessons { get; set; } = new();
|
||||
}
|
||||
}
|
||||
|
@ -1,23 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ZooContracts.ViewModels
|
||||
{
|
||||
public class ReportViewModel
|
||||
{
|
||||
[DisplayName("Название маршрута")]
|
||||
public int RouteNumber { get; set; }
|
||||
[DisplayName("Дата записи")]
|
||||
public DateTime Date { get; set; }
|
||||
[DisplayName("Сумма затрат")]
|
||||
public double Sum { get; set; }
|
||||
[DisplayName("Кол-во заповедников")]
|
||||
public int RouteCount { get; set; }
|
||||
[DisplayName("Название затраты")]
|
||||
public List<ReportCostViewModel> Cost { get; set; }
|
||||
}
|
||||
}
|
@ -16,5 +16,13 @@ namespace ZooDataModels.Models
|
||||
/// Название
|
||||
/// </summary>
|
||||
public string CostName { get; }
|
||||
/// <summary>
|
||||
/// количество
|
||||
/// </summary>
|
||||
public int Count { get; set; }
|
||||
/// <summary>
|
||||
/// Id сотрудника
|
||||
/// </summary>
|
||||
public int EmployeeId { get; set; }
|
||||
}
|
||||
}
|
||||
|
@ -43,6 +43,26 @@ namespace ZooDatabaseImplements.Implements
|
||||
return null;
|
||||
}
|
||||
|
||||
public List<ReportCostsInRoutesViewModel> GetCostsInRoutes(RouteCostSearchModel model)
|
||||
{
|
||||
if (model.DateFrom == null || model.DateTo == null)
|
||||
{
|
||||
return new();
|
||||
}
|
||||
using var context = new ZooDatabase();
|
||||
return context.RouteCosts.Include(x => x.Route)
|
||||
.Include(x => x.Cost)
|
||||
.ThenInclude(x => x.Employee)
|
||||
.Select(x => new ReportCostsInRoutesViewModel()
|
||||
{
|
||||
EmployeeName = x.Cost.Employee.EmployeeName,
|
||||
RouteId = x.Route.Id,
|
||||
CostName = x.Cost.CostName,
|
||||
Count = x.Cost.Count,
|
||||
Sum = x.Cost.Sum
|
||||
})
|
||||
.ToList();
|
||||
}
|
||||
public List<RouteCostViewModel> GetFilteredList(RouteCostSearchModel model)
|
||||
{
|
||||
using var context = new ZooDatabase();
|
||||
|
@ -25,22 +25,11 @@ namespace ZooDatabaseImplements.Implements
|
||||
public List<RouteViewModel> GetFilteredList(RouteSearchModel model)
|
||||
{
|
||||
using var context = new ZooDatabase();
|
||||
if (model.DateFrom.HasValue && model.DateTo.HasValue) // если не ищем по id, значит ищем по диапазону дат
|
||||
{
|
||||
return context.Routes
|
||||
.Where(x => model.DateFrom <= x.DateStart.Date && x.DateStart <= model.DateTo)
|
||||
.Include(x => x.Client)
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
if (model.ClientId.HasValue)
|
||||
{
|
||||
return context.Routes
|
||||
.Where(x => x.Client.Id == model.ClientId)
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
return new();
|
||||
return context.Routes
|
||||
.Where(x => x.Id == model.Id)
|
||||
.Include(x => x.Client)
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
public RouteViewModel? GetElement(RouteSearchModel model)
|
||||
{
|
||||
@ -92,7 +81,11 @@ namespace ZooDatabaseImplements.Implements
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Получение списка заповедников по выбранному маршруту
|
||||
/// </summary>
|
||||
/// <param name="model"></param>
|
||||
/// <returns></returns>
|
||||
public List<ReportRouteReservesViewModel> GetReserveRoutes(RouteSearchModel model)
|
||||
{
|
||||
if (model.SelectedRoutesIds == null)
|
||||
@ -101,26 +94,23 @@ namespace ZooDatabaseImplements.Implements
|
||||
}
|
||||
using var context = new ZooDatabase();
|
||||
return context.Routes
|
||||
.Where(c => model.SelectedRoutesIds.Contains(c.Id))
|
||||
.Select(c => new ReportRouteReservesViewModel()
|
||||
.Where(x => model.SelectedRoutesIds.Contains(x.Id))
|
||||
.Select(x => new ReportRouteReservesViewModel()
|
||||
{
|
||||
RouteReserves = GetRouteReserves(context, new() { Id = c.Id })
|
||||
})
|
||||
.ToList();
|
||||
}
|
||||
/// <summary>
|
||||
/// Получение списка заповедников по выбранному маршруту
|
||||
/// </summary>
|
||||
/// <param name="model"></param>
|
||||
/// <returns></returns>
|
||||
private static List<ReportReserveRoutesViewModel> GetRouteReserves(ZooDatabase context, RouteSearchModel model)
|
||||
{
|
||||
return context.Routes
|
||||
.Include(wir => wir.RouteReserves)
|
||||
.Where(wir => wir.Id == model.Id)
|
||||
.Select(wir => new ReportReserveRoutesViewModel()
|
||||
{
|
||||
ReserveId = wir.RouteReserves.Id
|
||||
RouteId = x.Id,
|
||||
Reserves = context.RouteReserves
|
||||
.Include(x => x.Reserve)
|
||||
.ThenInclude(x => x.Employee)
|
||||
.Where(x => x.RouteId == x.Id)
|
||||
.Select(x => new ReportReserveRoutesViewModel()
|
||||
{
|
||||
|
||||
ReserveId = x.Route.Id,
|
||||
EmployeeName = x.Reserve.Employee.EmployeeName,
|
||||
Sum = x.Reserve.ReservePrice
|
||||
|
||||
})
|
||||
.ToList()
|
||||
})
|
||||
.ToList();
|
||||
}
|
||||
|
@ -17,9 +17,15 @@ namespace ZooDatabaseImplements.Models
|
||||
public string CostName { get; private set; } = string.Empty;
|
||||
[Required]
|
||||
public double Sum { get; private set; }
|
||||
[Required]
|
||||
public int Count { get; private set; }
|
||||
public int EmployeeId { get; private set; }
|
||||
public int RouteId { get; private set; }
|
||||
[ForeignKey("CostId")]
|
||||
public virtual List<RouteCost> RouteCosts { get; set; } = new();
|
||||
public static Cost? Create(CostBindingModel model)
|
||||
[ForeignKey("CostId")]
|
||||
public virtual Employee Employee { get; set; } = new();
|
||||
public static Cost? Create(ZooDatabase context, CostBindingModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
@ -29,7 +35,9 @@ namespace ZooDatabaseImplements.Models
|
||||
{
|
||||
Id = model.Id,
|
||||
CostName = model.CostName,
|
||||
Sum = model.Sum
|
||||
Sum = model.Sum,
|
||||
Count = model.Count,
|
||||
Employee = context.Employees.First(x => x.Id == model.EmployeeId)
|
||||
};
|
||||
}
|
||||
public void Update(CostBindingModel model)
|
||||
|
@ -23,6 +23,8 @@ namespace ZooDatabaseImplements.Models
|
||||
[Required]
|
||||
public string EmployeeName { get; set; } = string.Empty;
|
||||
[ForeignKey("EmployeeId")]
|
||||
public virtual List<Cost> Costs { get; set; } = new();
|
||||
[ForeignKey("CostId")]
|
||||
public virtual List<Reserve> Reserves { get; set; } = new();
|
||||
public static Employee? Create(EmployeeBindingModel model)
|
||||
{
|
||||
@ -51,9 +53,13 @@ namespace ZooDatabaseImplements.Models
|
||||
EmployeePhone = model.EmployeePhone;
|
||||
}
|
||||
|
||||
public CostViewModel GetViewModel => new()
|
||||
public EmployeeViewModel GetViewModel => new()
|
||||
{
|
||||
Id = Id
|
||||
Id = Id,
|
||||
EmployeeName = EmployeeName,
|
||||
EmployeeEmail = EmployeeEmail,
|
||||
EmployeePassword = EmployeePassword,
|
||||
EmployeePhone = EmployeePhone
|
||||
};
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user