public HttpResponseMessage TestKeys(SetKeysViewModel ViewModel)
 {
     try
     {
         if (ViewModel == null)
         {
             return(Request.CreateResponse(HttpStatusCode.NotAcceptable, "Campos Inválidos", "text/plain"));
         }
         if (ModelState.IsValid)
         {
             var BinanceResult = BinanceRestApi.GetAccountInformation(ViewModel.binanceKey, ViewModel.binanceSecret);
             if (BinanceResult.IsSuccessStatusCode)
             {
                 return(Request.CreateResponse(HttpStatusCode.OK));
             }
             else
             {
                 var BinanceerrorObj = Helper.GetBinanceErrorObj(BinanceResult);
                 return(Request.CreateResponse(HttpStatusCode.BadRequest, BinanceerrorObj));
             }
         }
         var modelstateError = ModelStateErrors.DisplayModelStateError(ModelState);
         return(Request.CreateResponse(HttpStatusCode.NotAcceptable, modelstateError, "text/plain"));
     }
     catch (Exception ex)
     {
         return(Request.CreateResponse(HttpStatusCode.InternalServerError, ex.Message));
     }
 }
        public MyJsonResult TestKey(SetKeysViewModel ViewModel)
        {
            var         token = Session["token"].ToString();
            HttpContent form  = new FormUrlEncodedContent(new[]
            {
                new KeyValuePair <string, string>("binanceKey", ViewModel.binanceKey),
                new KeyValuePair <string, string>("binanceSecret", ViewModel.binanceSecret)
            });
            var res = ApiUsuario.BinanceTestKeys(form, token);

            if (res.IsSuccessStatusCode)
            {
                return(new MyJsonResult(true, JsonRequestBehavior.AllowGet));
            }

            var resObj = res.Content.ReadAsStringAsync().Result;

            Response.TrySkipIisCustomErrors = true;
            Response.StatusCode             = (int)res.StatusCode;
            return(new MyJsonResult(resObj, JsonRequestBehavior.AllowGet));
        }
 /// <summary>
 /// Atualiza as Chaves da api binance
 /// </summary>
 /// <param name="ViewModel"></param>
 /// <returns></returns>
 public HttpResponseMessage Post([FromBody] SetKeysViewModel ViewModel)
 {
     try
     {
         if (ViewModel == null)
         {
             return(Request.CreateResponse(HttpStatusCode.NotAcceptable, "Campos Inválidos", "text/plain"));
         }
         if (ModelState.IsValid)
         {
             var userId        = int.Parse(Helper.GetJWTPayloadValue(Request, "id"));
             var user          = _UserRepo.GetById(userId);
             var BinanceResult = BinanceRestApi.GetAccountInformation(ViewModel.binanceKey, ViewModel.binanceSecret);
             if (BinanceResult.IsSuccessStatusCode)
             {
                 user.BinanceAPIKey      = ViewModel.binanceKey;
                 user.BinanceAPISecret   = ViewModel.binanceSecret;
                 user.IsValidBinanceKeys = true;
                 _UserRepo.Update(user);
                 var monitor = WSMonitor.Instancia;
                 monitor.RemoveMonitor(userId);
                 return(Request.CreateResponse(HttpStatusCode.OK));
             }
             else
             {
                 user.IsValidBinanceKeys = false;
                 _UserRepo.Update(user);
                 var BinanceerrorObj = Helper.GetBinanceErrorObj(BinanceResult);
                 return(Request.CreateResponse(HttpStatusCode.BadRequest, BinanceerrorObj));
             }
         }
         var modelstateError = ModelStateErrors.DisplayModelStateError(ModelState);
         return(Request.CreateResponse(HttpStatusCode.NotAcceptable, modelstateError, "text/plain"));
     }
     catch (Exception ex)
     {
         return(Request.CreateResponse(HttpStatusCode.InternalServerError, ex.Message));
     }
 }
 public ActionResult setkeys(SetKeysViewModel ViewModel)
 {
     if (ModelState.IsValid)
     {
         var         token = Session["token"].ToString();
         HttpContent form  = new FormUrlEncodedContent(new[]
         {
             new KeyValuePair <string, string>("binanceKey", ViewModel.binanceKey),
             new KeyValuePair <string, string>("binanceSecret", ViewModel.binanceSecret)
         });
         var res = ApiUsuario.BinanceKeys(form, token);
         if (res.IsSuccessStatusCode)
         {
             return(RedirectToAction("index", "Dashboard"));
         }
         else
         {
             ModelState.AddModelError("error", "Chaves Inválidas tente novamente");
         }
     }
     return(View(ViewModel));
 }