2024-07-04 11:02:45 +05:00
|
|
|
using System.Collections.Generic;
|
2021-08-10 14:35:49 +05:00
|
|
|
using System.Threading;
|
|
|
|
using System.Threading.Tasks;
|
2021-08-02 14:45:13 +05:00
|
|
|
|
2024-08-19 10:01:07 +05:00
|
|
|
namespace AsbCloudApp.Services;
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Сервис получения, добавления, изменения, удаления данных
|
|
|
|
/// </summary>
|
|
|
|
/// <typeparam name="TDto"></typeparam>
|
|
|
|
public interface ICrudRepository<TDto>
|
|
|
|
where TDto : Data.IId
|
2021-08-02 14:45:13 +05:00
|
|
|
{
|
2022-06-01 17:52:26 +05:00
|
|
|
/// <summary>
|
2024-08-19 10:01:07 +05:00
|
|
|
/// Код возврата ошибки: Id не найден в БД.
|
2022-06-01 17:52:26 +05:00
|
|
|
/// </summary>
|
2024-08-19 10:01:07 +05:00
|
|
|
public const int ErrorIdNotFound = -1;
|
2022-06-01 17:52:26 +05:00
|
|
|
|
2024-08-19 10:01:07 +05:00
|
|
|
/// <summary>
|
|
|
|
/// Получение всех записей
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="token"></param>
|
|
|
|
/// <returns>emptyList if nothing found</returns>
|
|
|
|
Task<IEnumerable<TDto>> GetAllAsync(CancellationToken token);
|
2022-06-01 17:52:26 +05:00
|
|
|
|
2024-08-19 10:01:07 +05:00
|
|
|
/// <summary>
|
|
|
|
/// Получить запись по id
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="id"></param>
|
|
|
|
/// <param name="token"></param>
|
|
|
|
/// <returns>null if not found</returns>
|
|
|
|
Task<TDto?> GetOrDefaultAsync(int id, CancellationToken token);
|
2022-06-01 17:52:26 +05:00
|
|
|
|
2022-08-01 13:55:51 +05:00
|
|
|
|
2024-08-19 10:01:07 +05:00
|
|
|
/// <summary>
|
|
|
|
/// Получить запись по id
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="id"></param>
|
|
|
|
/// <returns>null if not found</returns>
|
|
|
|
TDto? GetOrDefault(int id);
|
2022-06-06 15:43:47 +05:00
|
|
|
|
2024-08-19 10:01:07 +05:00
|
|
|
/// <summary>
|
|
|
|
/// Добавление новой записи
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="newItem"></param>
|
|
|
|
/// <param name="token"></param>
|
|
|
|
/// <returns>Id новой записи</returns>
|
|
|
|
Task<int> InsertAsync(TDto newItem, CancellationToken token);
|
2022-06-01 17:52:26 +05:00
|
|
|
|
2024-08-19 10:01:07 +05:00
|
|
|
/// <summary>
|
|
|
|
/// Добавление нескольких записей
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="newItems"></param>
|
|
|
|
/// <param name="token"></param>
|
|
|
|
/// <returns>количество добавленных</returns>
|
|
|
|
Task<int> InsertRangeAsync(IEnumerable<TDto> newItems, CancellationToken token);
|
2022-06-01 17:52:26 +05:00
|
|
|
|
2024-08-19 10:01:07 +05:00
|
|
|
/// <summary>
|
|
|
|
/// Отредактировать запись
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="item"></param>
|
|
|
|
/// <param name="token"></param>
|
|
|
|
/// <returns>если больше 0 - Id записи, если меньше 0 - код ошибки</returns>
|
|
|
|
Task<int> UpdateAsync(TDto item, CancellationToken token);
|
2022-06-01 17:52:26 +05:00
|
|
|
|
2024-08-19 10:01:07 +05:00
|
|
|
/// <summary>
|
|
|
|
/// Удалить запись
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="id"></param>
|
|
|
|
/// <param name="token"></param>
|
|
|
|
/// <returns>количество добавленных, если меньше 0 - код ошибки</returns>
|
|
|
|
Task<int> DeleteAsync(int id, CancellationToken token);
|
2021-08-02 14:45:13 +05:00
|
|
|
}
|