public async void SaveContact(ContactObject contact, bool isCreated) { if (contact == null) { return; } try { QuerySpec querySpec = QuerySpec.BuildExactQuerySpec(ContactSoup, Constants.Id, contact.ObjectId, 1); JArray returned = _store.Query(querySpec, 0); JObject item = returned.Count > 0 ? returned[0].ToObject <JObject>() : new JObject(); item[ContactObject.FirstNameField] = contact.FirstName; item[ContactObject.LastNameField] = contact.LastName; item[Constants.NameField] = contact.ContactName; item[ContactObject.TitleField] = contact.Title; item[ContactObject.DepartmentField] = contact.Department; item[ContactObject.PhoneField] = contact.Phone; item[ContactObject.EmailField] = contact.Email; item[ContactObject.AddressField] = contact.Address; item[SyncManager.Local] = true; item[SyncManager.LocallyUpdated] = !isCreated; item[SyncManager.LocallyCreated] = isCreated; item[SyncManager.LocallyDeleted] = false; if (isCreated && item[Constants.Attributes.ToLower()] == null) { item[Constants.Id] = "local_" + SmartStore.CurrentTimeMillis; contact.ObjectId = item[Constants.Id].Value <string>(); var attributes = new JObject(); attributes[Constants.Type.ToLower()] = Constants.Contact; item[Constants.Attributes.ToLower()] = attributes; _store.Create(ContactSoup, item); } else { _store.Upsert(ContactSoup, item); } contact.UpdatedOrCreated = true; await UpdateContact(contact); } catch (Exception) { Debug.WriteLine("Exception occurred while trying to save"); } }
public async void SaveNote(NoteObject note, bool isCreated) { if (note == null) { return; } try { QuerySpec querySpec = QuerySpec.BuildExactQuerySpec(NotesSoup, Constants.Id, note.ObjectId, 1); JArray returned = _store.Query(querySpec, 0); JObject item = returned.Count > 0 ? returned[0].ToObject <JObject>() : new JObject(); item[NoteObject.TitleField] = note.Title; item[NoteObject.ContentField] = Convert.ToBase64String(Encoding.UTF8.GetBytes(note.Content)); item[SyncManager.Local] = true; item[SyncManager.LocallyUpdated] = !isCreated; item[SyncManager.LocallyCreated] = isCreated; item[SyncManager.LocallyDeleted] = false; if (isCreated && item[Constants.Attributes.ToLower()] == null) { item[Constants.Id] = "local_" + SmartStore.CurrentTimeMillis; note.ObjectId = item[Constants.Id].Value <string>(); var attributes = new JObject(); attributes[Constants.Type.ToLower()] = Constants.Contact; item[Constants.Attributes.ToLower()] = attributes; _store.Create(NotesSoup, item); } else { _store.Upsert(NotesSoup, item); } note.UpdatedOrCreated = true; await UpdateNote(note); } catch (Exception) { Debug.WriteLine("Exception occurred while trying to save"); } }