public async Task <ApiResponseWrapper <LoginResposeModel> > Login(LoginResquestModel loginResquestModel) { ApiResponseWrapper <LoginResposeModel> res = new ApiResponseWrapper <LoginResposeModel>(); try { HttpClient client = new HttpClient(); //specify to use TLS 1.2 as default connection System.Net.ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls; var values = new Dictionary <string, string> { { "username", loginResquestModel.UserName }, { "password", loginResquestModel.Password } }; var content = new FormUrlEncodedContent(values); var response = await client.PostAsync(ApiConstants.LoginApiUrl, content); string result = response.Content.ReadAsStringAsync().Result; response.Dispose(); res = new ApiResponseWrapper <LoginResposeModel>(true, JsonConvert.DeserializeObject <LoginResposeModel>(result)); } catch (Exception ex) { res = new ApiResponseWrapper <LoginResposeModel>(false, null, ex.Message); } return(res); }
public async void Login(object param) { //var words = new[] { ",this", " is ", "a", "test", "Super, \"luxurious\" truck" }; //System.Diagnostics.Debug.WriteLine(words.ToCsv(x => x, typeof(CsvAlwaysQuote<string>))); //System.Diagnostics.Debug.WriteLine(words.ToCsv(x => x, typeof(CsvRfc4180<string>))); //System.Diagnostics.Debug.WriteLine(words.ToCsv(x => x, typeof(CsvBare<string>))); //System.Diagnostics.Debug.WriteLine(words.ToCsv(x => x, typeof(CsvTrimAlwaysQuote<string>))); //System.Diagnostics.Debug.WriteLine(words.ToCsv(x => x, typeof(CsvTrimRfc4180<string>))); //System.Diagnostics.Debug.WriteLine(words.ToCsv(x => x, typeof(CsvTrimBare<string>))); //string str = "<ENVELOPE><COMPANYNAME.LIST><COMPANYNAME>Itlion</COMPANYNAME><COMPANYNAME>Itlion</COMPANYNAME><COMPANYNAME>Itlion</COMPANYNAME>" + // "<COMPANYNAME>Itlion</COMPANYNAME></COMPANYNAME.LIST></ENVELOPE>"; //ENVELOPE CompanyList = XmlHelper.Deserialize<ENVELOPE>(str); //System.Diagnostics.Debug.WriteLine(CompanyList.COMPANYNAME_LIST.COMPANYNAME.ToCsv(x => x, typeof(CsvTrimBare<string>))); if (this.UserNm == string.Empty || this.Password == string.Empty) { MessageBox.Show(MessageConstants.UserNamePasswordRequired, Application.Current.Resources["AppTitle"].ToString(), MessageBoxButton.OK, MessageBoxImage.Warning); } else { //bool resa= ApiManager.getInstance().CHECKCONNECTED(); GlobalSettings.UserName = this.UserNm; GlobalSettings.Password = this.Password; LoginResquestModel loginResquestModel = new LoginResquestModel(this.UserNm, this.Password); ApiResponseWrapper <LoginResposeModel> res = await ApiManager.getInstance().Login(loginResquestModel); if (res == null || res.IsSuccessful == false) { MessageBox.Show(MessageConstants.LoginFailureMessage("invalid credentials"), Application.Current.Resources["AppTitle"].ToString(), MessageBoxButton.OK, MessageBoxImage.Warning); return; } if (res.Data.status) { if (param != null) { Window win = param as Window; //TempMainContainerView tempMainContainerView = new TempMainContainerView(); TempTestView tempMainContainerView = new TempTestView(); tempMainContainerView.Owner = win; win.Hide(); tempMainContainerView.ShowDialog(); } //MessageBox.Show(MessageConstants.LoginSuccess, Application.Current.Resources["AppTitle"].ToString(), MessageBoxButton.OK, MessageBoxImage.Warning); } } }