void HandleNewTag(object sender, NfcTag e) { var contentRead = Encoding.ASCII.GetString(e.NdefMessage[0].Payload); string serialNumber = BitConverter.ToString(e.Id); var r = new CrudApi(App.btoken); Uri restUri = new Uri(Constants.RestURLAddAttendance); string NFCContentUploaded = Guid.NewGuid().ToString(); AddAttendanceBody body = new AddAttendanceBody(serialNumber, contentRead, NFCContentUploaded); AddAttendanceResponseBody responseBody = null; try { var spRecord = new NdefTextRecord { Payload = Encoding.ASCII.GetBytes(NFCContentUploaded) }; var msg = new NdefMessage { spRecord }; device.WriteTag(msg); responseBody = Task.Run(async() => { return(await r.PostAsync <AddAttendanceBody, AddAttendanceResponseBody>(restUri, body)); }).Result; string text = responseBody.EmployeeInfo + " succesfully added attendance no." + responseBody.ID + " on point " + System.Environment.NewLine + responseBody.TagInfo; ShowSuccess(text); } catch (Exception excp) { ShowFail("An error occurred."); DependencyService.Get <IAudio>().PlayMp3File("door.mp3"); return; } Device.StartTimer(System.TimeSpan.FromSeconds(5), () => { ShowBasic(); return(true); }); return; }
public void LogoutClicked(object sender, EventArgs e) { var r = new CrudApi(App.btoken); Uri restUri = new Uri(Constants.RestURLLogout); Task.Run(async() => { return(await r.PostAsync(restUri)); }); Settings.BearerToken = ""; App.btoken = null; Navigation.PushModalAsync(new NavigationPage(new Login())); }
public void SendCode(object Sender, EventArgs e) { string phoneNumber = phoneNumberInput.Text; //"+385998308829"; string phoneID = Settings.IMEI; //"355457287365196"; var r = new CrudApi(); Uri restUri = new Uri(Constants.RestURLInitiateLogin); InitiateLogInBody body = new InitiateLogInBody(phoneID, phoneNumber); string code = Task.Run(async() => { return(await r.PostAsync <InitiateLogInBody, string>(restUri, body, true)); }).Result; if (code != null) { Navigation.PushModalAsync(new NavigationPage(new Verify(code, phoneID, phoneNumber))); } else { DisplayAlert("Not allowed", "Device and number do not match. Try retypeing the number.", "OK"); } }
public void LoginUser(object Sender, EventArgs e) { string code = verificationCodeInput.Text; if (code == Token) { var r = new RestService(); LogInBody tijelo = new LogInBody(PhoneID, PhoneNumber, code); Uri restUri = new Uri(Constants.RestURLBearerToken); App.btoken = Task.Run(async() => { return(await r.AuthentificateAsync(restUri, tijelo)); }).Result; Settings.BearerToken = JsonConvert.SerializeObject(App.btoken); CrudApi api = new CrudApi(App.btoken); if (App.btoken.Access_token != "") { Navigation.PushModalAsync(new NavigationPage(new AddAttendance())); } } else { DisplayAlert("Verification failed", "You entered invalid code.", "OK"); } }