public async Task <List <PersistKeyedData> > SetPersistKeyedData([FromBody] SetDataRequest request)
        {
            List <PersistKeyedData> inserted_data = new List <PersistKeyedData>();
            //update existing
            var lookup = new PersistKeyedDataLookup();

            lookup.gameLookup    = request.gameLookup;
            lookup.profileLookup = request.profileLookup;
            lookup.persistType   = request.persistType;
            lookup.dataIndex     = request.dataIndex;
            lookup.keys          = new List <string>();

            //find keys to be deleted
            foreach (var key in request.keyValueList)
            {
                if (key.Value == null || key.Value.Length == 0)
                {
                    lookup.keys.Add(key.Key);
                }
            }
            await persistKeyedRepository.Delete(lookup);

            lookup.keys.Clear();

            //find existing keys
            foreach (var key in request.keyValueList)
            {
                lookup.keys.Add(key.Key);
            }
            var found_keys = await persistKeyedRepository.Lookup(lookup);

            foreach (var found_key in found_keys)
            {
                found_key.Modified = DateTime.UtcNow;
                found_key.KeyValue = Convert.FromBase64String(request.keyValueList[found_key.KeyName]);
                inserted_data.Add(await persistKeyedRepository.Update(found_key));
                request.keyValueList.Remove(found_key.KeyName);
            }

            //create new
            foreach (var kvData in request.keyValueList)
            {
                var data = new PersistKeyedData();
                data.KeyName     = kvData.Key;
                data.KeyValue    = Convert.FromBase64String(kvData.Value);
                data.Modified    = DateTime.UtcNow;
                data.DataIndex   = request.dataIndex;
                data.PersistType = request.persistType;

                var game    = (await gameRepository.Lookup(request.gameLookup)).FirstOrDefault();
                var profile = (await profileRepository.Lookup(request.profileLookup)).FirstOrDefault();
                data.Gameid    = game.Id;
                data.Profileid = profile.Id;
                inserted_data.Add(await persistKeyedRepository.Create(data));
            }
            return(inserted_data);
        }
        public async Task <PersistData> SetPersistData([FromBody] SetDataRequest request)
        {
            var game = (await gameRepository.Lookup(request.gameLookup)).FirstOrDefault();

            if (game == null)
            {
                throw new ArgumentException();
            }
            var profile = (await profileRepository.Lookup(request.profileLookup)).FirstOrDefault();

            if (profile == null)
            {
                throw new NoSuchUserException();
            }

            var lookup = new PersistDataLookup();

            lookup.profileLookup = request.profileLookup;
            lookup.gameLookup    = request.gameLookup;
            lookup.DataIndex     = request.dataIndex;
            lookup.PersistType   = request.persistType;

            //delete request
            PersistData data_entry = null;

            if (request.base64Data.Length == 0)
            {
                bool success = await persistRepository.Delete(lookup);

                //if(success)
                {
                    var data = new PersistData();
                    data.Modified = DateTime.UtcNow;
                    data.Profile  = profile;
                    return(data);
                }
            }
            else
            {
                data_entry = (await persistRepository.Lookup(lookup)).FirstOrDefault();
                if (data_entry != null)
                {
                    data_entry.Base64Data = Convert.FromBase64String(request.base64Data);
                    return(await persistRepository.Update(data_entry));
                }
                else
                {
                    var data = new PersistData();
                    data.Base64Data  = Convert.FromBase64String(request.base64Data);
                    data.DataIndex   = request.dataIndex;
                    data.PersistType = request.persistType;
                    data.Profileid   = profile.Id;
                    data.Gameid      = game.Id;
                    return(await persistRepository.Create(data));
                }
            }
        }