コード例 #1
0
        public async Task <IActionResult> Post(ExchangeKeyToCreateDTO key)
        {
            try
            {
                key.Key    = _javaScriptEncoder.Encode(key.Key);
                key.Secret = _javaScriptEncoder.Encode(key.Secret);

                if (key.Name != "BitMEX" && key.Name != "Binance")
                {
                    return(StatusCode(400, "Name must have one of the following values: BitMEX, Binance"));
                }
                int userId = Int32.Parse(this.User.FindFirstValue(ClaimTypes.NameIdentifier));

                if (await _keyService.KeyExists(key.Name, key.Key, userId))
                {
                    return(StatusCode(400, "Duplicate key"));
                }

                bool created = await _keyService.CreateExchangeKey(key, userId);

                if (created)
                {
                    return(StatusCode(200));
                }
                return(StatusCode(500, "Falied to save key"));
            }
            catch
            {
                return(StatusCode(500, "Something went wrong while attempting to create a key"));
            }
        }
コード例 #2
0
        private ExchangeKey ConvertExchangeKeyToCreate(ExchangeKeyToCreateDTO dto)
        {
            var key = new ExchangeKey
            {
                Name   = dto.Name,
                Key    = dto.Key,
                Secret = dto.Secret
            };

            return(key);
        }
コード例 #3
0
        public async Task <bool> CreateExchangeKey(ExchangeKeyToCreateDTO key, int userId)
        {
            try
            {
                var keyToCreate = ConvertExchangeKeyToCreate(key);
                keyToCreate.UserId = userId;

                await _genericRepo.AddAsync(keyToCreate);

                return(true);
            }
            catch
            {
                return(false);
            }
        }