Example #1
0
        public IActionResult Index()
        {
            try
            {
                Coin coinResult = new Coin();

                using (var client = new HttpClient())
                {
                    client.BaseAddress = new Uri("https://localhost:44310/api/");
                    //HTTP GET
                    var responseTask = client.GetAsync("coin/2/50");
                    responseTask.Wait();

                    var result = responseTask.Result;
                    if (result.IsSuccessStatusCode)
                    {
                        var readTask = result.Content.ReadAsAsync <Coin>();
                        readTask.Wait();
                        coinResult = readTask.Result;
                    }
                    else
                    {
                        LogOperation.InsertLog(new StackTrace().GetFrame(1).GetMethod().Name, string.Concat("Coinbase servisinden response hatalı döndü", result.ReasonPhrase), DateTime.Now);
                        ModelState.AddModelError(string.Empty, "Coinbase Server error. Please contact administrator.");
                    }
                }
                return(View(coinResult));
            }
            catch (Exception ex)
            {
                LogOperation.InsertLog(new StackTrace().GetFrame(1).GetMethod().Name, string.Concat("Coinbase servisi çağrılırken hata oluştu", ex.Message), DateTime.Now);
                return(RedirectToAction("Error", "Home"));
            }
        }
Example #2
0
 [HttpGet("{fiattype}/{maxsize}/{symbol}")]// GET /api/coin
 public IActionResult GetCoinBySymbol(string symbol)
 {
     try
     {
         return(Ok(_coinData.GetCoinList(FiatType.USD).Datas.Where(x => x.Symbol == symbol)));
     }
     catch (Exception ex)
     {
         LogOperation.InsertLog("Coin/GetCoinBySymbol", string.Concat("Coinbase servisi çağrılırken hata oluştu", ex.Message), DateTime.Now);
         return(NotFound(ex.Message));
     }
 }
Example #3
0
 [HttpGet("{fiattype}/{maxsize}")]// GET /api/coin
 public IActionResult GetCoinList(FiatType fiatType, int maxSize)
 {
     try
     {
         return(Ok(_coinData.GetCoinList(fiatType, maxSize)));
     }
     catch (Exception ex)
     {
         LogOperation.InsertLog("Coin/GetCoinList", string.Concat("Coinbase servisi çağrılırken hata oluştu", ex.Message), DateTime.Now);
         return(NotFound(ex.Message));
     }
 }
        public IActionResult Authenticate(User model)
        {
            string response = string.Empty;

            try
            {
                response = _userService.Authenticate(model);

                if (string.IsNullOrEmpty(response))
                {
                    LogOperation.InsertLog("User/Authenticate", string.Format("Hatalı login işlemi : Username - {0} - Password - {1}", model.UserName, model.Password), DateTime.Now);
                    return(BadRequest(new { message = "Username or password is incorrect" }));
                }
            }
            catch (Exception ex)
            {
                LogOperation.InsertLog("User/Authenticate", string.Format("Authenticate metodunda hata alındı : {0}", ex.Message), DateTime.Now);
            }

            return(Ok(response));
        }
Example #5
0
        public ActionResult Search(string symbol)
        {
            List <Data> coinResult = new List <Data>();

            try
            {
                using (var client = new HttpClient())
                {
                    client.BaseAddress = new Uri("https://localhost:44310/api/");
                    var responseTask = client.GetAsync("coin/2/5000/" + symbol.ToUpper());
                    responseTask.Wait();

                    var result = responseTask.Result;
                    if (result.IsSuccessStatusCode)
                    {
                        var readTask = result.Content.ReadAsAsync <List <Data> >();
                        readTask.Wait();
                        coinResult = readTask.Result;
                        if (coinResult != null)
                        {
                            coinResult.ForEach(s => s.last_updated = DateTime.Now.ToString());
                        }
                    }
                    else
                    {
                        LogOperation.InsertLog(new StackTrace().GetFrame(1).GetMethod().Name, string.Concat("Coinbase servisinden response hatalı döndü", result.ReasonPhrase), DateTime.Now);
                        ModelState.AddModelError(string.Empty, "Coinbase Server error. Please contact administrator.");
                    }
                }
                return(View("CoinInfo", coinResult));
            }
            catch (Exception ex)
            {
                LogOperation.InsertLog(new StackTrace().GetFrame(1).GetMethod().Name, string.Concat("Coinbase servisi çağrılırken hata oluştu", ex.Message), DateTime.Now);
                return(RedirectToAction("Error", "Home"));
            }
        }
        public ActionResult Autherize(User user)
        {
            try
            {
                string jToken = string.Empty;
                using (var client = new HttpClient())
                {
                    client.BaseAddress = new Uri("https://localhost:44310/user/authenticate");

                    //HTTP POST
                    var postTask = client.PostAsJsonAsync <User>("authenticate", user);
                    postTask.Wait();
                    var result = postTask.Result;
                    if (result.IsSuccessStatusCode)
                    {
                        var readTask = result.Content.ReadAsStringAsync();
                        readTask.Wait();
                        jToken = readTask.Result;
                    }
                    if (string.IsNullOrEmpty(jToken))
                    {
                        ModelState.AddModelError("LogOnError", "The user name or password provided is incorrect.");
                        return(View());
                    }
                    else
                    {
                        return(RedirectToAction("CoinInfo", "Home"));
                    }
                }
            }
            catch (Exception ex)
            {
                LogOperation.InsertLog("Login/Autherize", string.Concat("Coinbase servisi çağrılırken hata oluştu", ex.Message), DateTime.Now);
                return(RedirectToAction("Error", "Home"));
            }
        }