|
|
@ -1,5 +1,6 @@ |
|
|
|
using System; |
|
|
|
using System.Collections.Generic; |
|
|
|
using System.Linq; |
|
|
|
using System.Threading.Tasks; |
|
|
|
using Microsoft.AspNetCore.Authorization; |
|
|
|
using Microsoft.AspNetCore.Mvc; |
|
|
@ -38,10 +39,12 @@ public class SfsLabelAppServiceWithCodeBase<TEntity, TEntityDto, TRequestDTO, TC |
|
|
|
[HttpGet("by-code/{code}")] |
|
|
|
public virtual async Task<TEntityDto> GetByCodeAsync(string code) |
|
|
|
{ |
|
|
|
var dto = await Cache.GetOrAddItemAsync( |
|
|
|
$"{typeof(TEntityDto).Name}:{code}".ToString(), |
|
|
|
async () => await GetFromRepositoryAsync(code).ConfigureAwait(false), |
|
|
|
SfsCacheConst.SeveralMinutes).ConfigureAwait(false); |
|
|
|
// var dto = await Cache.GetOrAddItemAsync(
|
|
|
|
// $"{typeof(TEntityDto).Name}:{code}".ToString(),
|
|
|
|
// async () => await GetFromRepositoryAsync(code).ConfigureAwait(false),
|
|
|
|
// SfsCacheConst.SeveralMinutes).ConfigureAwait(false);
|
|
|
|
|
|
|
|
var dto = await GetFromRepositoryAsync(code).ConfigureAwait(false); |
|
|
|
|
|
|
|
return dto; |
|
|
|
} |
|
|
@ -50,18 +53,22 @@ public class SfsLabelAppServiceWithCodeBase<TEntity, TEntityDto, TRequestDTO, TC |
|
|
|
[HttpPost("by-codes")] |
|
|
|
public virtual async Task<List<TEntityDto>> GetByCodesAsync(IEnumerable<string> codes) |
|
|
|
{ |
|
|
|
var dtoList = new List<TEntityDto>(); |
|
|
|
foreach (var code in codes) |
|
|
|
{ |
|
|
|
var dto = await Cache.GetOrAddItemAsync( |
|
|
|
$"{typeof(TEntityDto).Name}:{code}".ToString(), |
|
|
|
async () => await GetFromRepositoryAsync(code).ConfigureAwait(false), |
|
|
|
SfsCacheConst.SeveralMinutes).ConfigureAwait(false); |
|
|
|
if (dto != null) |
|
|
|
{ |
|
|
|
dtoList.Add(dto); |
|
|
|
} |
|
|
|
} |
|
|
|
// var dtoList = new List<TEntityDto>();
|
|
|
|
// foreach (var code in codes)
|
|
|
|
// {
|
|
|
|
// var dto = await Cache.GetOrAddItemAsync(
|
|
|
|
// $"{typeof(TEntityDto).Name}:{code}".ToString(),
|
|
|
|
// async () => await GetFromRepositoryAsync(code).ConfigureAwait(false),
|
|
|
|
// SfsCacheConst.SeveralMinutes).ConfigureAwait(false);
|
|
|
|
// if (dto != null)
|
|
|
|
// {
|
|
|
|
// dtoList.Add(dto);
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// return dtoList;
|
|
|
|
|
|
|
|
var entities = await _repository.GetListAsync(p => codes.Contains(p.Code)).ConfigureAwait(false); |
|
|
|
var dtoList = ObjectMapper.Map<List<TEntity>, List<TEntityDto>>(entities); |
|
|
|
return dtoList; |
|
|
|
} |
|
|
|
|
|
|
|