using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using Microsoft.EntityFrameworkCore; using PhoenixLib.Logging; using Plugin.Database.DB; using WingsAPI.Data.Families; namespace Plugin.Database.Families { public class FamilyWarehouseLogDao : IFamilyWarehouseLogDao { private readonly IDbContextFactory _contextFactory; public FamilyWarehouseLogDao(IDbContextFactory contextFactory) => _contextFactory = contextFactory; public async Task SaveAsync(long familyId, IEnumerable objs) { try { await using GameContext context = _contextFactory.CreateDbContext(); await context.FamilyWarehouseLogs.SingleMergeAsync(new FamilyWarehouseLogEntity { FamilyId = familyId, LogEntries = objs.ToList() }); return await context.SaveChangesAsync(); } catch (Exception e) { Log.Error("[FAMILY_WAREHOUSE_LOG_DAO][SAVE_ASYNC] ", e); throw; } } public async Task> GetByFamilyIdAsync(long familyId) { try { await using GameContext context = _contextFactory.CreateDbContext(); FamilyWarehouseLogEntity logs = await context.FamilyWarehouseLogs.FindAsync(familyId); return logs?.LogEntries; } catch (Exception e) { Log.Error("[FAMILY_WAREHOUSE_LOG_DAO][GET_BY_FAMILY_ID_ASYNC] ", e); throw; } } } }