Чистка лишних пустых строк
This commit is contained in:
parent
745617d8b5
commit
570615e48a
@ -22,15 +22,12 @@ public class AthleteAccommodationRepository : IAthleteAccommodationRepository
|
||||
{
|
||||
_logger.LogInformation("Добавление объекта");
|
||||
_logger.LogDebug("Объект: {json}", JsonConvert.SerializeObject(athleteAccommodation));
|
||||
|
||||
try
|
||||
{
|
||||
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||
|
||||
var queryInsert =
|
||||
@"INSERT INTO AthleteAccommodation (RoomId, AthleteId, DateStart, DateEnd)
|
||||
VALUES (@RoomId, @AthleteId, @DateStart, @DateEnd)";
|
||||
|
||||
connection.Execute(queryInsert, athleteAccommodation);
|
||||
}
|
||||
catch (Exception ex)
|
||||
@ -44,13 +41,10 @@ public class AthleteAccommodationRepository : IAthleteAccommodationRepository
|
||||
{
|
||||
_logger.LogInformation("Удаление объекта");
|
||||
_logger.LogDebug("Объект: {id}", id);
|
||||
|
||||
try
|
||||
{
|
||||
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||
|
||||
var queryDelete = @"DELETE FROM AthleteAccommodation WHERE Id=@id";
|
||||
|
||||
connection.Execute(queryDelete, new { id });
|
||||
}
|
||||
catch (Exception ex)
|
||||
@ -64,17 +58,12 @@ public class AthleteAccommodationRepository : IAthleteAccommodationRepository
|
||||
int? roomId = null, int? athleteId = null)
|
||||
{
|
||||
_logger.LogInformation("Получение всех объектов");
|
||||
|
||||
try
|
||||
{
|
||||
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||
|
||||
var querySelect = "SELECT * FROM AthleteAccommodation";
|
||||
|
||||
var athleteAccommodation = connection.Query<AthleteAccommodation>(querySelect);
|
||||
|
||||
_logger.LogDebug("Полученные объекты: {json}", JsonConvert.SerializeObject(athleteAccommodation));
|
||||
|
||||
return athleteAccommodation;
|
||||
}
|
||||
catch (Exception ex)
|
||||
|
@ -21,15 +21,12 @@ public class AthleteRepository : IAthleteRepository
|
||||
{
|
||||
_logger.LogInformation("Добавление объекта");
|
||||
_logger.LogDebug("Объект: {json}", JsonConvert.SerializeObject(athlete));
|
||||
|
||||
try
|
||||
{
|
||||
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||
|
||||
var queryInsert =
|
||||
@"INSERT INTO Athlete (Name, Surname, KindOfSport, AthleteClassification)
|
||||
VALUES (@Name, @Surname, @KindOfSport, @AthleteClassification)";
|
||||
|
||||
connection.Execute(queryInsert, athlete);
|
||||
}
|
||||
catch (Exception ex)
|
||||
@ -43,18 +40,15 @@ public class AthleteRepository : IAthleteRepository
|
||||
{
|
||||
_logger.LogInformation("Редактирование объекта");
|
||||
_logger.LogDebug("Объект: {json}", JsonConvert.SerializeObject(athlete));
|
||||
|
||||
try
|
||||
{
|
||||
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||
|
||||
var queryUpdate = @"UPDATE Athlete SET
|
||||
Name=@Name,
|
||||
Surname=@Surname,
|
||||
KindOfSport=@KindOfSport,
|
||||
AthleteClassification=@AthleteClassification
|
||||
WHERE Id=@Id";
|
||||
|
||||
connection.Execute(queryUpdate, athlete);
|
||||
}
|
||||
catch (Exception ex)
|
||||
@ -68,13 +62,10 @@ public class AthleteRepository : IAthleteRepository
|
||||
{
|
||||
_logger.LogInformation("Удаление объекта");
|
||||
_logger.LogDebug("Объект: {id}", id);
|
||||
|
||||
try
|
||||
{
|
||||
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||
|
||||
var queryDelete = @"DELETE FROM Athlete WHERE Id=@id";
|
||||
|
||||
connection.Execute(queryDelete, new { id });
|
||||
}
|
||||
catch (Exception ex)
|
||||
@ -88,17 +79,12 @@ public class AthleteRepository : IAthleteRepository
|
||||
{
|
||||
_logger.LogInformation("Получение объекта по идентификатору");
|
||||
_logger.LogDebug("Объект: {id}", id);
|
||||
|
||||
try
|
||||
{
|
||||
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||
|
||||
var querySelect = @"SELECT * FROM Athlete WHERE Id=@id";
|
||||
|
||||
var ahlete = connection.QueryFirst<Athlete>(querySelect, new { id });
|
||||
|
||||
_logger.LogDebug("Найденный объект: {json}", JsonConvert.SerializeObject(ahlete));
|
||||
|
||||
return ahlete;
|
||||
}
|
||||
catch (Exception ex)
|
||||
@ -111,17 +97,12 @@ public class AthleteRepository : IAthleteRepository
|
||||
public IEnumerable<Athlete> ReadAthletes()
|
||||
{
|
||||
_logger.LogInformation("Получение всех объектов");
|
||||
|
||||
try
|
||||
{
|
||||
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||
|
||||
var querySelect = "SELECT * FROM Athlete";
|
||||
|
||||
var ahletes = connection.Query<Athlete>(querySelect);
|
||||
|
||||
_logger.LogDebug("Полученные объекты: {json}", JsonConvert.SerializeObject(ahletes));
|
||||
|
||||
return ahletes;
|
||||
}
|
||||
catch (Exception ex)
|
||||
|
@ -21,13 +21,10 @@ public class HotelRepository : IHotelRepository
|
||||
{
|
||||
_logger.LogInformation("Добавление объекта");
|
||||
_logger.LogDebug("Объект: {json}", JsonConvert.SerializeObject(hotel));
|
||||
|
||||
try
|
||||
{
|
||||
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||
|
||||
var queryInsert = @"INSERT INTO Hotel (Name) VALUES (@Name)";
|
||||
|
||||
connection.Execute(queryInsert, hotel);
|
||||
}
|
||||
catch (Exception ex)
|
||||
@ -41,15 +38,12 @@ public class HotelRepository : IHotelRepository
|
||||
{
|
||||
_logger.LogInformation("Редактирование объекта");
|
||||
_logger.LogDebug("Объект: {json}", JsonConvert.SerializeObject(hotel));
|
||||
|
||||
try
|
||||
{
|
||||
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||
|
||||
var queryUpdate = @"UPDATE Hotel SET
|
||||
Name=@Name
|
||||
WHERE Id=@Id";
|
||||
|
||||
connection.Execute(queryUpdate, hotel);
|
||||
}
|
||||
catch (Exception ex)
|
||||
@ -63,13 +57,10 @@ public class HotelRepository : IHotelRepository
|
||||
{
|
||||
_logger.LogInformation("Удаление объекта");
|
||||
_logger.LogDebug("Объект: {id}", id);
|
||||
|
||||
try
|
||||
{
|
||||
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||
|
||||
var queryDelete = @"DELETE FROM Hotel WHERE Id=@id";
|
||||
|
||||
connection.Execute(queryDelete, new { id });
|
||||
}
|
||||
catch (Exception ex)
|
||||
@ -83,17 +74,12 @@ public class HotelRepository : IHotelRepository
|
||||
{
|
||||
_logger.LogInformation("Получение объекта по идентификатору");
|
||||
_logger.LogDebug("Объект: {id}", id);
|
||||
|
||||
try
|
||||
{
|
||||
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||
|
||||
var querySelect = @"SELECT * FROM Hotel WHERE Id=@id";
|
||||
|
||||
var hotel = connection.QueryFirst<Hotel>(querySelect, new { id });
|
||||
|
||||
_logger.LogDebug("Найденный объект: {json}", JsonConvert.SerializeObject(hotel));
|
||||
|
||||
return hotel;
|
||||
}
|
||||
catch (Exception ex)
|
||||
@ -106,17 +92,12 @@ public class HotelRepository : IHotelRepository
|
||||
public IEnumerable<Hotel> ReadHotels()
|
||||
{
|
||||
_logger.LogInformation("Получение всех объектов");
|
||||
|
||||
try
|
||||
{
|
||||
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||
|
||||
var querySelect = "SELECT * FROM Hotel";
|
||||
|
||||
var hotels = connection.Query<Hotel>(querySelect);
|
||||
|
||||
_logger.LogDebug("Полученные объекты: {json}", JsonConvert.SerializeObject(hotels));
|
||||
|
||||
return hotels;
|
||||
}
|
||||
catch (Exception ex)
|
||||
|
@ -21,15 +21,12 @@ public class RoomRepository : IRoomRepository
|
||||
{
|
||||
_logger.LogInformation("Добавление объекта");
|
||||
_logger.LogDebug("Объект: {json}", JsonConvert.SerializeObject(room));
|
||||
|
||||
try
|
||||
{
|
||||
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||
|
||||
var queryInsert =
|
||||
@"INSERT INTO Room (HotelId, Name, TypeOfRoom)
|
||||
VALUES (@HotelId, @Name, @TypeOfRoom)";
|
||||
|
||||
connection.Execute(queryInsert, room);
|
||||
}
|
||||
catch (Exception ex)
|
||||
@ -43,17 +40,14 @@ public class RoomRepository : IRoomRepository
|
||||
{
|
||||
_logger.LogInformation("Редактирование объекта");
|
||||
_logger.LogDebug("Объект: {json}", JsonConvert.SerializeObject(room));
|
||||
|
||||
try
|
||||
{
|
||||
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||
|
||||
var queryUpdate = @"UPDATE Room SET
|
||||
HotelId=@HotelId,
|
||||
Name=@Name,
|
||||
TypeOfRoom=@TypeOfRoom
|
||||
WHERE Id=@Id";
|
||||
|
||||
connection.Execute(queryUpdate, room);
|
||||
}
|
||||
catch (Exception ex)
|
||||
@ -67,13 +61,10 @@ public class RoomRepository : IRoomRepository
|
||||
{
|
||||
_logger.LogInformation("Удаление объекта");
|
||||
_logger.LogDebug("Объект: {id}", id);
|
||||
|
||||
try
|
||||
{
|
||||
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||
|
||||
var queryDelete = @"DELETE FROM Room WHERE Id=@id";
|
||||
|
||||
connection.Execute(queryDelete, new { id });
|
||||
}
|
||||
catch (Exception ex)
|
||||
@ -87,17 +78,12 @@ public class RoomRepository : IRoomRepository
|
||||
{
|
||||
_logger.LogInformation("Получение объекта по идентификатору");
|
||||
_logger.LogDebug("Объект: {id}", id);
|
||||
|
||||
try
|
||||
{
|
||||
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||
|
||||
var querySelect = @"SELECT * FROM Room WHERE Id=@id";
|
||||
|
||||
var room = connection.QueryFirst<Room>(querySelect, new { id });
|
||||
|
||||
_logger.LogDebug("Найденный объект: {json}", JsonConvert.SerializeObject(room));
|
||||
|
||||
return room;
|
||||
}
|
||||
catch (Exception ex)
|
||||
@ -110,17 +96,12 @@ public class RoomRepository : IRoomRepository
|
||||
public IEnumerable<Room> ReadRooms()
|
||||
{
|
||||
_logger.LogInformation("Получение всех объектов");
|
||||
|
||||
try
|
||||
{
|
||||
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||
|
||||
var querySelect = "SELECT * FROM Room";
|
||||
|
||||
var rooms = connection.Query<Room>(querySelect);
|
||||
|
||||
_logger.LogDebug("Полученные объекты: {json}", JsonConvert.SerializeObject(rooms));
|
||||
|
||||
return rooms;
|
||||
}
|
||||
catch (Exception ex)
|
||||
|
@ -3,7 +3,6 @@ using Microsoft.Extensions.Logging;
|
||||
using Newtonsoft.Json;
|
||||
using Npgsql;
|
||||
using ProjectAthletesAccommodation.Entities;
|
||||
using Serilog.Core;
|
||||
namespace ProjectAthletesAccommodation.Repositories.Implementations;
|
||||
|
||||
public class ServiceProvisionRepository : IServiceProvisionRepository
|
||||
@ -23,30 +22,23 @@ public class ServiceProvisionRepository : IServiceProvisionRepository
|
||||
{
|
||||
_logger.LogInformation("Добавление объекта");
|
||||
_logger.LogDebug("Объект: {json}", JsonConvert.SerializeObject(serviceProvision));
|
||||
|
||||
try
|
||||
{
|
||||
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||
connection.Open();
|
||||
|
||||
using var transaction = connection.BeginTransaction();
|
||||
|
||||
var queryInsert =
|
||||
@"INSERT INTO ServiceProvision (HotelId, Name, Date)
|
||||
VALUES (@HotelId, @Name, @Date);
|
||||
SELECT MAX(Id) FROM ServiceProvision";
|
||||
|
||||
var serviceProvisionId = connection.QueryFirst<int>(queryInsert, serviceProvision, transaction);
|
||||
|
||||
var querySubInsert =
|
||||
@"INSERT INTO ServiceProvisionConnection (ServiceProvisionId, AthleteId, Price)
|
||||
VALUES (@ServiceProvisionId, @AthleteId, @Price)";
|
||||
|
||||
foreach (var elem in serviceProvision.ServiceProvisionConnection)
|
||||
{
|
||||
connection.Execute(querySubInsert, new { serviceProvisionId, elem.AthleteId, elem.Price }, transaction);
|
||||
}
|
||||
|
||||
transaction.Commit();
|
||||
}
|
||||
catch (Exception ex)
|
||||
@ -60,13 +52,10 @@ public class ServiceProvisionRepository : IServiceProvisionRepository
|
||||
{
|
||||
_logger.LogInformation("Удаление объекта");
|
||||
_logger.LogDebug("Объект: {id}", id);
|
||||
|
||||
try
|
||||
{
|
||||
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||
|
||||
var queryDelete = @"DELETE FROM ServiceProvision WHERE Id=@id";
|
||||
|
||||
connection.Execute(queryDelete, new { id });
|
||||
}
|
||||
catch (Exception ex)
|
||||
@ -80,17 +69,12 @@ public class ServiceProvisionRepository : IServiceProvisionRepository
|
||||
int? hotelId = null, int? athleteId = null)
|
||||
{
|
||||
_logger.LogInformation("Получение всех объектов");
|
||||
|
||||
try
|
||||
{
|
||||
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||
|
||||
var querySelect = @"SELECT * FROM ServiceProvision";
|
||||
|
||||
var serviceProvision = connection.Query<ServiceProvision>(querySelect);
|
||||
|
||||
_logger.LogDebug("Полученные объекты: {json}", JsonConvert.SerializeObject(serviceProvision));
|
||||
|
||||
return serviceProvision;
|
||||
}
|
||||
catch (Exception ex)
|
||||
|
Loading…
x
Reference in New Issue
Block a user