using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using Microsoft.EntityFrameworkCore; using PhoenixLib.DAL; using PhoenixLib.Logging; using Plugin.Database.DB; using WingsAPI.Data.Account; using WingsAPI.Data.Warehouse; namespace Plugin.Database.Warehouse { public class AccountWarehouseItemItemDao : IAccountWarehouseItemDao { private readonly IDbContextFactory _contextFactory; private readonly IMapper _mapper; public AccountWarehouseItemItemDao(IDbContextFactory contextFactory, IMapper mapper) { _contextFactory = contextFactory; _mapper = mapper; } public async Task SaveAsync(IReadOnlyList objs) { try { IEnumerable entities = _mapper.Map(objs); await using GameContext context = _contextFactory.CreateDbContext(); await context.AccountWarehouseItems.BulkMergeAsync(entities); return await context.SaveChangesAsync(); } catch (Exception e) { Log.Error("[ACCOUNT_WAREHOUSE_ITEM_DAO][SAVE_ASYNC] ", e); throw; } } public async Task DeleteAsync(IEnumerable objs) { try { IEnumerable entities = _mapper.Map(objs); await using GameContext context = _contextFactory.CreateDbContext(); await context.AccountWarehouseItems.BulkDeleteAsync(entities); return await context.SaveChangesAsync(); } catch (Exception e) { Log.Error("[ACCOUNT_WAREHOUSE_ITEM_DAO][DELETE_ASYNC] ", e); throw; } } public async Task> GetByAccountIdAsync(long accountId) { try { await using GameContext context = _contextFactory.CreateDbContext(); IEnumerable items = await context.AccountWarehouseItems.Where(s => s.AccountId == accountId).ToListAsync(); return _mapper.Map(items); } catch (Exception e) { Log.Error("[ACCOUNT_WAREHOUSE_ITEM_DAO][GET_BY_FAMILY_ID_ASYNC] ", e); throw; } } } }