how to get id based on username and password web api xamarin forms

i need to get only from table based on username and passsword i am using xamarin cross platfrom and i am using web api to connect with sql server here is my code.

Web Api

Controller

[HttpGet]
        [ActionName("XAMARIN_Login")]      
       public IHttpActionResult GetId(string username, string password)
        {
  var result = db.AspNetUsers
                 .Where(x => x.UserName == username && x.PasswordHash==password)
                 .Select(x => x.Id)
   .FirstOrDefault();
return Ok(result);
        }

Xamarin

RestClient.cs

 private const string WebloginUrl = "http://172.16.4.212:55364/api/AspNetUsers/GetId/";
    public async Task<List<T>> checkLogin(string username, string password)
            {
                var httpClient = new HttpClient();
                var json = await httpClient.GetStringAsync(WebloginUrl + "?username=" + username + "&" + "password=" + password);
                var taskModels = JsonConvert.DeserializeObject<List<T>>(json);
                return taskModels;

            }

Xamarin

Services.cs

public async Task<List<UserDetail>> GetId(string username, string password)
        {
    RestClient<UserDetail> userDetail = new RestClient<UserDetail>();
            var user = await userDetail.checkLogin(username,password);
           return user;
        }

Xamarin

MainPage.xaml

 <?xml version="1.0" encoding="utf-8" ?>
    <ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
                 xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
                 xmlns:local="clr-namespace:Employee"
                 xmlns:ViewModels="clr-namespace:Employee.ViewModels"
                 x:Class="Employee.MainPage" Title="Kulsum International Hospital">



     <StackLayout>
            <Entry  x:Name="EntryUsername"/>
            <Entry x:Name="EntryPassword" />
 <Entry x:Name="Id" /> 

`// what i want when user click on button Id should appear in this entry`  


            <Button x:Name="ButtonLogin"  Clicked="ButtonLogin_Clicked"/>
        </StackLayout>
    </ContentPage>

Xamarin

MainPage.xaml.cs

 private async void ButtonLogin_Clicked(object sender, EventArgs e)
        {
            EmployeesServices services = new EmployeesServices();
            var getLoginDetails = await services.GetId(EntryUsername.Text, EntryPassword.Text);




// Here i dont know what to do to get id in entry

        }

I have uploaded all my code now this code working absolutely fine, but i am just confused on last step wheere i dont know how to show id in entry when user click on button

Best Answer

Answers

Sign In or Register to comment.