Ejemplo n.º 1
0
        //Get data from enterWeight database
        async void GetWeightRequest()
        {
            //getting information from database
            List <Weightdb> weightInformation = await AzureManager.AzureManagerInstance.GetWeightInformation();

            int count = weightInformation.Count;

            if (count == 0)
            {
                return; // first time user
            }
            Weightdb last = weightInformation[count - 1];

            //populating invisible labels
            lblCWeight.Text = last.CurrentWeight.ToString();
            lblTWeight.Text = last.TargetWeight.ToString();
            lblTDate.Text   = last.TargetDate.ToString();

            DisplayCurrentWeight();
        }
Ejemplo n.º 2
0
        private async Task UpdateWeightRequest()
        {
            //trying to convert string to float
            bool     resultCurrent = float.TryParse(entryField.Text, out float cWeight);
            bool     resultTarget  = float.TryParse(entryTargetWeight.Text, out float tWeight);
            Weightdb model;

            //first time user - this is to stop errors occuring
            //if weight label is null - no data in database
            if (IsNull(lblCWeight.Text))
            {
                lblCWeight.Text = "0";
            }

            //if target weight label is null - no data in database
            if (IsNull(lblTWeight.Text))
            {
                lblTWeight.Text = "0";
            }

            if (!resultCurrent) //checking if valid input/or empty
            {
                //updating values in database
                model = new Weightdb()
                {
                    ID            = "1",
                    CurrentWeight = float.Parse(lblCWeight.Text), //user has not entered a value so grabing value from database
                    TargetWeight  = tWeight,
                    TargetDate    = dateTargetWeight.Date
                };
            }
            else if (!resultTarget) //checking if valid input/or empty
            {
                //updating values in database
                model = new Weightdb()
                {
                    ID            = "1",
                    CurrentWeight = cWeight,
                    TargetWeight  = float.Parse(lblTWeight.Text), //user has not entered a value so grabing value from database
                    TargetDate    = dateTargetWeight.Date
                };
            }
            else
            {
                //updating values in database
                model = new Weightdb()
                {
                    ID            = "1",
                    CurrentWeight = cWeight,
                    TargetWeight  = tWeight,
                    TargetDate    = dateTargetWeight.Date
                };
            }

            if (weightHistoryList.Count == 0)
            {
                //first time user
                await AzureManager.AzureManagerInstance.PostWeightInformation(model);

                return;
            }

            try
            {
                //update existing row
                await AzureManager.AzureManagerInstance.UpdateWeightInformation(model);
            }
            catch (ArgumentException)
            {
                lblResult.Text = "ID does not exist in Database";
            }
        }
Ejemplo n.º 3
0
 public async Task UpdateWeightInformation(Weightdb enterWeight)
 {
     await this.enterWeightTable.UpdateAsync(enterWeight);
 }
Ejemplo n.º 4
0
 public async Task PostWeightInformation(Weightdb enterWeight)
 {
     await this.enterWeightTable.InsertAsync(enterWeight);
 }