示例#1
0
        private async Task InsertItem(bool isValid)
        {
            var ctx = this.DataContext as ReportPageViewModel;
            ReportedIssue newIssue = new ReportedIssue();
            newIssue.SiteName = ((Site)cmbSiteName.SelectedItem).SiteName;
            newIssue.SiteManager = ((SiteManager)cmbSiteManager.SelectedItem).Name;
            newIssue.Contractor = ((Contractor)cmbSubcontractor.SelectedValue).ContractorName;

            if (isValid)
            {
                newIssue.Area = ((Issue)cmbArea.SelectedValue).Refraction;
            }
            else
            {
                if (txtNewAreaInput.Text != "")
                {
                    newIssue.Area = txtNewAreaInput.Text;
                    this.newIssueAdded = true;
                }
            }
            //  Get Date
            newIssue.Date = GetReportDate();
            newIssue.ActionTaken = ActionTakenTextBox.Text;
            newIssue.Severity = severity;

            try
            {
                await ctx.InsertReport(newIssueAdded, newIssue);
                //await new MessageDialog("Submit Successful").ShowAsync();
                newIssueAdded = false;
                this.navigationHelper.GoBack();
            }
            catch (MobileServiceInvalidOperationException ex)
            {
                await new MessageDialog(ex.Message, "Error").ShowAsync();
            }
            catch (Exception e)
            {
                await new MessageDialog(e.Message, "Error").ShowAsync();
            }
        }
        public async Task InsertReport(bool newIssueAdded, ReportedIssue report)
        {
            await reportsTable.InsertAsync(report);
            if (newIssueAdded)
            {
                await issuesTable.InsertAsync(new Issue { Refraction = report.Area });
            }

            await SyncAsync();  // Offline sync
        }