make possible to load services list
This commit is contained in:
parent
cf54488e71
commit
d644ef51a2
@ -36,4 +36,19 @@ public class Contract
|
|||||||
Services = services
|
Services = services
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static Contract CreateEntity(TempServiceContract tempServiceContract, IEnumerable<Service> services)
|
||||||
|
{
|
||||||
|
return new Contract
|
||||||
|
{
|
||||||
|
Id = tempServiceContract.Id,
|
||||||
|
CustomerID = tempServiceContract.CustomerID,
|
||||||
|
ExecutorID = tempServiceContract.ExecutorID,
|
||||||
|
Category = tempServiceContract.Category,
|
||||||
|
ConclusionDate = tempServiceContract.ConclusionDate,
|
||||||
|
Deadline = tempServiceContract.Deadline,
|
||||||
|
PaymentAmount = tempServiceContract.PaymentAmount,
|
||||||
|
Services = services
|
||||||
|
};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,24 @@
|
|||||||
|
using PIbd_23_Gutorov_I.A._IT_Company.Entities.Enums;
|
||||||
|
|
||||||
|
namespace PIbd_23_Gutorov_I.A._IT_Company.Entities;
|
||||||
|
|
||||||
|
public class TempServiceContract
|
||||||
|
{
|
||||||
|
public int Id { get; private set; }
|
||||||
|
|
||||||
|
public int CustomerID { get; private set; }
|
||||||
|
|
||||||
|
public int ExecutorID { get; private set; }
|
||||||
|
|
||||||
|
public ContractCategory Category { get; private set; }
|
||||||
|
|
||||||
|
public DateTime ConclusionDate { get; private set; }
|
||||||
|
|
||||||
|
public DateTime Deadline { get; private set; }
|
||||||
|
|
||||||
|
public int PaymentAmount { get; private set; }
|
||||||
|
|
||||||
|
public int ServiceId { get; private set; }
|
||||||
|
|
||||||
|
public string Description { get; private set; } = string.Empty;
|
||||||
|
}
|
@ -75,9 +75,12 @@ namespace PIbd_23_Gutorov_I.A._IT_Company.Forms
|
|||||||
|
|
||||||
foreach (DataGridViewRow row in dataGridViewServices.Rows)
|
foreach (DataGridViewRow row in dataGridViewServices.Rows)
|
||||||
if (row.Cells["ColumnServiceDescription"].Value != null)
|
if (row.Cells["ColumnServiceDescription"].Value != null)
|
||||||
list.Add(Service.CreateEntity(0, Convert.ToString(row.Cells["ColumnServiceDescription"].Value)!));
|
list.Add(Service.CreateEntity(Convert.ToInt32(row.Cells["ColumnServiceDescription"].Value),
|
||||||
|
Convert.ToString(row.Cells["ColumnServiceDescription"])!));
|
||||||
|
|
||||||
return list;
|
return list.GroupBy(x => x.Id)
|
||||||
|
.Select(x => x.First())
|
||||||
|
.ToList();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using Npgsql;
|
using Npgsql;
|
||||||
|
using PIbd_23_Gutorov_I.A._IT_Company.Entities;
|
||||||
|
|
||||||
namespace PIbd_23_Gutorov_I.A._IT_Company.Repositories.Implementations;
|
namespace PIbd_23_Gutorov_I.A._IT_Company.Repositories.Implementations;
|
||||||
|
|
||||||
@ -76,17 +77,25 @@ public class ContractRepository : IContractRepository
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public IEnumerable<Entities.Contract> ReadContracts(DateTime? dateFrom = null, DateTime? dateTo = null, int? customerId = null, int? executorId = null)
|
public IEnumerable<Contract> ReadContracts(DateTime? dateFrom = null, DateTime? dateTo = null, int? customerId = null, int? executorId = null)
|
||||||
{
|
{
|
||||||
_logger.LogInformation("Получение всех объектов");
|
_logger.LogInformation("Получение всех объектов");
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||||
var querySelect = @"SELECT * FROM Contracts";
|
var querySelect = @"
|
||||||
var contracts = connection.Query<Entities.Contract>(querySelect);
|
SELECT c.*, sc.ServiceId, s.Description
|
||||||
|
FROM Contracts c
|
||||||
|
INNER JOIN ServiceContract sc ON sc.ContractId = c.Id
|
||||||
|
INNER JOIN Services s ON sc.ServiceId = s.Id
|
||||||
|
";
|
||||||
|
var contracts = connection.Query<TempServiceContract>(querySelect);
|
||||||
_logger.LogDebug("Полученные объекты: {json}", JsonConvert.SerializeObject(contracts));
|
_logger.LogDebug("Полученные объекты: {json}", JsonConvert.SerializeObject(contracts));
|
||||||
return contracts;
|
return contracts
|
||||||
|
.GroupBy(x => x.Id, y => y, (key, value) =>
|
||||||
|
Contract.CreateEntity(value.First(), value.Select(z => Service.CreateEntity(z.ServiceId, z.Description))))
|
||||||
|
.ToList();
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user