a
This commit is contained in:
parent
a044cb7680
commit
17f644cf7b
4
ShoeStore/.editorconfig
Normal file
4
ShoeStore/.editorconfig
Normal file
@ -0,0 +1,4 @@
|
||||
[*.cs]
|
||||
|
||||
# CS0618: Тип или член устарел
|
||||
dotnet_diagnostic.CS0618.severity = none
|
@ -11,20 +11,20 @@ public class ShoesReplenishment
|
||||
public int Id { get; private set; }
|
||||
public int FactoryId { get; private set; }
|
||||
public DateTime DateReceipt { get; private set; }
|
||||
public IEnumerable<ShoesShoesReplenishment> ShoesShoesReplenishment
|
||||
public IEnumerable<ShoesShoesReplenishment> ShoesShoesReplenishments
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
} = [];
|
||||
public static ShoesReplenishment CreateOpeartion(int id, int factoryId,
|
||||
IEnumerable<ShoesShoesReplenishment> shoesShoesReplenishment)
|
||||
IEnumerable<ShoesShoesReplenishment> shoesShoesReplenishments)
|
||||
{
|
||||
return new ShoesReplenishment
|
||||
{
|
||||
Id = id,
|
||||
FactoryId = factoryId,
|
||||
DateReceipt = DateTime.Now,
|
||||
ShoesShoesReplenishment = shoesShoesReplenishment
|
||||
ShoesShoesReplenishments = shoesShoesReplenishments
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,11 @@
|
||||
using ShoeStore.Repositories.Implementations;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Serilog;
|
||||
using ShoeStore.Repositories;
|
||||
using Unity.Lifetime;
|
||||
using ShoeStore.Repositories.Implementations;
|
||||
using Unity;
|
||||
using Unity.Lifetime;
|
||||
using Unity.Microsoft.Logging;
|
||||
|
||||
namespace ShoeStore
|
||||
{
|
||||
@ -18,9 +22,15 @@ namespace ShoeStore
|
||||
ApplicationConfiguration.Initialize();
|
||||
Application.Run(CreateContainer().Resolve<FormStorage>());
|
||||
}
|
||||
private static IUnityContainer CreateContainer()
|
||||
private static UnityContainer CreateContainer()
|
||||
{
|
||||
var container = new UnityContainer();
|
||||
|
||||
container.AddExtension(new
|
||||
LoggingExtension(CreateLoggerFactory()));
|
||||
|
||||
container.RegisterType<IConnectionString,
|
||||
ConnectionString>(new SingletonLifetimeManager());
|
||||
container.RegisterType<IFactoryRepository,
|
||||
FactoryRepository>(new TransientLifetimeManager());
|
||||
container.RegisterType<IStoreRepository,
|
||||
@ -33,5 +43,16 @@ namespace ShoeStore
|
||||
ShoesReplenishmentRepository>(new TransientLifetimeManager());
|
||||
return container;
|
||||
}
|
||||
private static LoggerFactory CreateLoggerFactory()
|
||||
{
|
||||
var loggerFactory = new LoggerFactory();
|
||||
loggerFactory.AddSerilog(new LoggerConfiguration()
|
||||
.ReadFrom.Configuration(new ConfigurationBuilder()
|
||||
.SetBasePath(Directory.GetCurrentDirectory())
|
||||
.AddJsonFile("appsettings.json")
|
||||
.Build())
|
||||
.CreateLogger());
|
||||
return loggerFactory;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
12
ShoeStore/ShoeStore/Repositories/IConnectionString.cs
Normal file
12
ShoeStore/ShoeStore/Repositories/IConnectionString.cs
Normal file
@ -0,0 +1,12 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ShoeStore.Repositories;
|
||||
|
||||
internal interface IConnectionString
|
||||
{
|
||||
string ConnectionString { get; }
|
||||
}
|
@ -0,0 +1,13 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ShoeStore.Repositories.Implementations;
|
||||
|
||||
internal class ConnectionString : IConnectionString
|
||||
{
|
||||
string IConnectionString.ConnectionString => "";
|
||||
}
|
||||
|
@ -1,35 +1,134 @@
|
||||
using ShoeStore.Entities;
|
||||
using Dapper;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Newtonsoft.Json;
|
||||
using ShoeStore.Entities;
|
||||
using ShoeStore.Entities.Enums;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data.SqlClient;
|
||||
using System.Linq;
|
||||
using System.Numerics;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ShoeStore.Repositories.Implementations;
|
||||
|
||||
public class FactoryRepository : IFactoryRepository
|
||||
internal class FactoryRepository : IFactoryRepository
|
||||
{
|
||||
private readonly IConnectionString _connectionString;
|
||||
private readonly ILogger<FactoryRepository> _logger;
|
||||
public FactoryRepository(IConnectionString connectionString,
|
||||
ILogger<FactoryRepository> logger)
|
||||
{
|
||||
_connectionString = connectionString;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public void CreateFactory(Factory factory)
|
||||
{
|
||||
_logger.LogInformation("Добавление объекта");
|
||||
_logger.LogDebug("Объект: {json}",
|
||||
JsonConvert.SerializeObject(factory));
|
||||
try
|
||||
{
|
||||
using var connection = new
|
||||
SqlConnection(_connectionString.ConnectionString);
|
||||
var queryInsert = @"
|
||||
INSERT INTO Factorys (FactoryName, Manufacturer)
|
||||
VALUES (@FactoryName, @Manufacturer)";
|
||||
connection.Execute(queryInsert, factory);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка при добавлении объекта");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
public void UpdateFactory(Factory factory)
|
||||
{
|
||||
_logger.LogInformation("Редактирование объекта");
|
||||
_logger.LogDebug("Объект: {json}",
|
||||
JsonConvert.SerializeObject(factory));
|
||||
try
|
||||
{
|
||||
using var connection = new
|
||||
SqlConnection(_connectionString.ConnectionString);
|
||||
var queryUpdate = @"
|
||||
UPDATE Factorys
|
||||
SET
|
||||
FactoryName=@FactoryName,
|
||||
Manufacturer=@Manufacturer
|
||||
WHERE [Id]=@Id";
|
||||
connection.Execute(queryUpdate, factory);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка при редактировании объекта");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
public void DeleteFactory(int id)
|
||||
{
|
||||
_logger.LogInformation("Удаление объекта");
|
||||
_logger.LogDebug("Объект: {id}", id);
|
||||
try
|
||||
{
|
||||
using var connection = new
|
||||
SqlConnection(_connectionString.ConnectionString);
|
||||
var queryDelete = @"
|
||||
DELETE FROM Factorys
|
||||
WHERE Id=@id";
|
||||
connection.Execute(queryDelete, new { id });
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка при удалении объекта");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
public Factory ReadFactoryById(int id)
|
||||
{
|
||||
return Factory.CreateEntity(0, string.Empty,
|
||||
Manufacturer.None);
|
||||
_logger.LogInformation("Получение объекта по идентификатору");
|
||||
_logger.LogDebug("Объект: {id}", id);
|
||||
try
|
||||
{
|
||||
using var connection = new
|
||||
SqlConnection(_connectionString.ConnectionString);
|
||||
var querySelect = @"
|
||||
SELECT * FROM Factorys
|
||||
WHERE Id=@id";
|
||||
var factory = connection.QueryFirst<Factory>(querySelect,
|
||||
new { id });
|
||||
_logger.LogDebug("Найденный объект: {json}",
|
||||
JsonConvert.SerializeObject(factory));
|
||||
return factory;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка при поиске объекта");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
public IEnumerable<Factory> ReadFactorys()
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
public void UpdateFactory(Factory factory)
|
||||
{
|
||||
_logger.LogInformation("Получение всех объектов");
|
||||
try
|
||||
{
|
||||
using var connection = new
|
||||
SqlConnection(_connectionString.ConnectionString);
|
||||
var querySelect = "SELECT * FROM Factorys";
|
||||
var factorys = connection.Query<Factory>(querySelect);
|
||||
_logger.LogDebug("Полученные объекты: {json}",
|
||||
JsonConvert.SerializeObject(factorys));
|
||||
return factorys;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка при чтении объектов");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,25 +1,103 @@
|
||||
using ShoeStore.Entities;
|
||||
using Dapper;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Newtonsoft.Json;
|
||||
using ShoeStore.Entities;
|
||||
using ShoeStore.Entities.Enums;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data.SqlClient;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ShoeStore.Repositories.Implementations;
|
||||
|
||||
public class ShoesReplenishmentRepository : IShoesReplenishmentRepository
|
||||
internal class ShoesReplenishmentRepository : IShoesReplenishmentRepository
|
||||
{
|
||||
private readonly IConnectionString _connectionString;
|
||||
private readonly ILogger<ShoesReplenishmentRepository> _logger;
|
||||
public ShoesReplenishmentRepository(IConnectionString connectionString,
|
||||
ILogger<ShoesReplenishmentRepository> logger)
|
||||
{
|
||||
_connectionString = connectionString;
|
||||
_logger = logger;
|
||||
}
|
||||
public void CreateShoesReplenishment(ShoesReplenishment shoesReplenishment)
|
||||
{
|
||||
_logger.LogInformation("Добавление объекта");
|
||||
_logger.LogDebug("Объект: {json}",
|
||||
JsonConvert.SerializeObject(shoesReplenishment));
|
||||
try
|
||||
{
|
||||
using var connection = new
|
||||
SqlConnection(_connectionString.ConnectionString);
|
||||
connection.Open();
|
||||
using var transaction = connection.BeginTransaction();
|
||||
var queryInsert = @"
|
||||
INSERT INTO ShoesReplenishments (EmployeeId, DateReceipt)
|
||||
VALUES (@EmployeeId, @DateReceipt);
|
||||
SELECT MAX(Id) FROM ShoesReplenishments";
|
||||
var shoesReplenishmentId =
|
||||
connection.QueryFirst<int>(queryInsert, shoesReplenishment, transaction);
|
||||
var querySubInsert = @"
|
||||
INSERT INTO ShoesShoesReplenishments (ShoesReplenishmentId, ShoesId, Count)
|
||||
VALUES (@ShoesReplenishmentId,@ShoesId, @Count)";
|
||||
foreach (var elem in shoesReplenishment.ShoesShoesReplenishments)
|
||||
{
|
||||
connection.Execute(querySubInsert, new
|
||||
{
|
||||
shoesReplenishmentId,
|
||||
elem.ShoesId,
|
||||
elem.Count
|
||||
}, transaction);
|
||||
}
|
||||
transaction.Commit();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка при добавлении объекта");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
public void DeleteShoesReplenishment(int id)
|
||||
{
|
||||
_logger.LogInformation("Удаление объекта");
|
||||
_logger.LogDebug("Объект: {id}", id);
|
||||
try
|
||||
{
|
||||
using var connection = new
|
||||
SqlConnection(_connectionString.ConnectionString);
|
||||
var queryDelete = @"
|
||||
DELETE FROM ShoesReplenishments
|
||||
WHERE Id=@id";
|
||||
connection.Execute(queryDelete, new { id });
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка при удалении объекта");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
public IEnumerable<ShoesReplenishment> ReadShoesReplenishment(DateTime? dateForm = null, DateTime? dateTo = null, int? shoesId = null, int? factoryId = null)
|
||||
public IEnumerable<ShoesReplenishment> ReadShoesReplenishment(DateTime?
|
||||
dateForm = null, DateTime? dateTo = null, int? shoesId = null, int? employeeId =
|
||||
null)
|
||||
{
|
||||
return [];
|
||||
_logger.LogInformation("Получение всех объектов");
|
||||
try
|
||||
{
|
||||
using var connection = new
|
||||
SqlConnection(_connectionString.ConnectionString);
|
||||
var querySelect = @"SELECT * FROM ShoesReplenishments";
|
||||
var shoesReplenishments =
|
||||
connection.Query<ShoesReplenishment>(querySelect);
|
||||
_logger.LogDebug("Полученные объекты: {json}",
|
||||
JsonConvert.SerializeObject(shoesReplenishments));
|
||||
return shoesReplenishments;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка при чтении объектов");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,36 +1,133 @@
|
||||
using Microsoft.VisualBasic.FileIO;
|
||||
using Dapper;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.VisualBasic.FileIO;
|
||||
using Newtonsoft.Json;
|
||||
using ShoeStore.Entities;
|
||||
using ShoeStore.Entities.Enums;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data.SqlClient;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ShoeStore.Repositories.Implementations;
|
||||
|
||||
public class ShoesRepository : IShoesRepository
|
||||
internal class ShoesRepository : IShoesRepository
|
||||
{
|
||||
private readonly IConnectionString _connectionString;
|
||||
private readonly ILogger<ShoesRepository> _logger;
|
||||
public ShoesRepository(IConnectionString connectionString,
|
||||
ILogger<ShoesRepository> logger)
|
||||
{
|
||||
_connectionString = connectionString;
|
||||
_logger = logger;
|
||||
}
|
||||
public void CreateShoes(Shoes shoes)
|
||||
{
|
||||
_logger.LogInformation("Добавление объекта");
|
||||
_logger.LogDebug("Объект: {json}",
|
||||
JsonConvert.SerializeObject(shoes));
|
||||
try
|
||||
{
|
||||
using var connection = new
|
||||
SqlConnection(_connectionString.ConnectionString);
|
||||
var queryInsert = @"
|
||||
INSERT INTO Shoess (ShoesType, Name, Description)
|
||||
VALUES (@ShoesType, @Name, @Description)";
|
||||
connection.Execute(queryInsert, shoes);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка при добавлении объекта");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
public void DeleteShoes(int id)
|
||||
{
|
||||
}
|
||||
|
||||
public Shoes ReadShoesById(int id)
|
||||
{
|
||||
return Shoes.CreateEntity(0, ShoesType.None, string.Empty,
|
||||
string.Empty);
|
||||
}
|
||||
|
||||
public IEnumerable<Shoes> ReadShoess()
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
public void UpdateShoes(Shoes shoes)
|
||||
{
|
||||
_logger.LogInformation("Редактирование объекта");
|
||||
_logger.LogDebug("Объект: {json}",
|
||||
JsonConvert.SerializeObject(shoes));
|
||||
try
|
||||
{
|
||||
using var connection = new
|
||||
SqlConnection(_connectionString.ConnectionString);
|
||||
var queryUpdate = @"
|
||||
UPDATE Shoess
|
||||
SET
|
||||
ShoesType=@ShoesType,
|
||||
Name=@Name,
|
||||
Description=@Description
|
||||
WHERE Id=@Id";
|
||||
connection.Execute(queryUpdate, shoes);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка при редактировании объекта");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
public void DeleteShoes(int id)
|
||||
{
|
||||
_logger.LogInformation("Удаление объекта");
|
||||
_logger.LogDebug("Объект: {id}", id);
|
||||
try
|
||||
{
|
||||
using var connection = new
|
||||
SqlConnection(_connectionString.ConnectionString);
|
||||
var queryDelete = @"
|
||||
DELETE FROM Shoess
|
||||
WHERE Id=@id";
|
||||
connection.Execute(queryDelete, new { id });
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка при удалении объекта");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
public Shoes ReadShoesById(int id)
|
||||
{
|
||||
_logger.LogInformation("Получение объекта по идентификатору");
|
||||
_logger.LogDebug("Объект: {id}", id);
|
||||
try
|
||||
{
|
||||
using var connection = new
|
||||
SqlConnection(_connectionString.ConnectionString);
|
||||
var querySelect = @"
|
||||
SELECT * FROM Shoess
|
||||
WHERE Id=@id";
|
||||
var shoes = connection.QueryFirst<Shoes>(querySelect, new
|
||||
{
|
||||
id
|
||||
});
|
||||
_logger.LogDebug("Найденный объект: {json}",
|
||||
JsonConvert.SerializeObject(shoes));
|
||||
return shoes;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка при поиске объекта");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
public IEnumerable<Shoes> ReadShoess()
|
||||
{
|
||||
_logger.LogInformation("Получение всех объектов");
|
||||
try
|
||||
{
|
||||
using var connection = new
|
||||
SqlConnection(_connectionString.ConnectionString);
|
||||
var querySelect = "SELECT * FROM Shoess";
|
||||
var shoess = connection.Query<Shoes>(querySelect);
|
||||
_logger.LogDebug("Полученные объекты: {json}",
|
||||
JsonConvert.SerializeObject(shoess));
|
||||
return shoess;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка при чтении объектов");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,20 +1,66 @@
|
||||
using ShoeStore.Entities;
|
||||
using Dapper;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Newtonsoft.Json;
|
||||
using ShoeStore.Entities;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data.SqlClient;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ShoeStore.Repositories.Implementations;
|
||||
|
||||
public class ShoesSaleRepository : IShoesSaleRepository
|
||||
internal class ShoesSaleRepository : IShoesSaleRepository
|
||||
{
|
||||
private readonly IConnectionString _connectionString;
|
||||
private readonly ILogger<ShoesSaleRepository> _logger;
|
||||
public ShoesSaleRepository(IConnectionString connectionString,
|
||||
ILogger<ShoesSaleRepository> logger)
|
||||
{
|
||||
_connectionString = connectionString;
|
||||
_logger = logger;
|
||||
}
|
||||
public void CreateShoesSale(ShoesSale shoesSale)
|
||||
{
|
||||
_logger.LogInformation("Добавление объекта");
|
||||
_logger.LogDebug("Объект: {json}",
|
||||
JsonConvert.SerializeObject(shoesSale));
|
||||
try
|
||||
{
|
||||
using var connection = new
|
||||
SqlConnection(_connectionString.ConnectionString);
|
||||
var queryInsert = @"
|
||||
INSERT INTO ShoesSales (ShoesId, FactoryId, StoreId, SaleDate, Specificity)
|
||||
VALUES (@ShoesId, @FactoryId, @StoreId, @SaleDate, @Specificity)";
|
||||
connection.Execute(queryInsert, shoesSale);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка при добавлении объекта");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
public IEnumerable<ShoesSale> ReadShoesSales(DateTime? dateForm = null, DateTime? dateTo = null, int? shoesId = null, int? factoryId = null, int? storeId = null)
|
||||
public IEnumerable<ShoesSale> ReadShoesSales(DateTime? dateForm =
|
||||
null, DateTime? dateTo = null, int? shoesId = null, int? factoryId = null, int?
|
||||
storeId = null)
|
||||
{
|
||||
return [];
|
||||
_logger.LogInformation("Получение всех объектов");
|
||||
try
|
||||
{
|
||||
using var connection = new
|
||||
SqlConnection(_connectionString.ConnectionString);
|
||||
var querySelect = "SELECT * FROM ShoesSales";
|
||||
var shoesSales =
|
||||
connection.Query<ShoesSale>(querySelect);
|
||||
_logger.LogDebug("Полученные объекты: {json}",
|
||||
JsonConvert.SerializeObject(shoesSales));
|
||||
return shoesSales;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка при чтении объектов");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,34 +1,135 @@
|
||||
using ShoeStore.Entities;
|
||||
using Dapper;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Newtonsoft.Json;
|
||||
using ShoeStore.Entities;
|
||||
using ShoeStore.Entities.Enums;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data.SqlClient;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ShoeStore.Repositories.Implementations;
|
||||
|
||||
public class StoreRepository : IStoreRepository
|
||||
internal class StoreRepository : IStoreRepository
|
||||
{
|
||||
private readonly IConnectionString _connectionString;
|
||||
private readonly ILogger<StoreRepository> _logger;
|
||||
public StoreRepository(IConnectionString connectionString,
|
||||
ILogger<StoreRepository> logger)
|
||||
{
|
||||
_connectionString = connectionString;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public void CreateStore(Store store)
|
||||
{
|
||||
_logger.LogInformation("Добавление объекта");
|
||||
_logger.LogDebug("Объект: {json}", JsonConvert.SerializeObject(store));
|
||||
try
|
||||
{
|
||||
using var connection = new
|
||||
SqlConnection(_connectionString.ConnectionString);
|
||||
var queryInsert = @"
|
||||
INSERT INTO Stores (StoreType, StoreName, Employees, Visitors)
|
||||
VALUES (@StoreType, @StoreName, @Employees, @Visitors)";
|
||||
connection.Execute(queryInsert, store);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка при добавлении объекта");
|
||||
throw;
|
||||
};
|
||||
}
|
||||
public void UpdateStore(Store store)
|
||||
{
|
||||
_logger.LogInformation("Редактирование объекта");
|
||||
_logger.LogDebug("Объект: {json}", JsonConvert.SerializeObject(store));
|
||||
try
|
||||
{
|
||||
using var connection = new
|
||||
SqlConnection(_connectionString.ConnectionString);
|
||||
var queryUpdate = @"
|
||||
UPDATE Store
|
||||
SET
|
||||
StoreType=@StoreType,
|
||||
StoreName=@StoreName,
|
||||
Employees=@Employees,
|
||||
Visitors=@Visitors
|
||||
WHERE Id=@Id";
|
||||
connection.Execute(queryUpdate, store);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка при редактировании объекта");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
public void DeleteStore(int id)
|
||||
{
|
||||
_logger.LogInformation("Удаление объекта");
|
||||
_logger.LogDebug("Объект: {id}", id);
|
||||
try
|
||||
{
|
||||
using var connection = new
|
||||
SqlConnection(_connectionString.ConnectionString);
|
||||
var queryDelete = @"
|
||||
DELETE FROM Store
|
||||
WHERE Id=@id";
|
||||
connection.Execute(queryDelete, new { id });
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка при удалении объекта");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
public Store ReadStoreById(int id)
|
||||
{
|
||||
return Store.CreateEntity(0, string.Empty, string.Empty, 0, 0);
|
||||
_logger.LogInformation("Получение объекта по идентификатору");
|
||||
_logger.LogDebug("Объект: {id}", id);
|
||||
try
|
||||
{
|
||||
using var connection = new
|
||||
SqlConnection(_connectionString.ConnectionString);
|
||||
var querySelect = @"
|
||||
SELECT * FROM Store
|
||||
WHERE [Id]=@id";
|
||||
var store = connection.QueryFirst<Store>(querySelect, new
|
||||
{
|
||||
id
|
||||
});
|
||||
_logger.LogDebug("Найденный объект: {json}", JsonConvert.SerializeObject(store));
|
||||
return store;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка при поиске объекта");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
public IEnumerable<Store> ReadStores()
|
||||
{
|
||||
return [];
|
||||
_logger.LogInformation("Получение всех объектов");
|
||||
try
|
||||
{
|
||||
using var connection = new
|
||||
SqlConnection(_connectionString.ConnectionString);
|
||||
var querySelect = "SELECT * FROM Stores";
|
||||
var stores = connection.Query<Store>(querySelect);
|
||||
_logger.LogDebug("Полученные объекты: {json}", JsonConvert.SerializeObject(stores));
|
||||
return stores;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка при чтении объектов");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
public void UpdateStore(Store store)
|
||||
{
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -9,7 +9,18 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Dapper" Version="2.1.35" />
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration" Version="9.0.0" />
|
||||
<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="Serilog" Version="4.1.0" />
|
||||
<PackageReference Include="Serilog.Extensions.Logging" Version="8.0.0" />
|
||||
<PackageReference Include="Serilog.Settings.Configuration" Version="8.0.4" />
|
||||
<PackageReference Include="Serilog.Sinks.File" Version="6.0.0" />
|
||||
<PackageReference Include="System.Data.SqlClient" Version="4.9.0" />
|
||||
<PackageReference Include="Unity" Version="5.11.10" />
|
||||
<PackageReference Include="Unity.Microsoft.Logging" Version="5.11.1" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
@ -27,4 +38,10 @@
|
||||
</EmbeddedResource>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Update="appsettings.json">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
15
ShoeStore/ShoeStore/appsettings.json
Normal file
15
ShoeStore/ShoeStore/appsettings.json
Normal file
@ -0,0 +1,15 @@
|
||||
{
|
||||
"Serilog": {
|
||||
"Using": [ "Serilog.Sinks.File" ],
|
||||
"MinimumLevel": "Debug",
|
||||
"WriteTo": [
|
||||
{
|
||||
"Name": "File",
|
||||
"Args": {
|
||||
"path": "Logs/zoo_log.txt",
|
||||
"rollingInterval": "Day"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user