when user enter password from login activity sending it to login service and waiting for the boolean response in login service.but its giving above syntax error(I mentioned it in code ) can any one solve my problem. i've to wait until the service response comes to my login activity
1.Login Interface
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
namespace RetailAppShared
{
public interface ILoginServices
{
bool AuthenticateUser (string passcode, Func<bool> function);
}
}
2.Login service
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Net;
using RestSharp;
using System.Threading.Tasks;
using Newtonsoft.Json;
namespace RetailAppShared
{
public class LoginServices : ILoginServices
{
public bool AuthenticateUser (string passcode, Func<bool> function)
{
try {
RestClient _client = new RestClient ("https://www.example.com/app/class");
var request = new RestRequest ("loginservice", Method.POST) {
RequestFormat = DataFormat.Json
};
var obj = new login ();
obj.passcode = passcode;
request.AddJsonBody (obj);
request.AddHeader ("Content-type", "application/json");
_client.ExecuteAsync (request, response => {
if (response.StatusCode == HttpStatusCode.OK) {
if (!string.IsNullOrEmpty (response.Content)) {
var objlog = JsonConvert.DeserializeObject<LoginModel> (response.Content);
flag = objlog.result.state == 1 ? true : false;
function (true);//error
} else
flag = false;
}
});
} catch (Exception ex) {
Debug.WriteLine (@" ERROR {0}", ex.Message);
}
}
}
class login
{
public string passcode { get; set; }
}
}
3.login activity
Login.Click += async (object sender, EventArgs e) => {
progress = ProgressDialog.Show (this, "", "Connecting...");
var isLoginSuccessful = loginAuthenticator.AuthenticateUser
(password.Text, (value) => {
Console.WriteLine (value);
});//error
if (progress != null) {
progress.Dismiss ();
progress = null;
}
if (isLoginSuccessful) {
StartActivity (typeof(Ledger_HomeActivity));
this.Finish ();
} else {
Toast.MakeText (this, "Invalid Login credentials! try again", ToastLength.Short).Show ();
}
};