DD.WellWorkover.Cloud/AsbCloudInfrastructure/Services/FileCategoryService.cs

50 lines
1.6 KiB
C#
Raw Normal View History

using AsbCloudApp.Data;
using AsbCloudApp.Services;
using AsbCloudDb.Model;
using AsbCloudInfrastructure.Repository;
using DocumentFormat.OpenXml.InkML;
using Microsoft.EntityFrameworkCore;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
namespace AsbCloudInfrastructure.Services
{
public class FileCategoryService : CrudCacheServiceBase<FileCategoryDto, FileCategory>, IFileCategoryService
{
private readonly IAsbCloudDbContext db;
public FileCategoryService(IAsbCloudDbContext context)
: base(context)
{
this.db = context;
}
public async Task<IEnumerable<FileCategoryDto>> GetWellCategoryAsync(CancellationToken token)
{
var data = await (from category in db.FileCategories
where category.Id >= 10000 && category.Id <= 20000
select new FileCategoryDto
{
Id = category.Id,
Name = category.Name,
ShortName = category.ShortName
})
.ToListAsync(token)
.ConfigureAwait(false);
return data.ToList();
}
public override async Task<FileCategoryDto> GetOrDefaultAsync(int id, CancellationToken token)
{
var entity = await db.FileCategories
.FirstOrDefaultAsync(x => x.Id == id)
.ConfigureAwait(false);
var dto = Convert(entity);
return dto;
}
}
}