k
This commit is contained in:
parent
17f644cf7b
commit
ea30177fe1
@ -6,7 +6,7 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace ShoeStore.Repositories;
|
||||
|
||||
internal interface IConnectionString
|
||||
public interface IConnectionString
|
||||
{
|
||||
string ConnectionString { get; }
|
||||
public string ConnectionString { get; }
|
||||
}
|
||||
|
@ -8,6 +8,6 @@ namespace ShoeStore.Repositories.Implementations;
|
||||
|
||||
internal class ConnectionString : IConnectionString
|
||||
{
|
||||
string IConnectionString.ConnectionString => "";
|
||||
string IConnectionString.ConnectionString => "Server=localhost;Port=5432;Database=BDOTP;User Id=postgres;Password=postgres;";
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,7 @@
|
||||
using Dapper;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Newtonsoft.Json;
|
||||
using Npgsql;
|
||||
using ShoeStore.Entities;
|
||||
using ShoeStore.Entities.Enums;
|
||||
using System;
|
||||
@ -32,7 +33,7 @@ internal class FactoryRepository : IFactoryRepository
|
||||
try
|
||||
{
|
||||
using var connection = new
|
||||
SqlConnection(_connectionString.ConnectionString);
|
||||
NpgsqlConnection(_connectionString.ConnectionString);
|
||||
var queryInsert = @"
|
||||
INSERT INTO Factorys (FactoryName, Manufacturer)
|
||||
VALUES (@FactoryName, @Manufacturer)";
|
||||
@ -52,7 +53,7 @@ VALUES (@FactoryName, @Manufacturer)";
|
||||
try
|
||||
{
|
||||
using var connection = new
|
||||
SqlConnection(_connectionString.ConnectionString);
|
||||
NpgsqlConnection(_connectionString.ConnectionString);
|
||||
var queryUpdate = @"
|
||||
UPDATE Factorys
|
||||
SET
|
||||
@ -75,7 +76,7 @@ WHERE [Id]=@Id";
|
||||
try
|
||||
{
|
||||
using var connection = new
|
||||
SqlConnection(_connectionString.ConnectionString);
|
||||
NpgsqlConnection(_connectionString.ConnectionString);
|
||||
var queryDelete = @"
|
||||
DELETE FROM Factorys
|
||||
WHERE Id=@id";
|
||||
@ -95,7 +96,7 @@ WHERE Id=@id";
|
||||
try
|
||||
{
|
||||
using var connection = new
|
||||
SqlConnection(_connectionString.ConnectionString);
|
||||
NpgsqlConnection(_connectionString.ConnectionString);
|
||||
var querySelect = @"
|
||||
SELECT * FROM Factorys
|
||||
WHERE Id=@id";
|
||||
|
@ -1,6 +1,7 @@
|
||||
using Dapper;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Newtonsoft.Json;
|
||||
using Npgsql;
|
||||
using ShoeStore.Entities;
|
||||
using ShoeStore.Entities.Enums;
|
||||
using System;
|
||||
@ -30,7 +31,7 @@ internal class ShoesReplenishmentRepository : IShoesReplenishmentRepository
|
||||
try
|
||||
{
|
||||
using var connection = new
|
||||
SqlConnection(_connectionString.ConnectionString);
|
||||
NpgsqlConnection(_connectionString.ConnectionString);
|
||||
connection.Open();
|
||||
using var transaction = connection.BeginTransaction();
|
||||
var queryInsert = @"
|
||||
@ -66,7 +67,7 @@ VALUES (@ShoesReplenishmentId,@ShoesId, @Count)";
|
||||
try
|
||||
{
|
||||
using var connection = new
|
||||
SqlConnection(_connectionString.ConnectionString);
|
||||
NpgsqlConnection(_connectionString.ConnectionString);
|
||||
var queryDelete = @"
|
||||
DELETE FROM ShoesReplenishments
|
||||
WHERE Id=@id";
|
||||
@ -86,7 +87,7 @@ WHERE Id=@id";
|
||||
try
|
||||
{
|
||||
using var connection = new
|
||||
SqlConnection(_connectionString.ConnectionString);
|
||||
NpgsqlConnection(_connectionString.ConnectionString);
|
||||
var querySelect = @"SELECT * FROM ShoesReplenishments";
|
||||
var shoesReplenishments =
|
||||
connection.Query<ShoesReplenishment>(querySelect);
|
||||
|
@ -2,6 +2,7 @@
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.VisualBasic.FileIO;
|
||||
using Newtonsoft.Json;
|
||||
using Npgsql;
|
||||
using ShoeStore.Entities;
|
||||
using ShoeStore.Entities.Enums;
|
||||
using System;
|
||||
@ -31,7 +32,7 @@ internal class ShoesRepository : IShoesRepository
|
||||
try
|
||||
{
|
||||
using var connection = new
|
||||
SqlConnection(_connectionString.ConnectionString);
|
||||
NpgsqlConnection(_connectionString.ConnectionString);
|
||||
var queryInsert = @"
|
||||
INSERT INTO Shoess (ShoesType, Name, Description)
|
||||
VALUES (@ShoesType, @Name, @Description)";
|
||||
@ -51,7 +52,7 @@ VALUES (@ShoesType, @Name, @Description)";
|
||||
try
|
||||
{
|
||||
using var connection = new
|
||||
SqlConnection(_connectionString.ConnectionString);
|
||||
NpgsqlConnection(_connectionString.ConnectionString);
|
||||
var queryUpdate = @"
|
||||
UPDATE Shoess
|
||||
SET
|
||||
@ -74,7 +75,7 @@ WHERE Id=@Id";
|
||||
try
|
||||
{
|
||||
using var connection = new
|
||||
SqlConnection(_connectionString.ConnectionString);
|
||||
NpgsqlConnection(_connectionString.ConnectionString);
|
||||
var queryDelete = @"
|
||||
DELETE FROM Shoess
|
||||
WHERE Id=@id";
|
||||
@ -93,7 +94,7 @@ WHERE Id=@id";
|
||||
try
|
||||
{
|
||||
using var connection = new
|
||||
SqlConnection(_connectionString.ConnectionString);
|
||||
NpgsqlConnection(_connectionString.ConnectionString);
|
||||
var querySelect = @"
|
||||
SELECT * FROM Shoess
|
||||
WHERE Id=@id";
|
||||
@ -117,7 +118,7 @@ WHERE Id=@id";
|
||||
try
|
||||
{
|
||||
using var connection = new
|
||||
SqlConnection(_connectionString.ConnectionString);
|
||||
NpgsqlConnection(_connectionString.ConnectionString);
|
||||
var querySelect = "SELECT * FROM Shoess";
|
||||
var shoess = connection.Query<Shoes>(querySelect);
|
||||
_logger.LogDebug("Полученные объекты: {json}",
|
||||
|
@ -1,6 +1,7 @@
|
||||
using Dapper;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Newtonsoft.Json;
|
||||
using Npgsql;
|
||||
using ShoeStore.Entities;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@ -29,7 +30,7 @@ internal class ShoesSaleRepository : IShoesSaleRepository
|
||||
try
|
||||
{
|
||||
using var connection = new
|
||||
SqlConnection(_connectionString.ConnectionString);
|
||||
NpgsqlConnection(_connectionString.ConnectionString);
|
||||
var queryInsert = @"
|
||||
INSERT INTO ShoesSales (ShoesId, FactoryId, StoreId, SaleDate, Specificity)
|
||||
VALUES (@ShoesId, @FactoryId, @StoreId, @SaleDate, @Specificity)";
|
||||
@ -49,7 +50,7 @@ VALUES (@ShoesId, @FactoryId, @StoreId, @SaleDate, @Specificity)";
|
||||
try
|
||||
{
|
||||
using var connection = new
|
||||
SqlConnection(_connectionString.ConnectionString);
|
||||
NpgsqlConnection(_connectionString.ConnectionString);
|
||||
var querySelect = "SELECT * FROM ShoesSales";
|
||||
var shoesSales =
|
||||
connection.Query<ShoesSale>(querySelect);
|
||||
|
@ -1,6 +1,7 @@
|
||||
using Dapper;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Newtonsoft.Json;
|
||||
using Npgsql;
|
||||
using ShoeStore.Entities;
|
||||
using ShoeStore.Entities.Enums;
|
||||
using System;
|
||||
@ -30,7 +31,7 @@ internal class StoreRepository : IStoreRepository
|
||||
try
|
||||
{
|
||||
using var connection = new
|
||||
SqlConnection(_connectionString.ConnectionString);
|
||||
NpgsqlConnection(_connectionString.ConnectionString);
|
||||
var queryInsert = @"
|
||||
INSERT INTO Stores (StoreType, StoreName, Employees, Visitors)
|
||||
VALUES (@StoreType, @StoreName, @Employees, @Visitors)";
|
||||
@ -49,7 +50,7 @@ VALUES (@StoreType, @StoreName, @Employees, @Visitors)";
|
||||
try
|
||||
{
|
||||
using var connection = new
|
||||
SqlConnection(_connectionString.ConnectionString);
|
||||
NpgsqlConnection(_connectionString.ConnectionString);
|
||||
var queryUpdate = @"
|
||||
UPDATE Store
|
||||
SET
|
||||
@ -74,7 +75,7 @@ WHERE Id=@Id";
|
||||
try
|
||||
{
|
||||
using var connection = new
|
||||
SqlConnection(_connectionString.ConnectionString);
|
||||
NpgsqlConnection(_connectionString.ConnectionString);
|
||||
var queryDelete = @"
|
||||
DELETE FROM Store
|
||||
WHERE Id=@id";
|
||||
@ -94,7 +95,7 @@ WHERE Id=@id";
|
||||
try
|
||||
{
|
||||
using var connection = new
|
||||
SqlConnection(_connectionString.ConnectionString);
|
||||
NpgsqlConnection(_connectionString.ConnectionString);
|
||||
var querySelect = @"
|
||||
SELECT * FROM Store
|
||||
WHERE [Id]=@id";
|
||||
@ -118,7 +119,7 @@ WHERE [Id]=@id";
|
||||
try
|
||||
{
|
||||
using var connection = new
|
||||
SqlConnection(_connectionString.ConnectionString);
|
||||
NpgsqlConnection(_connectionString.ConnectionString);
|
||||
var querySelect = "SELECT * FROM Stores";
|
||||
var stores = connection.Query<Store>(querySelect);
|
||||
_logger.LogDebug("Полученные объекты: {json}", JsonConvert.SerializeObject(stores));
|
||||
|
@ -14,6 +14,7 @@
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="9.0.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Logging" Version="9.0.0" />
|
||||
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
|
||||
<PackageReference Include="Npgsql" Version="9.0.2" />
|
||||
<PackageReference Include="Serilog" Version="4.1.0" />
|
||||
<PackageReference Include="Serilog.Extensions.Logging" Version="8.0.0" />
|
||||
<PackageReference Include="Serilog.Settings.Configuration" Version="8.0.4" />
|
||||
|
Loading…
Reference in New Issue
Block a user