72 lines
2.4 KiB
C#
72 lines
2.4 KiB
C#
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>, IAccountProfileService
|
|
{
|
|
public async Task<Profile?> GetAccountProfileByIdAsync(Guid accountId)
|
|
{
|
|
return await db.AccountProfiles.FirstOrDefaultAsync(p => p.AccountId == accountId);
|
|
}
|
|
|
|
public async Task<Profile> 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<List<Profile>> GetAccountsWithStellarMembershipAsync()
|
|
{
|
|
return await db.AccountProfiles
|
|
.Where(a => a.StellarMembership != null)
|
|
.ToListAsync();
|
|
}
|
|
|
|
public async Task<int> ClearStellarMembershipsAsync(List<Guid> accountIds)
|
|
{
|
|
return await db.AccountProfiles
|
|
.Where(a => accountIds.Contains(a.Id))
|
|
.ExecuteUpdateAsync(s => s
|
|
.SetProperty(a => a.StellarMembership, p => null)
|
|
);
|
|
}
|
|
|
|
public async Task<Profile> 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<Profile> 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;
|
|
}
|
|
} |