Grial Kit

时间:2018-04-17 10:31:30

标签: c# api xamarin xamarin.forms httpclient

我在Grial模板上运行以下代码,但它无效。另一方面,它正在开展一个空项目。这些都是API运行的所有相关数据。

//数据服务

public class DataService
{

    private string Url = "http://mystroapi.azurewebsites.net/api/Company/validatecompany";

    public async Task<CompanyModel> ValidateCompany(CompanyModel model)
    {
        try
        {
           var httpClient = new HttpClient();
           var json = JsonConvert.SerializeObject(model);

           StringContent content = new StringContent(json);
           content.Headers.ContentType = new MediaTypeHeaderValue("applicantion/json");

           var response = await httpClient.PostAsync(Url, content);
           var result = await response.Content.ReadAsStringAsync();
           var company = JsonConvert.DeserializeObject<CompanyModel>(result);

           return company;

        }  
        catch (Exception)
        {
            return new CompanyModel();
        }
    }
}

// MODEL

public class CompanyModel
{

    public int CompanyId { get; set; }
    public string CompanyIdentification { get; set; }
    public string CompanyName { get; set; }
    public string CompanyApi { get; set; }
    public bool? IsActive { get; set; }

}

//调用方法

public Page GetMainPage()
{

    if(!string.IsNullOrWhiteSpace(CompanyIdentification))
    {
        CompanyModel companyModel = new CompanyModel();
        companyModel.CompanyIdentification = CompanyIdentification;

        var company = dt.ValidateCompany(companyModel);
        if (company.Id!=0)
        {
                CompanyApi = company.Result.CompanyApi;
                Settings.CompanyApi = CompanyApi;


                if (!IsLogin)
                    return new NavigationPage(new EmployeeLoginPage());
                else
                    return new RootPage();
            }

        }

       return new NavigationPage(new CompanyLoginPage());
    }
}

如有必要,请让我添加更多详细信息。

我仍然无法弄清楚为什么它不能用于Grial UI模板,而是处理其他文件。

我有什么参考资料吗?任何android或ios属性?我在Xamarin中并不是那么先进。

0 个答案:

没有答案