Ejemplo n.º 1
0
        public async Task <CDKeySuccessResponse> TestCDKeyValid([FromBody] GetProfileByCDKeyRequest request)
        {
            var resp = new CDKeySuccessResponse();

            var game = (await gameRepository.Lookup(request.gameLookup)).FirstOrDefault();

            if (game == null)
            {
                throw new ArgumentException();
            }

            var lookupRequest = new CdKeyLookup();

            lookupRequest.Cdkey  = request.cdkey;
            lookupRequest.Gameid = game.Id;

            var failIfNotFound = await cdkeyRepository.LookupFailItNotFound(lookupRequest);

            if (failIfNotFound == false)
            {
                resp.success = true;
                return(resp);
            }

            var keys = await cdkeyRepository.Lookup(lookupRequest);

            resp.success = keys.Count() > 0;
            return(resp);
        }
Ejemplo n.º 2
0
        public async Task <CDKeySuccessResponse> AssociateCDKeyToProfile([FromBody] CDKeyAssociateRequest request)
        {
            var profile = (await profileRepository.Lookup(request.profileLookup)).FirstOrDefault();

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

            var game = (await gameRepository.Lookup(request.gameLookup)).FirstOrDefault();

            if (game == null)
            {
                throw new ArgumentException();
            }


            var profileCdKeyLookup = new CdKeyLookup();

            profileCdKeyLookup.Gameid        = game.Id;
            profileCdKeyLookup.profileLookup = request.profileLookup;

            var cdKeyData = await cdkeyRepository.LookupCDKeyFromProfile(profileCdKeyLookup);

            if (cdKeyData != null)
            {
                throw new CdKeyAlreadySetException();
            }

            var cdkeyLookup = new CdKeyLookup();

            cdkeyLookup.Cdkey  = request.cdkey;
            cdkeyLookup.Gameid = game.Id;

            var resp = new CDKeySuccessResponse();

            resp.success = await cdkeyRepository.AssociateCDKeyToProfile(cdkeyLookup, profile);

            return(resp);
        }