private async void AddNotes_ToCollection(Notes obj) { //Add Notes to Server Animate = true; Instructions = "Adding Note"; //Diagnostics string Message = string.Empty; string StackTrace = string.Empty; bool _HasError = false; string cid = obj.Content_ID_Ref; //Temp Client Id await Task.Run(() => { try { Device.BeginInvokeOnMainThread(() => { var curr = new NotesCellViewModel(obj, navigation, dialogue); curr._DeleteContent += RemoveNote_FromCollection; this.Notes.Add(curr); }); DataVaultWebServiceClient dataService = new DataVaultWebServiceClient(ConfigurationManager.InSecurePublicBinding(), new System.ServiceModel.EndpointAddress(Constants.Data_InSecureUrl)); var response = dataService._AddNote(LocalMapper.MapNote_ToServer(obj)); if (response.Errors.Count != 0) { response.Errors.ForEach(w => { //Add to log table for diagnostics if (this.logging != null) { var log = LocalMapper.Map_LogWithMessage(w, Guid.NewGuid().ToString(), Guid.NewGuid().ToString()); this.logging.AddLog(log); } }); _HasError = true; } else { Device.BeginInvokeOnMainThread(() => { var note = this.Notes.SingleOrDefault(w => w.ID.Equals(cid)); note.ID = response.Content_ID; ReloadData = true; }); //Update local ID with the Server ID obj.Content_ID_Ref = response.Content_ID; _notesManager.UpdateNote(obj); } } catch (Exception ex) { _HasError = true; if (ex.InnerException != null) { Message = ex.InnerException.Message; StackTrace = ex.InnerException.StackTrace; } else { Message = ex.Message; StackTrace = ex.StackTrace; } var mEx = new Exceptions(logging, Message, StackTrace); if (mEx != null) { mEx.HandleException(mEx, logging); } } }).ContinueWith((e) => { Device.BeginInvokeOnMainThread(() => { Animate = false; //if () // dialogue.ShowAlert("mmm...Something went wrong", Message); }); }); }
private async void UpdateNote_ToCollection(Notes obj) { //Add Notes to Server Animate = true; Instructions = "Updating Note"; //Diagnostics string Message = string.Empty; string StackTrace = string.Empty; bool _HasError = false; await Task.Run(() => { try { var Index = this.Notes.IndexOf(this.Notes.SingleOrDefault(i => i.ID == obj.Content_ID_Ref)); this.Notes[Index].Subject = obj.Subject; this.Notes[Index].Description = obj.Description; DataVaultWebServiceClient dataService = new DataVaultWebServiceClient(ConfigurationManager.InSecurePublicBinding(), new System.ServiceModel.EndpointAddress(Constants.Data_InSecureUrl)); var response = dataService._UpdateNote_ByID(LocalMapper.MapNote_ToServer(obj)); if (response.Errors.Count != 0) { response.Errors.ForEach(w => { //Add to log table for diagnostics if (this.logging != null) { var log = LocalMapper.Map_LogWithMessage(w, Guid.NewGuid().ToString(), Guid.NewGuid().ToString()); this.logging.AddLog(log); } }); _HasError = true; } } catch (Exception ex) { _HasError = true; if (ex.InnerException != null) { Message = ex.InnerException.Message; StackTrace = ex.InnerException.StackTrace; } else { Message = ex.Message; StackTrace = ex.StackTrace; } var mEx = new Exceptions(logging, Message, StackTrace); if (mEx != null) { mEx.HandleException(mEx, logging); } } }).ContinueWith((e) => { Device.BeginInvokeOnMainThread(() => { Animate = false; //if (dialogue != null & _HasError) // dialogue.ShowAlert("mmm...Something went wrong", Message); }); }); }