Чистка лишних пустых строк

This commit is contained in:
TikhonElli 2024-12-05 17:27:36 +04:00
parent 745617d8b5
commit 570615e48a
5 changed files with 0 additions and 84 deletions

View File

@ -22,15 +22,12 @@ public class AthleteAccommodationRepository : IAthleteAccommodationRepository
{ {
_logger.LogInformation("Добавление объекта"); _logger.LogInformation("Добавление объекта");
_logger.LogDebug("Объект: {json}", JsonConvert.SerializeObject(athleteAccommodation)); _logger.LogDebug("Объект: {json}", JsonConvert.SerializeObject(athleteAccommodation));
try try
{ {
using var connection = new NpgsqlConnection(_connectionString.ConnectionString); using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
var queryInsert = var queryInsert =
@"INSERT INTO AthleteAccommodation (RoomId, AthleteId, DateStart, DateEnd) @"INSERT INTO AthleteAccommodation (RoomId, AthleteId, DateStart, DateEnd)
VALUES (@RoomId, @AthleteId, @DateStart, @DateEnd)"; VALUES (@RoomId, @AthleteId, @DateStart, @DateEnd)";
connection.Execute(queryInsert, athleteAccommodation); connection.Execute(queryInsert, athleteAccommodation);
} }
catch (Exception ex) catch (Exception ex)
@ -44,13 +41,10 @@ public class AthleteAccommodationRepository : IAthleteAccommodationRepository
{ {
_logger.LogInformation("Удаление объекта"); _logger.LogInformation("Удаление объекта");
_logger.LogDebug("Объект: {id}", id); _logger.LogDebug("Объект: {id}", id);
try try
{ {
using var connection = new NpgsqlConnection(_connectionString.ConnectionString); using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
var queryDelete = @"DELETE FROM AthleteAccommodation WHERE Id=@id"; var queryDelete = @"DELETE FROM AthleteAccommodation WHERE Id=@id";
connection.Execute(queryDelete, new { id }); connection.Execute(queryDelete, new { id });
} }
catch (Exception ex) catch (Exception ex)
@ -64,17 +58,12 @@ public class AthleteAccommodationRepository : IAthleteAccommodationRepository
int? roomId = null, int? athleteId = null) int? roomId = null, int? athleteId = 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 AthleteAccommodation"; var querySelect = "SELECT * FROM AthleteAccommodation";
var athleteAccommodation = connection.Query<AthleteAccommodation>(querySelect); var athleteAccommodation = connection.Query<AthleteAccommodation>(querySelect);
_logger.LogDebug("Полученные объекты: {json}", JsonConvert.SerializeObject(athleteAccommodation)); _logger.LogDebug("Полученные объекты: {json}", JsonConvert.SerializeObject(athleteAccommodation));
return athleteAccommodation; return athleteAccommodation;
} }
catch (Exception ex) catch (Exception ex)

View File

@ -21,15 +21,12 @@ public class AthleteRepository : IAthleteRepository
{ {
_logger.LogInformation("Добавление объекта"); _logger.LogInformation("Добавление объекта");
_logger.LogDebug("Объект: {json}", JsonConvert.SerializeObject(athlete)); _logger.LogDebug("Объект: {json}", JsonConvert.SerializeObject(athlete));
try try
{ {
using var connection = new NpgsqlConnection(_connectionString.ConnectionString); using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
var queryInsert = var queryInsert =
@"INSERT INTO Athlete (Name, Surname, KindOfSport, AthleteClassification) @"INSERT INTO Athlete (Name, Surname, KindOfSport, AthleteClassification)
VALUES (@Name, @Surname, @KindOfSport, @AthleteClassification)"; VALUES (@Name, @Surname, @KindOfSport, @AthleteClassification)";
connection.Execute(queryInsert, athlete); connection.Execute(queryInsert, athlete);
} }
catch (Exception ex) catch (Exception ex)
@ -43,18 +40,15 @@ public class AthleteRepository : IAthleteRepository
{ {
_logger.LogInformation("Редактирование объекта"); _logger.LogInformation("Редактирование объекта");
_logger.LogDebug("Объект: {json}", JsonConvert.SerializeObject(athlete)); _logger.LogDebug("Объект: {json}", JsonConvert.SerializeObject(athlete));
try try
{ {
using var connection = new NpgsqlConnection(_connectionString.ConnectionString); using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
var queryUpdate = @"UPDATE Athlete SET var queryUpdate = @"UPDATE Athlete SET
Name=@Name, Name=@Name,
Surname=@Surname, Surname=@Surname,
KindOfSport=@KindOfSport, KindOfSport=@KindOfSport,
AthleteClassification=@AthleteClassification AthleteClassification=@AthleteClassification
WHERE Id=@Id"; WHERE Id=@Id";
connection.Execute(queryUpdate, athlete); connection.Execute(queryUpdate, athlete);
} }
catch (Exception ex) catch (Exception ex)
@ -68,13 +62,10 @@ public class AthleteRepository : IAthleteRepository
{ {
_logger.LogInformation("Удаление объекта"); _logger.LogInformation("Удаление объекта");
_logger.LogDebug("Объект: {id}", id); _logger.LogDebug("Объект: {id}", id);
try try
{ {
using var connection = new NpgsqlConnection(_connectionString.ConnectionString); using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
var queryDelete = @"DELETE FROM Athlete WHERE Id=@id"; var queryDelete = @"DELETE FROM Athlete WHERE Id=@id";
connection.Execute(queryDelete, new { id }); connection.Execute(queryDelete, new { id });
} }
catch (Exception ex) catch (Exception ex)
@ -88,17 +79,12 @@ public class AthleteRepository : IAthleteRepository
{ {
_logger.LogInformation("Получение объекта по идентификатору"); _logger.LogInformation("Получение объекта по идентификатору");
_logger.LogDebug("Объект: {id}", id); _logger.LogDebug("Объект: {id}", id);
try try
{ {
using var connection = new NpgsqlConnection(_connectionString.ConnectionString); using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
var querySelect = @"SELECT * FROM Athlete WHERE Id=@id"; var querySelect = @"SELECT * FROM Athlete WHERE Id=@id";
var ahlete = connection.QueryFirst<Athlete>(querySelect, new { id }); var ahlete = connection.QueryFirst<Athlete>(querySelect, new { id });
_logger.LogDebug("Найденный объект: {json}", JsonConvert.SerializeObject(ahlete)); _logger.LogDebug("Найденный объект: {json}", JsonConvert.SerializeObject(ahlete));
return ahlete; return ahlete;
} }
catch (Exception ex) catch (Exception ex)
@ -111,17 +97,12 @@ public class AthleteRepository : IAthleteRepository
public IEnumerable<Athlete> ReadAthletes() public IEnumerable<Athlete> ReadAthletes()
{ {
_logger.LogInformation("Получение всех объектов"); _logger.LogInformation("Получение всех объектов");
try try
{ {
using var connection = new NpgsqlConnection(_connectionString.ConnectionString); using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
var querySelect = "SELECT * FROM Athlete"; var querySelect = "SELECT * FROM Athlete";
var ahletes = connection.Query<Athlete>(querySelect); var ahletes = connection.Query<Athlete>(querySelect);
_logger.LogDebug("Полученные объекты: {json}", JsonConvert.SerializeObject(ahletes)); _logger.LogDebug("Полученные объекты: {json}", JsonConvert.SerializeObject(ahletes));
return ahletes; return ahletes;
} }
catch (Exception ex) catch (Exception ex)

View File

@ -21,13 +21,10 @@ public class HotelRepository : IHotelRepository
{ {
_logger.LogInformation("Добавление объекта"); _logger.LogInformation("Добавление объекта");
_logger.LogDebug("Объект: {json}", JsonConvert.SerializeObject(hotel)); _logger.LogDebug("Объект: {json}", JsonConvert.SerializeObject(hotel));
try try
{ {
using var connection = new NpgsqlConnection(_connectionString.ConnectionString); using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
var queryInsert = @"INSERT INTO Hotel (Name) VALUES (@Name)"; var queryInsert = @"INSERT INTO Hotel (Name) VALUES (@Name)";
connection.Execute(queryInsert, hotel); connection.Execute(queryInsert, hotel);
} }
catch (Exception ex) catch (Exception ex)
@ -41,15 +38,12 @@ public class HotelRepository : IHotelRepository
{ {
_logger.LogInformation("Редактирование объекта"); _logger.LogInformation("Редактирование объекта");
_logger.LogDebug("Объект: {json}", JsonConvert.SerializeObject(hotel)); _logger.LogDebug("Объект: {json}", JsonConvert.SerializeObject(hotel));
try try
{ {
using var connection = new NpgsqlConnection(_connectionString.ConnectionString); using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
var queryUpdate = @"UPDATE Hotel SET var queryUpdate = @"UPDATE Hotel SET
Name=@Name Name=@Name
WHERE Id=@Id"; WHERE Id=@Id";
connection.Execute(queryUpdate, hotel); connection.Execute(queryUpdate, hotel);
} }
catch (Exception ex) catch (Exception ex)
@ -63,13 +57,10 @@ public class HotelRepository : IHotelRepository
{ {
_logger.LogInformation("Удаление объекта"); _logger.LogInformation("Удаление объекта");
_logger.LogDebug("Объект: {id}", id); _logger.LogDebug("Объект: {id}", id);
try try
{ {
using var connection = new NpgsqlConnection(_connectionString.ConnectionString); using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
var queryDelete = @"DELETE FROM Hotel WHERE Id=@id"; var queryDelete = @"DELETE FROM Hotel WHERE Id=@id";
connection.Execute(queryDelete, new { id }); connection.Execute(queryDelete, new { id });
} }
catch (Exception ex) catch (Exception ex)
@ -83,17 +74,12 @@ public class HotelRepository : IHotelRepository
{ {
_logger.LogInformation("Получение объекта по идентификатору"); _logger.LogInformation("Получение объекта по идентификатору");
_logger.LogDebug("Объект: {id}", id); _logger.LogDebug("Объект: {id}", id);
try try
{ {
using var connection = new NpgsqlConnection(_connectionString.ConnectionString); using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
var querySelect = @"SELECT * FROM Hotel WHERE Id=@id"; var querySelect = @"SELECT * FROM Hotel WHERE Id=@id";
var hotel = connection.QueryFirst<Hotel>(querySelect, new { id }); var hotel = connection.QueryFirst<Hotel>(querySelect, new { id });
_logger.LogDebug("Найденный объект: {json}", JsonConvert.SerializeObject(hotel)); _logger.LogDebug("Найденный объект: {json}", JsonConvert.SerializeObject(hotel));
return hotel; return hotel;
} }
catch (Exception ex) catch (Exception ex)
@ -106,17 +92,12 @@ public class HotelRepository : IHotelRepository
public IEnumerable<Hotel> ReadHotels() public IEnumerable<Hotel> ReadHotels()
{ {
_logger.LogInformation("Получение всех объектов"); _logger.LogInformation("Получение всех объектов");
try try
{ {
using var connection = new NpgsqlConnection(_connectionString.ConnectionString); using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
var querySelect = "SELECT * FROM Hotel"; var querySelect = "SELECT * FROM Hotel";
var hotels = connection.Query<Hotel>(querySelect); var hotels = connection.Query<Hotel>(querySelect);
_logger.LogDebug("Полученные объекты: {json}", JsonConvert.SerializeObject(hotels)); _logger.LogDebug("Полученные объекты: {json}", JsonConvert.SerializeObject(hotels));
return hotels; return hotels;
} }
catch (Exception ex) catch (Exception ex)

View File

@ -21,15 +21,12 @@ public class RoomRepository : IRoomRepository
{ {
_logger.LogInformation("Добавление объекта"); _logger.LogInformation("Добавление объекта");
_logger.LogDebug("Объект: {json}", JsonConvert.SerializeObject(room)); _logger.LogDebug("Объект: {json}", JsonConvert.SerializeObject(room));
try try
{ {
using var connection = new NpgsqlConnection(_connectionString.ConnectionString); using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
var queryInsert = var queryInsert =
@"INSERT INTO Room (HotelId, Name, TypeOfRoom) @"INSERT INTO Room (HotelId, Name, TypeOfRoom)
VALUES (@HotelId, @Name, @TypeOfRoom)"; VALUES (@HotelId, @Name, @TypeOfRoom)";
connection.Execute(queryInsert, room); connection.Execute(queryInsert, room);
} }
catch (Exception ex) catch (Exception ex)
@ -43,17 +40,14 @@ public class RoomRepository : IRoomRepository
{ {
_logger.LogInformation("Редактирование объекта"); _logger.LogInformation("Редактирование объекта");
_logger.LogDebug("Объект: {json}", JsonConvert.SerializeObject(room)); _logger.LogDebug("Объект: {json}", JsonConvert.SerializeObject(room));
try try
{ {
using var connection = new NpgsqlConnection(_connectionString.ConnectionString); using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
var queryUpdate = @"UPDATE Room SET var queryUpdate = @"UPDATE Room SET
HotelId=@HotelId, HotelId=@HotelId,
Name=@Name, Name=@Name,
TypeOfRoom=@TypeOfRoom TypeOfRoom=@TypeOfRoom
WHERE Id=@Id"; WHERE Id=@Id";
connection.Execute(queryUpdate, room); connection.Execute(queryUpdate, room);
} }
catch (Exception ex) catch (Exception ex)
@ -67,13 +61,10 @@ public class RoomRepository : IRoomRepository
{ {
_logger.LogInformation("Удаление объекта"); _logger.LogInformation("Удаление объекта");
_logger.LogDebug("Объект: {id}", id); _logger.LogDebug("Объект: {id}", id);
try try
{ {
using var connection = new NpgsqlConnection(_connectionString.ConnectionString); using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
var queryDelete = @"DELETE FROM Room WHERE Id=@id"; var queryDelete = @"DELETE FROM Room WHERE Id=@id";
connection.Execute(queryDelete, new { id }); connection.Execute(queryDelete, new { id });
} }
catch (Exception ex) catch (Exception ex)
@ -87,17 +78,12 @@ public class RoomRepository : IRoomRepository
{ {
_logger.LogInformation("Получение объекта по идентификатору"); _logger.LogInformation("Получение объекта по идентификатору");
_logger.LogDebug("Объект: {id}", id); _logger.LogDebug("Объект: {id}", id);
try try
{ {
using var connection = new NpgsqlConnection(_connectionString.ConnectionString); using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
var querySelect = @"SELECT * FROM Room WHERE Id=@id"; var querySelect = @"SELECT * FROM Room WHERE Id=@id";
var room = connection.QueryFirst<Room>(querySelect, new { id }); var room = connection.QueryFirst<Room>(querySelect, new { id });
_logger.LogDebug("Найденный объект: {json}", JsonConvert.SerializeObject(room)); _logger.LogDebug("Найденный объект: {json}", JsonConvert.SerializeObject(room));
return room; return room;
} }
catch (Exception ex) catch (Exception ex)
@ -110,17 +96,12 @@ public class RoomRepository : IRoomRepository
public IEnumerable<Room> ReadRooms() public IEnumerable<Room> ReadRooms()
{ {
_logger.LogInformation("Получение всех объектов"); _logger.LogInformation("Получение всех объектов");
try try
{ {
using var connection = new NpgsqlConnection(_connectionString.ConnectionString); using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
var querySelect = "SELECT * FROM Room"; var querySelect = "SELECT * FROM Room";
var rooms = connection.Query<Room>(querySelect); var rooms = connection.Query<Room>(querySelect);
_logger.LogDebug("Полученные объекты: {json}", JsonConvert.SerializeObject(rooms)); _logger.LogDebug("Полученные объекты: {json}", JsonConvert.SerializeObject(rooms));
return rooms; return rooms;
} }
catch (Exception ex) catch (Exception ex)

View File

@ -3,7 +3,6 @@ using Microsoft.Extensions.Logging;
using Newtonsoft.Json; using Newtonsoft.Json;
using Npgsql; using Npgsql;
using ProjectAthletesAccommodation.Entities; using ProjectAthletesAccommodation.Entities;
using Serilog.Core;
namespace ProjectAthletesAccommodation.Repositories.Implementations; namespace ProjectAthletesAccommodation.Repositories.Implementations;
public class ServiceProvisionRepository : IServiceProvisionRepository public class ServiceProvisionRepository : IServiceProvisionRepository
@ -23,30 +22,23 @@ public class ServiceProvisionRepository : IServiceProvisionRepository
{ {
_logger.LogInformation("Добавление объекта"); _logger.LogInformation("Добавление объекта");
_logger.LogDebug("Объект: {json}", JsonConvert.SerializeObject(serviceProvision)); _logger.LogDebug("Объект: {json}", JsonConvert.SerializeObject(serviceProvision));
try try
{ {
using var connection = new NpgsqlConnection(_connectionString.ConnectionString); using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
connection.Open(); connection.Open();
using var transaction = connection.BeginTransaction(); using var transaction = connection.BeginTransaction();
var queryInsert = var queryInsert =
@"INSERT INTO ServiceProvision (HotelId, Name, Date) @"INSERT INTO ServiceProvision (HotelId, Name, Date)
VALUES (@HotelId, @Name, @Date); VALUES (@HotelId, @Name, @Date);
SELECT MAX(Id) FROM ServiceProvision"; SELECT MAX(Id) FROM ServiceProvision";
var serviceProvisionId = connection.QueryFirst<int>(queryInsert, serviceProvision, transaction); var serviceProvisionId = connection.QueryFirst<int>(queryInsert, serviceProvision, transaction);
var querySubInsert = var querySubInsert =
@"INSERT INTO ServiceProvisionConnection (ServiceProvisionId, AthleteId, Price) @"INSERT INTO ServiceProvisionConnection (ServiceProvisionId, AthleteId, Price)
VALUES (@ServiceProvisionId, @AthleteId, @Price)"; VALUES (@ServiceProvisionId, @AthleteId, @Price)";
foreach (var elem in serviceProvision.ServiceProvisionConnection) foreach (var elem in serviceProvision.ServiceProvisionConnection)
{ {
connection.Execute(querySubInsert, new { serviceProvisionId, elem.AthleteId, elem.Price }, transaction); connection.Execute(querySubInsert, new { serviceProvisionId, elem.AthleteId, elem.Price }, transaction);
} }
transaction.Commit(); transaction.Commit();
} }
catch (Exception ex) catch (Exception ex)
@ -60,13 +52,10 @@ public class ServiceProvisionRepository : IServiceProvisionRepository
{ {
_logger.LogInformation("Удаление объекта"); _logger.LogInformation("Удаление объекта");
_logger.LogDebug("Объект: {id}", id); _logger.LogDebug("Объект: {id}", id);
try try
{ {
using var connection = new NpgsqlConnection(_connectionString.ConnectionString); using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
var queryDelete = @"DELETE FROM ServiceProvision WHERE Id=@id"; var queryDelete = @"DELETE FROM ServiceProvision WHERE Id=@id";
connection.Execute(queryDelete, new { id }); connection.Execute(queryDelete, new { id });
} }
catch (Exception ex) catch (Exception ex)
@ -80,17 +69,12 @@ public class ServiceProvisionRepository : IServiceProvisionRepository
int? hotelId = null, int? athleteId = null) int? hotelId = null, int? athleteId = 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 ServiceProvision"; var querySelect = @"SELECT * FROM ServiceProvision";
var serviceProvision = connection.Query<ServiceProvision>(querySelect); var serviceProvision = connection.Query<ServiceProvision>(querySelect);
_logger.LogDebug("Полученные объекты: {json}", JsonConvert.SerializeObject(serviceProvision)); _logger.LogDebug("Полученные объекты: {json}", JsonConvert.SerializeObject(serviceProvision));
return serviceProvision; return serviceProvision;
} }
catch (Exception ex) catch (Exception ex)