using DysonNetwork.Shared.Models; using DysonNetwork.Shared.Services; using Microsoft.EntityFrameworkCore; using MagicOnion.Server; namespace DysonNetwork.Pass.Account; public class AccountProfileService(AppDatabase db) : ServiceBase, IAccountProfileService { public async Task GetAccountProfileByIdAsync(Guid accountId) { return await db.AccountProfiles.FirstOrDefaultAsync(p => p.AccountId == accountId); } public async Task UpdateStellarMembershipAsync(Guid accountId, SubscriptionReferenceObject? subscription) { var profile = await db.AccountProfiles.FirstOrDefaultAsync(p => p.AccountId == accountId); if (profile == null) { profile = new Profile { AccountId = accountId }; db.AccountProfiles.Add(profile); } profile.StellarMembership = subscription; await db.SaveChangesAsync(); return profile; } public async Task> GetAccountsWithStellarMembershipAsync() { return await db.AccountProfiles .Where(a => a.StellarMembership != null) .ToListAsync(); } public async Task ClearStellarMembershipsAsync(List accountIds) { return await db.AccountProfiles .Where(a => accountIds.Contains(a.Id)) .ExecuteUpdateAsync(s => s .SetProperty(a => a.StellarMembership, p => null) ); } public async Task UpdateProfilePictureAsync(Guid accountId, CloudFileReferenceObject? picture) { var profile = await db.AccountProfiles.FirstOrDefaultAsync(p => p.AccountId == accountId); if (profile == null) { profile = new Profile { AccountId = accountId }; db.AccountProfiles.Add(profile); } profile.Picture = picture; await db.SaveChangesAsync(); return profile; } public async Task UpdateProfileBackgroundAsync(Guid accountId, CloudFileReferenceObject? background) { var profile = await db.AccountProfiles.FirstOrDefaultAsync(p => p.AccountId == accountId); if (profile == null) { profile = new Profile { AccountId = accountId }; db.AccountProfiles.Add(profile); } profile.Background = background; await db.SaveChangesAsync(); return profile; } }