// WingsEmu // // Developed by NosWings Team using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using Microsoft.EntityFrameworkCore; using PhoenixLib.DAL; using Plugin.Database.DB; using WingsEmu.DTOs.Mails; namespace Plugin.Database.Mail { public class CharacterMailDao : ICharacterMailDao { private readonly IDbContextFactory _contextFactory; private readonly IMapper _mapper; private readonly IGenericAsyncLongRepository _repository; public CharacterMailDao(IMapper mapper, IDbContextFactory contextFactory, IGenericAsyncLongRepository repository) { _mapper = mapper; _contextFactory = contextFactory; _repository = repository; } public async Task> GetByCharacterIdAsync(long characterId) { await using GameContext context = _contextFactory.CreateDbContext(); List mails = await context.Mail.Where(s => s.ReceiverId == characterId).ToListAsync(); return _mapper.Map(mails); } public async Task> GetAllAsync() => await _repository.GetAllAsync(); public async Task GetByIdAsync(long id) => await _repository.GetByIdAsync(id); public async Task> GetByIdsAsync(IEnumerable ids) => await _repository.GetByIdsAsync(ids); public async Task SaveAsync(CharacterMailDto obj) => await _repository.SaveAsync(obj); public async Task> SaveAsync(IReadOnlyList objs) => await _repository.SaveAsync(objs); public async Task DeleteByIdAsync(long id) { await _repository.DeleteByIdAsync(id); } public async Task DeleteByIdsAsync(IEnumerable ids) { await _repository.DeleteByIdsAsync(ids); } } }