数据未发布到Azure数据库

时间:2019-04-05 10:09:42

标签: xamarin xamarin.forms

我一直试图在我的应用程序中运行此代码以将数据发布到Azure,但目前无法正常工作。我在不同的页面上使用了这种方法,并且适用于它们,这是唯一一个有问题的方法。没有数据将发布到Azure。

页面的目的是允许用户更新他们是否已服用某种药物。当用户单击“获取”按钮时,它将使用收集到的数据更新“ medfeedback”表,但当前未执行任何操作。

enter image description here

每隔一段时间我将这种方法用于其他表,它就可以工作,而且我无法弄清楚为什么这种方法对我不起作用,所以任何帮助将不胜感激。

当前,这是我的Viewmeds.cs文件:

我使用api调用来调用数据并通过列表视图进行查看;

async public Task GetUserMeds()
        {
            BusyIndicator.IsRunning = true;

            try
            {

                var usermeddosagetime = await usermedicationmanager.CurrentClient.InvokeApiAsync("getUserMedDosageTime?userid=" + Helpers.Settings.UserKey,null, HttpMethod.Get, await App.LoadAPIKeyAsync(), null);


                var responseContent = await usermeddosagetime.Content.ReadAsStringAsync();
                var user = JsonConvert.DeserializeObject<ObservableCollection<UserMedDosagePayLoad>>(responseContent);

                Debug.WriteLine("UserMedDosageTime" + usermeddosagetime);


                    foreach (UserMedDosagePayLoad item in user)
                    {
                        UserMedTimes.Add(item);
                    }

            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.ToString());
            }

AddMed函数:

   async Task AddMedFeedback(string usermedid, string medicid)
    {
        medFeedback.Usermedid = usermedid;
        medFeedback.MedID = medicid;
        medFeedback.MedsTaken = true;
        medFeedback.UserID = Helpers.Settings.UserKey;
        medFeedback.DateTime = DateTime.Now.ToString("g");


        try
        {
            await initialfeedbackmanager.AddInitialFeedback(medFeedback);

            await Navigation.PushAsync(new ViewMeds());

            medFeedback.Id = null;
        }
        catch (Exception ex)
        {
            await DisplayAlert("Error", ex.ToString(), "OK");
        }
    }

单击的按钮:

       async void Taken_Clicked(object sender, EventArgs e)
    {

        var response = await DisplayAlert("Confirm Taken", "Are you sure you took this ?", "Cancel", "OK");
        if (response == true)

        {
            await AddMedFeedback(medFeedback.MedID, medFeedback.Usermedid);

        }
        else {

            await Navigation.PushAsync(new InitialFeedbackList());
            //await GetCurrentWeather(initialmedfeedback.Id);
            Navigation.RemovePage(this);
            return;
        }

initialfeedbackmanager.cs文件:

    /// Adds or Updates medication in system
    /// </summary>
    /// <returns>The user.</returns>
    /// <param name="item">Item.</param>
    public async Task AddInitialFeedback(medfeedback item)
    {

        try
        {
            //if ID is null, it is a new record.
            if (item.Id == null)
            {
                await medicinefeedbacktable.InsertAsync(item);

            }

            //otherwise update existing record
            else
            {
                await medicinefeedbacktable.UpdateAsync(item);
            }
        }
        catch (Exception ex)
        {
            Debug.WriteLine(ex);
        }

    }

0 个答案:

没有答案