예제 #1
0
        public async Task SaveCharacterSlotAsync(NetUserId userId, ICharacterProfile?profile, int slot)
        {
            await using var db = await GetDb();

            if (profile is null)
            {
                await DeleteCharacterSlot(db.DbContext, userId, slot);

                await db.DbContext.SaveChangesAsync();

                return;
            }

            if (profile is not HumanoidCharacterProfile humanoid)
            {
                // TODO: Handle other ICharacterProfile implementations properly
                throw new NotImplementedException();
            }

            var entity = ConvertProfiles(humanoid, slot);

            var prefs = await db.DbContext
                        .Preference
                        .Include(p => p.Profiles)
                        .SingleAsync(p => p.UserId == userId.UserId);

            var oldProfile = prefs
                             .Profiles
                             .SingleOrDefault(h => h.Slot == entity.Slot);

            if (oldProfile is not null)
            {
                prefs.Profiles.Remove(oldProfile);
            }

            prefs.Profiles.Add(entity);
            await db.DbContext.SaveChangesAsync();
        }
 public Task SaveCharacterSlotAsync(NetUserId userId, ICharacterProfile?profile, int slot)
 {
     return(_db.SaveCharacterSlotAsync(userId, profile, slot));
 }