Exemple #1
0
        // Saves the Walk Entry item that is currently being added/edited.
        public async Task SaveWalkEntry(WalkDataModel item, bool isAdding)
        {
            try
            {
                HttpResponseMessage responseMessage;
                var json    = JsonConvert.SerializeObject(item);
                var content = new StringContent(json, Encoding.UTF8, "application/json");

                // Check to see if we are adding or editing, handle accordingly.
                if (isAdding)
                {
                    responseMessage = await client.PostAsync("tables/WalkEntries", content);
                }
                else
                {
                    responseMessage = await client.PutAsync("tables/WalkEntries", content);
                }
                // Check to see if we have successfully written the item to the database
                if (responseMessage.IsSuccessStatusCode)
                {
                    Debug.WriteLine("WalkEntry Item successfully saved.");
                }
            }
            catch (Exception ex)
            {
                // Catch and output any error messages that have occurred
                Debug.WriteLine("An error occurred {0}", ex.Message);
            }
        }
        public async Task SaveWalkEntryFirebase(WalkDataModel item, bool isAdding)
        {
            if (isAdding)
            {
                var allWalkDataModels = await GetWalkEntriesFirebase();

                await firebase
                .Child("WalkDataModels")
                .OnceAsync <WalkDataModel>();

                if (allWalkDataModels.Count > 0)
                {
                    var model = allWalkDataModels.MaxBy(a => a.Id).FirstOrDefault();
                    int next  = model.Id + 1;
                    item.Id = next;
                }
                else
                {
                    item.Id = 1;
                }
                await firebase
                .Child("WalkDataModels")
                .PostAsync(item);
            }
            else
            {
                var toUpdateWalkDataModel = (await firebase
                                             .Child("WalkDataModels")
                                             .OnceAsync <WalkDataModel>()).Where(a => a.Object.Id == item.Id).FirstOrDefault();

                await firebase
                .Child("WalkDataModels")
                .Child(toUpdateWalkDataModel.Key)
                .PutAsync(item);
            }
        }
 public async Task SaveWalkEntry(WalkDataModel item, bool isAdding)
 {
     await client.AddWalkEntires(item);
 }
        public async Task AddWalkEntires(WalkDataModel walk)
        {
            await WalkEntryTable.InsertAsync(walk);

            await SyncWalkEntries();
        }