Exemple #1
0
        //private Prescription GetPrescriptionEntity(int prescriptionID)
        //{
        //    // Define a LINQ query to get the specified Prescription entity.
        //    var query = from p in _db.Prescriptions
        //                where p.PrescriptionID == prescriptionID
        //                select p;

        //    // Return the Prescription entity.
        //    return query.First();
        //}

        private async void repeatPrescriptions_Click(object sender, EventArgs e)
        {
            // Get the highlighted prescriptions in the prescriptionsGridView.
            DataGridViewSelectedRowCollection selectedRows = prescriptionsGridView.SelectedRows;

            var updatedPrescriptions = new List <Prescriptions>();

            // For each highlighted prescription, increase the RepeatCount.
            for (int i = 0; i < selectedRows.Count; i++)
            {
                // Get the PrescriptionID from the prescriptionsGridView row.
                int prescriptionID = (int)selectedRows[i].Cells["PrescriptionID"].Value;

                // Get the Prescription entity.
                //Prescription prescription = GetPrescriptionEntity(prescriptionID);
                var prescription = await _client.GetAsync <Prescriptions>($"prescriptions/{prescriptionID}");

                // Increment the RepeatCount.
                prescription.RepeatCount++;

                // keep track of the updated prescriptions
                updatedPrescriptions.Add(prescription);
            }

            //// Save the changes to the database.
            //DoSave();

            // add ids to querystring
            var idsQueryString = new StringBuilder("?");

            updatedPrescriptions.ForEach(p => idsQueryString.Append($"ids={p.PrescriptionId}&"));

            // Save the changes to the database.
            try
            {
                await _client.PutAsync($"prescriptions{idsQueryString}", updatedPrescriptions);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Unable to save changes - please try again.");
            }
            DisplayPrescriptions();
        }