/// <summary> /// Parsed the new incident data returned by the server. /// </summary> /// <param name="result">The new incident data returned by the server.</param> private void ProcessReportIncidentResult(JsonValue result) { // Get the new incident report id var id = result.GetItemOrDefault("id").GetStringValueOrDefault(null); var status = result.GetItemOrDefault("status").GetStringValueOrDefault(string.Empty); if (!string.IsNullOrEmpty(id)) { // Create a new incident report var date = this.reportDate ?? DateTime.UtcNow; var report = new IncidentReport(id) { Date = date.ToLocalTime(), DropPoint = this.pin.Label, Type = this.IncidentTypes[this.incidentTypeIndex], Status = status }; // Raise incident reported created event this.OnIncidentReportCreated?.Invoke(this, report); } // End the submission process this.IsBusy = false; // Close the current view this.Navigation.PopModalAsync(); }
/// <summary> /// Processes the reports update returned by the server. /// </summary> /// <param name="result">The reports update result.</param> private void ProcessUpdateReportsResult(JsonValue result) { // Process the HAL string nextUri; var reports = WebHelper.ParseHalCollection(result, "reportes", out nextUri); // Parse my reports data foreach (var report in reports) { // Parse reports update data this.HaveReports = true; // Get my report field var id = report.GetItemOrDefault("id").GetStringValueOrDefault(null); var dateString = report.GetItemOrDefault("fecha").GetItemOrDefault("date").GetStringValueOrDefault(string.Empty); var dropPoint = report.GetItemOrDefault("montonera").GetStringValueOrDefault(null); var incident = report.GetItemOrDefault("incidencia").GetStringValueOrDefault(null); var status = report.GetItemOrDefault("status").GetStringValueOrDefault(string.Empty); // Parse notification date DateTime date; var parseResult = DateTime.TryParseExact( dateString, "yyyy-MM-dd HH:mm:ss.ffffff", null, System.Globalization.DateTimeStyles.None, out date); // If all fields present if (!string.IsNullOrEmpty(id) && parseResult && !string.IsNullOrEmpty(dropPoint) && !string.IsNullOrEmpty(incident) && !string.IsNullOrEmpty(status)) { // If report already exists if (this.reportsDictionary.ContainsKey(id)) { this.reportsDictionary[id].Status = status; } else { // Add to submitted reports commection var reportObject = new IncidentReport(id) { Date = date.ToLocalTime(), DropPoint = dropPoint, Type = incident, Status = status }; this.SubmittedReports.Add(reportObject); this.reportsDictionary.Add(id, reportObject); } } } // If new page is present if (nextUri != null) { // Get the favorites from the server WebHelper.SendAsync( new Uris.UriMethodPair(new Uri(nextUri), HttpMethod.Get), null, this.ProcessUpdateReportsResult, () => this.IsBusy = false); } else { // Hide the progress indicator this.IsBusy = false; } }