Улучшения 1
This commit is contained in:
parent
602d6e59fd
commit
e029ce6f6b
@ -1,4 +1,5 @@
|
||||
using RealEstateTransactions.Entities.Enums;
|
||||
using System.ComponentModel;
|
||||
|
||||
namespace RealEstateTransactions.Entities
|
||||
{
|
||||
@ -6,16 +7,22 @@ namespace RealEstateTransactions.Entities
|
||||
{
|
||||
public int Id { get; private set; }
|
||||
|
||||
[DisplayName("Агенство")]
|
||||
public AgencyType Agency_ID { get; private set; }
|
||||
|
||||
[DisplayName("Комнаты")]
|
||||
public FormFactorType Form_factor_ID { get; private set; }
|
||||
|
||||
[DisplayName("Площадь")]
|
||||
public float Area { get; private set; }
|
||||
|
||||
[DisplayName("Цена за кв.м.")]
|
||||
public float Price_per_SM { get; private set; }
|
||||
|
||||
[DisplayName("Начальная стоимость")]
|
||||
public float Base_price { get; private set; }
|
||||
|
||||
[DisplayName("Стоимость от агенства")]
|
||||
public float Desired_price { get; private set; }
|
||||
|
||||
public static Apartment CreateApartment(int id, AgencyType agencyId, FormFactorType formFactorId, float area,
|
||||
|
@ -1,13 +1,18 @@
|
||||
namespace RealEstateTransactions.Entities
|
||||
using System.ComponentModel;
|
||||
|
||||
namespace RealEstateTransactions.Entities
|
||||
{
|
||||
public class Buyer
|
||||
{
|
||||
public int Id { get; private set; }
|
||||
|
||||
[DisplayName("ФИО")]
|
||||
public string Full_name { get; private set; } = string.Empty;
|
||||
|
||||
[DisplayName("Серия паспорта")]
|
||||
public int Passport_series { get; private set; }
|
||||
|
||||
[DisplayName("Номер паспорта")]
|
||||
public int Passport_number { get; private set; }
|
||||
|
||||
public static Buyer CreateBuyer(int id, string fullName, int passportSeries, int passportNumber)
|
||||
|
@ -1,17 +1,31 @@
|
||||
namespace RealEstateTransactions.Entities
|
||||
using System.ComponentModel;
|
||||
|
||||
namespace RealEstateTransactions.Entities
|
||||
{
|
||||
public class Deal
|
||||
{
|
||||
public int Id { get; private set; }
|
||||
|
||||
[DisplayName("ID квартиры")]
|
||||
public int Apartment_ID { get; private set; }
|
||||
|
||||
[Browsable(false)]
|
||||
public int Buyer_ID { get; private set; }
|
||||
|
||||
[DisplayName("ФИО покупателя")]
|
||||
public string BuyerName { get; private set; } = string.Empty;
|
||||
|
||||
[DisplayName("Цена сделки")]
|
||||
public float Deal_price { get; private set; }
|
||||
|
||||
[DisplayName("Дата сделки")]
|
||||
public DateTime Deal_date { get; private set; }
|
||||
|
||||
[DisplayName("Услуги")]
|
||||
public string Services => DealServices != null ?
|
||||
string.Join(", ", DealServices.Select(x => $"{x.DealName} {x.Execution_time}")) : string.Empty;
|
||||
|
||||
[Browsable(false)]
|
||||
public IEnumerable<ServicesDeal> DealServices { get; private set; } = [];
|
||||
|
||||
public static Deal CreateDeal(int id, int apartmentId, int buyerId, float dealPrice,
|
||||
@ -27,5 +41,10 @@
|
||||
DealServices = dealServices
|
||||
};
|
||||
}
|
||||
|
||||
public void SetServicesDeal(IEnumerable<ServicesDeal> servicesDeal)
|
||||
{
|
||||
if (servicesDeal != null && servicesDeal.Any()) DealServices = servicesDeal;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,13 +1,18 @@
|
||||
namespace RealEstateTransactions.Entities
|
||||
using System.ComponentModel;
|
||||
|
||||
namespace RealEstateTransactions.Entities
|
||||
{
|
||||
public class PreSalesServices
|
||||
{
|
||||
public int Id { get; private set; }
|
||||
|
||||
[DisplayName("ID квартиры")]
|
||||
public int Apartment_ID { get; private set; }
|
||||
|
||||
[DisplayName("Название")]
|
||||
public string Name { get; private set; } = string.Empty;
|
||||
|
||||
[DisplayName("Стоимость")]
|
||||
public float Cost { get; private set; }
|
||||
|
||||
public static PreSalesServices CreatePreSalesServices(int id, int apartmentId, string name, float cost)
|
||||
|
@ -1,11 +1,15 @@
|
||||
namespace RealEstateTransactions.Entities
|
||||
using System.ComponentModel;
|
||||
|
||||
namespace RealEstateTransactions.Entities
|
||||
{
|
||||
public class Services
|
||||
{
|
||||
public int Id { get; private set; }
|
||||
|
||||
[DisplayName("Название")]
|
||||
public string Name { get; private set; } = string.Empty;
|
||||
|
||||
[DisplayName("Стоимость")]
|
||||
public float Price { get; private set; }
|
||||
|
||||
public static Services CreateService(int id, string name, float price)
|
||||
|
@ -1,4 +1,6 @@
|
||||
namespace RealEstateTransactions.Entities
|
||||
using System.ComponentModel;
|
||||
|
||||
namespace RealEstateTransactions.Entities
|
||||
{
|
||||
public class ServicesDeal
|
||||
{
|
||||
@ -6,6 +8,9 @@
|
||||
|
||||
public int Deal_ID { get; private set; }
|
||||
|
||||
public string DealName { get; private set; } = string.Empty;
|
||||
|
||||
[DisplayName("Время выполнения")]
|
||||
public double Execution_time { get; private set; }
|
||||
|
||||
public static ServicesDeal CreateServicesDeal(int servicesId, int dealId, double executionTime)
|
||||
|
@ -76,7 +76,11 @@ namespace RealEstateTransactions.Forms
|
||||
}
|
||||
}
|
||||
|
||||
private void LoadList() => dataGridView.DataSource = _repository.ReadApartments();
|
||||
private void LoadList()
|
||||
{
|
||||
dataGridView.DataSource = _repository.ReadApartments();
|
||||
dataGridView.Columns["Id"].Visible = false;
|
||||
}
|
||||
|
||||
private bool TryGetIdentifierFormSelectedRow(out int id)
|
||||
{
|
||||
|
@ -76,7 +76,11 @@ namespace RealEstateTransactions.Forms
|
||||
}
|
||||
}
|
||||
|
||||
private void LoadList() => dataGridView.DataSource = _repository.ReadBuyers();
|
||||
private void LoadList()
|
||||
{
|
||||
dataGridView.DataSource = _repository.ReadBuyers();
|
||||
dataGridView.Columns["Id"].Visible = false;
|
||||
}
|
||||
|
||||
private bool TryGetIdentifierFormSelectedRow(out int id)
|
||||
{
|
||||
|
@ -18,7 +18,7 @@ namespace RealEstateTransactions.Forms
|
||||
comboBoxApartmentId.ValueMember = "Id";
|
||||
|
||||
comboBoxFullName.DataSource = buyerRepository.ReadBuyers();
|
||||
comboBoxFullName.DisplayMember = "FullName";
|
||||
comboBoxFullName.DisplayMember = "Full_name";
|
||||
comboBoxFullName.ValueMember = "Id";
|
||||
|
||||
ColumnService.DataSource = servicesRepository.ReadServices();
|
||||
|
@ -60,7 +60,12 @@ namespace RealEstateTransactions.Entities
|
||||
}
|
||||
}
|
||||
|
||||
private void LoadList() => dataGridView.DataSource = _repository.ReadDeals();
|
||||
private void LoadList()
|
||||
{
|
||||
dataGridView.DataSource = _repository.ReadDeals();
|
||||
dataGridView.Columns["Id"].Visible = false;
|
||||
dataGridView.Columns["Deal_date"].DefaultCellStyle.Format = "dd MMMM yyyy hh:mm";
|
||||
}
|
||||
|
||||
private bool TryGetIdentifierFormSelectedRow(out int id)
|
||||
{
|
||||
|
@ -59,7 +59,11 @@ namespace RealEstateTransactions.Forms
|
||||
}
|
||||
}
|
||||
|
||||
private void LoadList() => dataGridView.DataSource = _repository.ReadPreSalesServices();
|
||||
private void LoadList()
|
||||
{
|
||||
dataGridView.DataSource = _repository.ReadPreSalesServices();
|
||||
dataGridView.Columns["Id"].Visible = false;
|
||||
}
|
||||
|
||||
private bool TryGetIdentifierFormSelectedRow(out int id)
|
||||
{
|
||||
|
@ -77,7 +77,11 @@ namespace RealEstateTransactions.Entities
|
||||
}
|
||||
}
|
||||
|
||||
private void LoadList() => dataGridView.DataSource = _repository.ReadServices();
|
||||
private void LoadList()
|
||||
{
|
||||
dataGridView.DataSource = _repository.ReadServices();
|
||||
dataGridView.Columns["Id"].Visible = false;
|
||||
}
|
||||
|
||||
private bool TryGetIdentifierFormSelectedRow(out int id)
|
||||
{
|
||||
|
@ -28,14 +28,14 @@ namespace RealEstateTransactions.Repositories.Implementations
|
||||
connection.Open();
|
||||
using var transaction = connection.BeginTransaction();
|
||||
var insertQuery = @"
|
||||
INSERT INTO Deal (Apartment_ID, Buyer_ID, Deal_price, Deal_date)
|
||||
VALUES (@Apartment_ID, @Buyer_ID, @Deal_price, @Deal_date);
|
||||
SELECT MAX(Id) FROM Deal";
|
||||
INSERT INTO Deal (Apartment_ID, Buyer_ID, Deal_price, Deal_date)
|
||||
VALUES (@Apartment_ID, @Buyer_ID, @Deal_price, @Deal_date);
|
||||
SELECT MAX(Id) FROM Deal";
|
||||
var dealId = connection.QueryFirst<int>(insertQuery, deal, transaction);
|
||||
|
||||
var subInsertQuery = @"
|
||||
INSERT INTO Services_Deal (Services_ID, Deal_ID, Execution_time)
|
||||
VALUES (@Services_ID, @Deal_ID, @Execution_time)";
|
||||
INSERT INTO Services_Deal (Services_ID, Deal_ID, Execution_time)
|
||||
VALUES (@Services_ID, @Deal_ID, @Execution_time)";
|
||||
foreach (var elem in deal.DealServices)
|
||||
{
|
||||
connection.Execute(subInsertQuery, new { elem.Services_ID,
|
||||
@ -58,9 +58,8 @@ VALUES (@Services_ID, @Deal_ID, @Execution_time)";
|
||||
try
|
||||
{
|
||||
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||
var deleteQuery = @"
|
||||
DELETE FROM Deal
|
||||
WHERE Id = @id";
|
||||
var deleteQuery = @"DELETE FROM Deal
|
||||
WHERE Id = @id";
|
||||
connection.Execute(deleteQuery, new { id });
|
||||
}
|
||||
catch (Exception ex)
|
||||
@ -77,10 +76,39 @@ WHERE Id = @id";
|
||||
try
|
||||
{
|
||||
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||
var selectQuery = @"SELECT * FROM Deal";
|
||||
var deals = connection.Query<Deal>(selectQuery);
|
||||
var selectQuery = @"SELECT
|
||||
de.*,
|
||||
bu.Full_name BuyerName,
|
||||
sd.Deal_Id,
|
||||
ss.Name DealName,
|
||||
sd.Services_Id,
|
||||
sd.Execution_time
|
||||
FROM Deal de
|
||||
LEFT JOIN Buyer bu on bu.Id = de.Buyer_Id
|
||||
INNER JOIN Services_Deal sd on sd.Deal_Id = de.Id
|
||||
LEFT JOIN Services ss on ss.Id = sd.Services_Id";
|
||||
var servicesDict = new Dictionary<int, List<ServicesDeal>>();
|
||||
|
||||
var deals = connection.Query<Deal, ServicesDeal, Deal>(selectQuery,
|
||||
(deal, servicesDeal) =>
|
||||
{
|
||||
if (!servicesDict.TryGetValue(deal.Id, out var sd))
|
||||
{
|
||||
sd = [];
|
||||
servicesDict.Add(deal.Id, sd);
|
||||
}
|
||||
|
||||
sd.Add(servicesDeal);
|
||||
return deal;
|
||||
}, splitOn: "Deal_Id");
|
||||
_logger.LogDebug("Полученные объекты: {json}", JsonConvert.SerializeObject(deals));
|
||||
return deals;
|
||||
|
||||
return servicesDict.Select(x =>
|
||||
{
|
||||
var dl = deals.First(y => y.Id == x.Key);
|
||||
dl.SetServicesDeal(x.Value);
|
||||
return dl;
|
||||
}).ToArray();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user