Лабораторная работа №4 Шаг 1/2
This commit is contained in:
parent
bb3bb40a8d
commit
1e3874d74c
@ -1,12 +1,18 @@
|
|||||||
using ProjectGasStation.Entities.Enums;
|
using ProjectGasStation.Entities.Enums;
|
||||||
|
using System.ComponentModel;
|
||||||
|
|
||||||
namespace ProjectGasStation.Entities;
|
namespace ProjectGasStation.Entities;
|
||||||
|
|
||||||
public class Contractor
|
public class Contractor
|
||||||
{
|
{
|
||||||
public int Id { get; private set; }
|
public int Id { get; private set; }
|
||||||
|
|
||||||
|
[DisplayName("Название")]
|
||||||
public string Name { get; private set; } = string.Empty;
|
public string Name { get; private set; } = string.Empty;
|
||||||
|
|
||||||
|
[DisplayName("Поставляемое топливо")]
|
||||||
public ContractorFuelType Types { get; private set; }
|
public ContractorFuelType Types { get; private set; }
|
||||||
|
|
||||||
public static Contractor CreateContractor(int id, string name, ContractorFuelType types)
|
public static Contractor CreateContractor(int id, string name, ContractorFuelType types)
|
||||||
{
|
{
|
||||||
return new Contractor { Id = id, Name = name, Types = types };
|
return new Contractor { Id = id, Name = name, Types = types };
|
||||||
|
@ -1,18 +1,39 @@
|
|||||||
namespace ProjectGasStation.Entities;
|
using ProjectGasStation.Entities.Enums;
|
||||||
|
using System.ComponentModel;
|
||||||
|
|
||||||
|
namespace ProjectGasStation.Entities;
|
||||||
|
|
||||||
public class ContractorFuel
|
public class ContractorFuel
|
||||||
{
|
{
|
||||||
public int Id { get; private set; }
|
public int Id { get; private set; }
|
||||||
|
|
||||||
|
[Browsable(false)]
|
||||||
public int ContractorId { get; private set; }
|
public int ContractorId { get; private set; }
|
||||||
|
|
||||||
|
[DisplayName("Поставщик")]
|
||||||
|
public string ContractorName { get; private set; } = string.Empty;
|
||||||
|
|
||||||
|
[DisplayName("Дата поставки")]
|
||||||
public DateTime Date { get; private set; }
|
public DateTime Date { get; private set; }
|
||||||
|
|
||||||
|
[DisplayName("Топливо")]
|
||||||
|
public string Fuel => ContractorFuelFuel != null ?
|
||||||
|
string.Join(", ", ContractorFuelFuel.Select(x => $"{(FuelType)x.FuelName} {x.Quantity}")) :
|
||||||
|
string.Empty;
|
||||||
|
|
||||||
|
[Browsable(false)]
|
||||||
public IEnumerable<ContractorFuelFuel> ContractorFuelFuel { get; private set; } = [];
|
public IEnumerable<ContractorFuelFuel> ContractorFuelFuel { get; private set; } = [];
|
||||||
|
|
||||||
public static ContractorFuel CreateContractorFuel(int id, int contractorId, DateTime date, IEnumerable<ContractorFuelFuel> contractorFuelFuel)
|
public static ContractorFuel CreateContractorFuel(int id, int contractorId, DateTime date, IEnumerable<ContractorFuelFuel> contractorFuelFuel)
|
||||||
{
|
{
|
||||||
return new ContractorFuel { Id = id, ContractorId = contractorId, Date = date, ContractorFuelFuel = contractorFuelFuel};
|
return new ContractorFuel { Id = id, ContractorId = contractorId, Date = date, ContractorFuelFuel = contractorFuelFuel};
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ContractorFuel CreateContractorFuel(TempContractorFuelFuel tempContractorFuelFuel, IEnumerable<ContractorFuelFuel> contractorFuelFuel)
|
public void SetContractorFuelFuel(IEnumerable<ContractorFuelFuel> contractorFuelFuel)
|
||||||
{
|
{
|
||||||
return new ContractorFuel { Id = tempContractorFuelFuel.Id, ContractorId = tempContractorFuelFuel.ContractorId, Date = tempContractorFuelFuel.Date, ContractorFuelFuel = contractorFuelFuel };
|
if (contractorFuelFuel != null && contractorFuelFuel.Any())
|
||||||
|
{
|
||||||
|
ContractorFuelFuel = contractorFuelFuel;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -3,8 +3,13 @@
|
|||||||
public class ContractorFuelFuel
|
public class ContractorFuelFuel
|
||||||
{
|
{
|
||||||
public int Id { get; private set; }
|
public int Id { get; private set; }
|
||||||
|
|
||||||
public int FuelId { get; private set; }
|
public int FuelId { get; private set; }
|
||||||
|
|
||||||
|
public int FuelName { get; private set; }
|
||||||
|
|
||||||
public int Quantity { get; private set; }
|
public int Quantity { get; private set; }
|
||||||
|
|
||||||
public static ContractorFuelFuel CreateContractorFuelFuel(int id, int fuelId, int quantity)
|
public static ContractorFuelFuel CreateContractorFuelFuel(int id, int fuelId, int quantity)
|
||||||
{
|
{
|
||||||
return new ContractorFuelFuel { Id = id, FuelId = fuelId, Quantity = quantity };
|
return new ContractorFuelFuel { Id = id, FuelId = fuelId, Quantity = quantity };
|
||||||
|
@ -1,12 +1,18 @@
|
|||||||
using ProjectGasStation.Entities.Enums;
|
using ProjectGasStation.Entities.Enums;
|
||||||
|
using System.ComponentModel;
|
||||||
|
|
||||||
namespace ProjectGasStation.Entities;
|
namespace ProjectGasStation.Entities;
|
||||||
|
|
||||||
public class Fuel
|
public class Fuel
|
||||||
{
|
{
|
||||||
public int Id { get; private set; }
|
public int Id { get; private set; }
|
||||||
|
|
||||||
|
[DisplayName("Тип топлива")]
|
||||||
public FuelType Type { get; private set; }
|
public FuelType Type { get; private set; }
|
||||||
|
|
||||||
|
[DisplayName("Цена")]
|
||||||
public double Price { get; private set; }
|
public double Price { get; private set; }
|
||||||
|
|
||||||
public static Fuel CreateFuel(int id, FuelType type, double price)
|
public static Fuel CreateFuel(int id, FuelType type, double price)
|
||||||
{
|
{
|
||||||
return new Fuel { Id = id, Type = type, Price = price };
|
return new Fuel { Id = id, Type = type, Price = price };
|
||||||
|
@ -3,8 +3,13 @@
|
|||||||
public class FuelFuelSale
|
public class FuelFuelSale
|
||||||
{
|
{
|
||||||
public int Id { get; private set; }
|
public int Id { get; private set; }
|
||||||
|
|
||||||
public int FuelId { get; private set; }
|
public int FuelId { get; private set; }
|
||||||
|
|
||||||
|
public int FuelName { get; private set; }
|
||||||
|
|
||||||
public int Quantity { get; private set; }
|
public int Quantity { get; private set; }
|
||||||
|
|
||||||
public static FuelFuelSale CreateFuelFuelSale(int id, int fuelId, int quantity)
|
public static FuelFuelSale CreateFuelFuelSale(int id, int fuelId, int quantity)
|
||||||
{
|
{
|
||||||
return new FuelFuelSale { Id = id, FuelId = fuelId, Quantity = quantity};
|
return new FuelFuelSale { Id = id, FuelId = fuelId, Quantity = quantity};
|
||||||
|
@ -1,11 +1,36 @@
|
|||||||
namespace ProjectGasStation.Entities;
|
using ProjectGasStation.Entities.Enums;
|
||||||
|
using System.ComponentModel;
|
||||||
|
|
||||||
|
namespace ProjectGasStation.Entities;
|
||||||
|
|
||||||
public class FuelSale
|
public class FuelSale
|
||||||
{
|
{
|
||||||
public int Id { get; private set; }
|
public int Id { get; private set; }
|
||||||
|
|
||||||
|
[Browsable(false)]
|
||||||
public int SalespersonId { get; private set; }
|
public int SalespersonId { get; private set; }
|
||||||
|
|
||||||
|
[Browsable(false)]
|
||||||
public int ShiftId { get; private set; }
|
public int ShiftId { get; private set; }
|
||||||
|
|
||||||
|
[DisplayName("Продавец")]
|
||||||
|
public string SalespersonName { get; private set; } = string.Empty;
|
||||||
|
|
||||||
|
[Browsable(false)]
|
||||||
|
public int TypeShift { get; private set; }
|
||||||
|
|
||||||
|
[DisplayName("Смена")]
|
||||||
|
public string ShiftName => $"{SaleDate.Date.ToString("dd.MM.yyyy")} {(ShiftType)TypeShift}";
|
||||||
|
|
||||||
|
[Browsable(false)]
|
||||||
public DateTime SaleDate { get; private set; }
|
public DateTime SaleDate { get; private set; }
|
||||||
|
|
||||||
|
[DisplayName("Топливо")]
|
||||||
|
public string Fuel => FuelFuelSale != null ?
|
||||||
|
string.Join(", ", FuelFuelSale.Select(x => $"{(FuelType)x.FuelName} {x.Quantity}")) :
|
||||||
|
string.Empty;
|
||||||
|
|
||||||
|
[Browsable(false)]
|
||||||
public IEnumerable<FuelFuelSale> FuelFuelSale { get; private set; } = [];
|
public IEnumerable<FuelFuelSale> FuelFuelSale { get; private set; } = [];
|
||||||
|
|
||||||
public static FuelSale CreateFuelSale(int id, int salesPersonId, int shiftId, DateTime saleDate, IEnumerable<FuelFuelSale> fuelFuelSale)
|
public static FuelSale CreateFuelSale(int id, int salesPersonId, int shiftId, DateTime saleDate, IEnumerable<FuelFuelSale> fuelFuelSale)
|
||||||
@ -20,15 +45,11 @@ public class FuelSale
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
public static FuelSale CreateFuelSale(TempFuelFuelSale tempFuelFuelSale, IEnumerable<FuelFuelSale> fuelFuelSale)
|
public void SetFuelFuelSale(IEnumerable<FuelFuelSale> fuelFuelSale)
|
||||||
{
|
{
|
||||||
return new FuelSale
|
if(fuelFuelSale != null && fuelFuelSale.Any())
|
||||||
{
|
{
|
||||||
Id = tempFuelFuelSale.Id,
|
FuelFuelSale = fuelFuelSale;
|
||||||
SalespersonId = tempFuelFuelSale.SalespersonId,
|
}
|
||||||
ShiftId = tempFuelFuelSale.ShiftId,
|
|
||||||
SaleDate = tempFuelFuelSale.SaleDate,
|
|
||||||
FuelFuelSale = fuelFuelSale
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,10 +1,17 @@
|
|||||||
namespace ProjectGasStation.Entities;
|
using System.ComponentModel;
|
||||||
|
|
||||||
|
namespace ProjectGasStation.Entities;
|
||||||
|
|
||||||
public class Salesperson
|
public class Salesperson
|
||||||
{
|
{
|
||||||
public int Id { get; private set; }
|
public int Id { get; private set; }
|
||||||
|
|
||||||
|
[DisplayName("Имя")]
|
||||||
public string FirstName { get; private set; } = string.Empty;
|
public string FirstName { get; private set; } = string.Empty;
|
||||||
|
|
||||||
|
[DisplayName("Фамилия")]
|
||||||
public string LastName { get; private set; } = string.Empty;
|
public string LastName { get; private set; } = string.Empty;
|
||||||
|
|
||||||
public static Salesperson CreateSalesperson(int id, string firstName, string lastName)
|
public static Salesperson CreateSalesperson(int id, string firstName, string lastName)
|
||||||
{
|
{
|
||||||
return new Salesperson { Id = id, FirstName = firstName, LastName = lastName };
|
return new Salesperson { Id = id, FirstName = firstName, LastName = lastName };
|
||||||
|
@ -1,15 +1,26 @@
|
|||||||
using ProjectGasStation.Entities.Enums;
|
using ProjectGasStation.Entities.Enums;
|
||||||
|
using System.ComponentModel;
|
||||||
|
|
||||||
namespace ProjectGasStation.Entities;
|
namespace ProjectGasStation.Entities;
|
||||||
|
|
||||||
public class Shift
|
public class Shift
|
||||||
{
|
{
|
||||||
public int Id { get; private set; }
|
public int Id { get; private set; }
|
||||||
|
|
||||||
|
[DisplayName("Время начала")]
|
||||||
public TimeSpan StartTime { get; private set; }
|
public TimeSpan StartTime { get; private set; }
|
||||||
|
|
||||||
|
[DisplayName("Время конца")]
|
||||||
public TimeSpan EndTime { get; private set; }
|
public TimeSpan EndTime { get; private set; }
|
||||||
|
|
||||||
|
[DisplayName("Дата")]
|
||||||
public DateTime Date { get; private set; }
|
public DateTime Date { get; private set; }
|
||||||
|
|
||||||
|
[DisplayName("Тип смены")]
|
||||||
public ShiftType Type { get; private set; }
|
public ShiftType Type { get; private set; }
|
||||||
|
|
||||||
public string DisplayName => $"{Date:yyyy-MM-dd} ({Type})";
|
public string DisplayName => $"{Date:yyyy-MM-dd} ({Type})";
|
||||||
|
|
||||||
public static Shift CreateShift(int id, TimeSpan startTime, TimeSpan endTime, DateTime date, ShiftType type)
|
public static Shift CreateShift(int id, TimeSpan startTime, TimeSpan endTime, DateTime date, ShiftType type)
|
||||||
{
|
{
|
||||||
return new Shift { Id = id, EndTime = endTime, StartTime = startTime, Date = date, Type = type };
|
return new Shift { Id = id, EndTime = endTime, StartTime = startTime, Date = date, Type = type };
|
||||||
|
@ -1,16 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace ProjectGasStation.Entities;
|
|
||||||
|
|
||||||
public class TempContractorFuelFuel
|
|
||||||
{
|
|
||||||
public int Id { get; private set; }
|
|
||||||
public int ContractorId { get; private set; }
|
|
||||||
public DateTime Date { get; private set; }
|
|
||||||
public int FuelId { get; private set; }
|
|
||||||
public int Quantity { get; private set; }
|
|
||||||
}
|
|
@ -1,17 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace ProjectGasStation.Entities;
|
|
||||||
|
|
||||||
public class TempFuelFuelSale
|
|
||||||
{
|
|
||||||
public int Id { get; private set; }
|
|
||||||
public int SalespersonId { get; private set; }
|
|
||||||
public int ShiftId { get; private set; }
|
|
||||||
public DateTime SaleDate { get; private set; }
|
|
||||||
public int FuelId { get; private set; }
|
|
||||||
public int Quantity { get; private set; }
|
|
||||||
}
|
|
@ -63,7 +63,11 @@ public partial class FormContractorFuels : Form
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void LoadList() => dataGridViewData.DataSource = _contractorFuelRepository.ReadContractorFuels();
|
private void LoadList()
|
||||||
|
{
|
||||||
|
dataGridViewData.DataSource = _contractorFuelRepository.ReadContractorFuels();
|
||||||
|
dataGridViewData.Columns["Id"].Visible = false;
|
||||||
|
}
|
||||||
|
|
||||||
private bool TryGetIdentifierFromSelectedRow(out int id)
|
private bool TryGetIdentifierFromSelectedRow(out int id)
|
||||||
{
|
{
|
||||||
|
@ -82,7 +82,11 @@ public partial class FormContractors : Form
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void LoadList() => dataGridViewData.DataSource = _contractorRepository.ReadContractors();
|
private void LoadList()
|
||||||
|
{
|
||||||
|
dataGridViewData.DataSource = _contractorRepository.ReadContractors();
|
||||||
|
dataGridViewData.Columns["Id"].Visible = false;
|
||||||
|
}
|
||||||
|
|
||||||
private bool TryGetIdentifierFromSelectedRow(out int id)
|
private bool TryGetIdentifierFromSelectedRow(out int id)
|
||||||
{
|
{
|
||||||
|
@ -62,7 +62,11 @@ public partial class FormFuelSales : Form
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void LoadList() => dataGridViewData.DataSource = _fuelSaleRepository.ReadFuelSales();
|
private void LoadList()
|
||||||
|
{
|
||||||
|
dataGridViewData.DataSource = _fuelSaleRepository.ReadFuelSales();
|
||||||
|
dataGridViewData.Columns["Id"].Visible = false;
|
||||||
|
}
|
||||||
|
|
||||||
private bool TryGetIdentifierFromSelectedRow(out int id)
|
private bool TryGetIdentifierFromSelectedRow(out int id)
|
||||||
{
|
{
|
||||||
|
@ -82,7 +82,11 @@ public partial class FormFuels : Form
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void LoadList() => dataGridViewData.DataSource = _fuelRepository.ReadFuels();
|
private void LoadList()
|
||||||
|
{
|
||||||
|
dataGridViewData.DataSource = _fuelRepository.ReadFuels();
|
||||||
|
dataGridViewData.Columns["Id"].Visible = false;
|
||||||
|
}
|
||||||
|
|
||||||
private bool TryGetIdentifierFromSelectedRow(out int id)
|
private bool TryGetIdentifierFromSelectedRow(out int id)
|
||||||
{
|
{
|
||||||
|
@ -82,7 +82,11 @@ public partial class FormSalespersons : Form
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void LoadList() => dataGridViewData.DataSource = _salespersonRepository.ReadSalespersons();
|
private void LoadList()
|
||||||
|
{
|
||||||
|
dataGridViewData.DataSource = _salespersonRepository.ReadSalespersons();
|
||||||
|
dataGridViewData.Columns["Id"].Visible = false;
|
||||||
|
}
|
||||||
|
|
||||||
private bool TryGetIdentifierFromSelectedRow(out int id)
|
private bool TryGetIdentifierFromSelectedRow(out int id)
|
||||||
{
|
{
|
||||||
|
@ -82,7 +82,12 @@ public partial class FormShifts : Form
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void LoadList() => dataGridViewData.DataSource = _shiftRepository.ReadShifts();
|
private void LoadList()
|
||||||
|
{
|
||||||
|
dataGridViewData.DataSource = _shiftRepository.ReadShifts();
|
||||||
|
dataGridViewData.Columns["Id"].Visible = false;
|
||||||
|
dataGridViewData.Columns["DisplayName"].Visible = false;
|
||||||
|
}
|
||||||
|
|
||||||
private bool TryGetIdentifierFromSelectedRow(out int id)
|
private bool TryGetIdentifierFromSelectedRow(out int id)
|
||||||
{
|
{
|
||||||
|
@ -1,7 +1,9 @@
|
|||||||
using Dapper;
|
using Dapper;
|
||||||
|
using DocumentFormat.OpenXml.Spreadsheet;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using Npgsql;
|
using Npgsql;
|
||||||
|
using PdfSharp.Pdf;
|
||||||
using ProjectGasStation.Entities;
|
using ProjectGasStation.Entities;
|
||||||
using System.Transactions;
|
using System.Transactions;
|
||||||
|
|
||||||
@ -91,12 +93,39 @@ public class ContractorFuelRepository : IContractorFuelRepository
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||||
var querySelect = @"SELECT cf.*, cff.FuelId, cff.Quantity FROM ContractorFuel cf
|
var querySelect = @"SELECT
|
||||||
INNER JOIN ContractorFuelFuel cff on cff.ContractorFuelId = cf.Id";
|
cf.*,
|
||||||
var contractorFuels = connection.Query<TempContractorFuelFuel>(querySelect);
|
c.Name as ContractorName,
|
||||||
|
cff.FuelId,
|
||||||
|
cff.Quantity,
|
||||||
|
f.Type as FuelName
|
||||||
|
FROM ContractorFuel cf
|
||||||
|
LEFT JOIN Contractor c on c.Id = cf.ContractorId
|
||||||
|
INNER JOIN ContractorFuelFuel cff on cff.ContractorFuelId = cf.Id
|
||||||
|
LEFT JOIN Fuel f on f.Id = cff.FuelId";
|
||||||
|
var contractorsDict = new Dictionary<int, List<ContractorFuelFuel>>();
|
||||||
|
|
||||||
|
var contractorFuels = connection.Query<ContractorFuel, ContractorFuelFuel, ContractorFuel>(querySelect,
|
||||||
|
(contractor, contractorFuel) =>
|
||||||
|
{
|
||||||
|
if (!contractorsDict.TryGetValue(contractor.Id, out var ccf))
|
||||||
|
{
|
||||||
|
ccf = [];
|
||||||
|
contractorsDict.Add(contractor.Id, ccf);
|
||||||
|
}
|
||||||
|
|
||||||
|
ccf.Add(contractorFuel);
|
||||||
|
return contractor;
|
||||||
|
}, splitOn: "FuelId");
|
||||||
_logger.LogDebug("Полученные объекты: {json}",
|
_logger.LogDebug("Полученные объекты: {json}",
|
||||||
JsonConvert.SerializeObject(contractorFuels));
|
JsonConvert.SerializeObject(contractorFuels));
|
||||||
return contractorFuels.GroupBy(x => x.Id, y => y, (key, value) => ContractorFuel.CreateContractorFuel(value.First(), value.Select(z => ContractorFuelFuel.CreateContractorFuelFuel(0, z.FuelId, z.Quantity)))).ToList();
|
|
||||||
|
return contractorsDict.Select(x =>
|
||||||
|
{
|
||||||
|
var cf = contractorFuels.First(y => y.Id == x.Key);
|
||||||
|
cf.SetContractorFuelFuel(x.Value);
|
||||||
|
return cf;
|
||||||
|
}).ToArray();
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
|
@ -61,12 +61,41 @@ public class FuelSaleRepository : IFuelSaleRepository
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||||
var querySelect = @"SELECT fs.*, ffs.FuelId, ffs.Quantity FROM FuelSale fs
|
var querySelect = @"SELECT
|
||||||
INNER JOIN FuelFuelSale ffs on ffs.FuelSaleId = fs.Id";
|
fs.*,
|
||||||
var fuelSales = connection.Query<TempFuelFuelSale>(querySelect);
|
CONCAT(s.LastName, ' ', s.FirstName) as SalespersonName,
|
||||||
|
sh.Type as TypeShift,
|
||||||
|
ffs.FuelId,
|
||||||
|
ffs.Quantity,
|
||||||
|
f.Type as FuelName
|
||||||
|
FROM FuelSale fs
|
||||||
|
LEFT JOIN Salesperson s on s.Id = fs.SalespersonId
|
||||||
|
LEFT JOIN Shift sh on sh.id = fs.ShiftId
|
||||||
|
INNER JOIN FuelFuelSale ffs on ffs.FuelSaleId = fs.Id
|
||||||
|
LEFT JOIN Fuel f on f.id = ffs.FuelId";
|
||||||
|
var salesDict = new Dictionary<int, List<FuelFuelSale>>();
|
||||||
|
|
||||||
|
var fuelSales = connection.Query<FuelSale, FuelFuelSale, FuelSale>(querySelect,
|
||||||
|
(sale, fuelSale) =>
|
||||||
|
{
|
||||||
|
if (!salesDict.TryGetValue(sale.Id, out var fss))
|
||||||
|
{
|
||||||
|
fss = [];
|
||||||
|
salesDict.Add(sale.Id, fss);
|
||||||
|
}
|
||||||
|
|
||||||
|
fss.Add(fuelSale);
|
||||||
|
return sale;
|
||||||
|
}, splitOn: "FuelId");
|
||||||
_logger.LogDebug("Полученные объекты: {json}",
|
_logger.LogDebug("Полученные объекты: {json}",
|
||||||
JsonConvert.SerializeObject(fuelSales));
|
JsonConvert.SerializeObject(fuelSales));
|
||||||
return fuelSales.GroupBy(x => x.Id, y => y, (key, value) => FuelSale.CreateFuelSale(value.First(), value.Select(z => FuelFuelSale.CreateFuelFuelSale(0, z.FuelId, z.Quantity)))).ToList();
|
|
||||||
|
return salesDict.Select(x =>
|
||||||
|
{
|
||||||
|
var fs = fuelSales.First(y => y.Id == x.Key);
|
||||||
|
fs.SetFuelFuelSale(x.Value);
|
||||||
|
return fs;
|
||||||
|
}).ToArray();
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user