public ResponseBasicVm CheckMessageFormat(string message) { var rp = new ResponseBasicVm(); try { if (message.Contains("=")) { var tokens = message.Split("="); if (tokens != null && tokens.Count() == 2) { var token1 = tokens[0]; if (token1 == "/stock") { var token2 = tokens[1].Trim().Replace("\u200B", string.Empty); rp.Status = Regex.IsMatch(token2, @"^[a-zA-Z]+$"); rp.Data = token2; } } } } catch (Exception) { rp.Status = false; } return(rp); }
public async Task <IActionResult> Login(string user, string pass) { var rp = new ResponseBasicVm(); try { var result = await _signInManager.PasswordSignInAsync(user, pass, true, false); if (result.Succeeded) { rp.Status = true; } else { rp.Status = false; rp.MsgBad.Add("Invalid login attempt."); } } catch (Exception e) { rp.Status = false; rp.MsgBad.Add(e.ToString()); } return(Json(rp)); }
public async Task <ResponseBasicVm> GetCsvAsync(string token) { var rp = new ResponseBasicVm(); try { string baseUrl = Configuration["csvEndpointFirst"] + token + Configuration["csvEndpointSecond"];// "https://stooq.com/q/l/?s=" + token + ".us&f=sd2t2ohlcv&h&e=csv"; //The 'using' will help to prevent memory leaks. //Create a new instance of HttpClient using (HttpClient client = new HttpClient()) using (HttpResponseMessage res = await client.GetAsync(baseUrl)) using (HttpContent content = res.Content) { string data = await content.ReadAsStringAsync(); if (data != null) { using (TextReader reader = new StringReader(data)) { //TextReader reader = new StreamReader(data); var csvReader = new CsvReader(reader); var records = csvReader.GetRecords <CsvResponseModel>(); var record = records.FirstOrDefault(); if (record.Close == "N/D" || record.Date == "N/D" || record.High == "N/D" || record.Low == "N/D") { rp.Status = false; } else { rp.Data = record; rp.Status = true; } } } } } catch (Exception e) { rp.MsgBad.Add(e.ToString()); rp.Status = false; } return(rp); }
public async Task <IActionResult> SignUp(string mail, string pass, string profileMetadata) { var rp = new ResponseBasicVm(); if (mail != null && mail != string.Empty && pass != null && pass != string.Empty && profileMetadata != null && profileMetadata != string.Empty) { var user = new UserIdentity { UserName = mail, Email = mail }; var result = await _userManager.CreateAsync(user, pass); if (result.Succeeded) { await _userManager.AddClaimAsync(user, new System.Security.Claims.Claim("profile", profileMetadata)); await _signInManager.SignInAsync(user, isPersistent : false); rp.Status = true; } else { rp.Status = false; foreach (var error in result.Errors) { rp.MsgBad.Add(error.Description); } return(Json(rp)); } } else { rp.Status = false; rp.MsgBad.Add("Wrong parameters sended!"); } return(Json(rp)); }