private void OnRefresh_Core() { //Generate collection of Notes Animate = true; Instructions = "Loading your notes"; Task.Run(() => { this.Notes.Clear(); var notes = _notesManager.Get_NotesByContactID <Notes>(Constants.InMemory_ContactID); if (notes.Count != 0) { foreach (var note in notes) { var obj = new NotesCellViewModel(note, navigation, dialogue); //Subscriptions obj._DeleteContent += RemoveNote_FromCollection; this.Notes.Add(obj); } } }).ContinueWith((e) => { Device.BeginInvokeOnMainThread(() => { ReloadData = true; Animate = false; }); }); }
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); }); }); }