Закончили реализацую репозиториев, кроме многи ко многим
This commit is contained in:
parent
e0e624f0ea
commit
66c30cdb8c
@ -1,39 +1,127 @@
|
||||
using ProjectTourAgency.Enities;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using ProjectTourAgency.Enities;
|
||||
using ProjectTourAgency.Repositories;
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Dapper;
|
||||
using System.Data.SqlClient;
|
||||
|
||||
namespace ProjectTourAgency.Implementations
|
||||
namespace ProjectTourAgency.Implementations;
|
||||
|
||||
public class AddMoneyRepository : IAddMoneyRepository
|
||||
{
|
||||
internal class AddMoneyRepository : IAddMoneyRepository
|
||||
|
||||
private readonly IConnectionString _connectionString;
|
||||
private readonly ILogger<AddMoneyRepository> _logger;
|
||||
public AddMoneyRepository(IConnectionString connectionString, ILogger<AddMoneyRepository> logger)
|
||||
{
|
||||
public void CreateAddMoney(AddMoney client)
|
||||
_connectionString = connectionString;
|
||||
_logger = logger;
|
||||
}
|
||||
public void CreateAddMoney(AddMoney AddMoney)
|
||||
{
|
||||
_logger.LogInformation("Добавление объекта");
|
||||
_logger.LogDebug("Объект: {jspn}", JsonConvert.SerializeObject(AddMoney));
|
||||
try
|
||||
{
|
||||
using var connection = new SqlConnection(_connectionString.ConnectionString);
|
||||
var queryInsert = @"
|
||||
INSERT INTO AddMoneys (ClientId,Date,MoneyAmount)
|
||||
VALUES (@ClientId,@Date,@MoneyAmount)";
|
||||
connection.Execute(queryInsert, AddMoney);
|
||||
|
||||
}
|
||||
|
||||
public void DeleteAddMoney(int id)
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка при добавлении объекта");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
public void DeleteAddMoney(int id)
|
||||
{
|
||||
_logger.LogInformation("Удаление объекта");
|
||||
_logger.LogDebug("Объект: {id}", id);
|
||||
try
|
||||
{
|
||||
using var connection = new SqlConnection(_connectionString.ConnectionString);
|
||||
connection.Open();
|
||||
var queryDelete = @"
|
||||
DELETE FROM AddMoneys
|
||||
WHERE Id = @Id";
|
||||
connection.Execute(queryDelete, new { id });
|
||||
|
||||
}
|
||||
|
||||
public AddMoney ReadAddMoneyById(int id)
|
||||
catch (Exception ex)
|
||||
{
|
||||
return AddMoney.CreateEntity(0,0,DateTime.Now,0);
|
||||
_logger.LogError(ex, "Ошибка при ужалении объекта");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
public IEnumerable<AddMoney> ReadAddMoneys()
|
||||
public AddMoney ReadAddMoneyById(int id)
|
||||
{
|
||||
_logger.LogInformation("Получение объекта по идентификатору");
|
||||
_logger.LogDebug("Объект: {id}", id);
|
||||
try
|
||||
{
|
||||
return [];
|
||||
using var connection = new SqlConnection(_connectionString.ConnectionString);
|
||||
var querySelect = @"
|
||||
SELECT * FROM AddMoneys
|
||||
WHERE [Id] = @Id";
|
||||
var AddMoney = connection.QueryFirst<AddMoney>(querySelect, new { id });
|
||||
_logger.LogDebug("Найденный объект: {json}", JsonConvert.SerializeObject(AddMoney));
|
||||
return AddMoney;
|
||||
|
||||
}
|
||||
|
||||
public void UpdateAddMoney(AddMoney client)
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка при поиске объекта");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
public IEnumerable<AddMoney> ReadAddMoneys()
|
||||
{
|
||||
_logger.LogInformation("Получение всех объектов");
|
||||
try
|
||||
{
|
||||
using var connection = new SqlConnection(_connectionString.ConnectionString);
|
||||
var querySelect = @"SELECT * FROM AddMoneys";
|
||||
var AddMoneys = connection.Query<AddMoney>(querySelect);
|
||||
_logger.LogDebug("Полученные объекты: {json}", JsonConvert.SerializeObject(AddMoneys));
|
||||
return AddMoneys;
|
||||
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка при чтении объектов");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
public void UpdateAddMoney(AddMoney AddMoney)
|
||||
{
|
||||
_logger.LogInformation("Редактирование объекта");
|
||||
_logger.LogDebug("Объект: {json}", JsonConvert.SerializeObject(AddMoney));
|
||||
try
|
||||
{
|
||||
using var connection = new SqlConnection(_connectionString.ConnectionString);
|
||||
var queryUpdate = @"
|
||||
UPDATE AddMoneys
|
||||
SET
|
||||
ClientId = @ClientId,
|
||||
Date = @Date,
|
||||
MoneyAmount = @MoneyAmount";
|
||||
connection.Execute(queryUpdate, AddMoney);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка при редкатировании объекта");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -9,5 +9,5 @@ namespace ProjectTourAgency.Implementations;
|
||||
|
||||
public class ConnectionString : IConnectionString
|
||||
{
|
||||
string IConnectionString.ConnectionString => "";
|
||||
string IConnectionString.ConnectionString => "Server=localHost;Port=...;Database=...;";
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user