public async Task UpdateMachine(Machine machine) { FirestoreDb db = await DataBase(); DocumentReference document = db.Document($"Machines/{machine.ReferenceId}"); try { WriteResult result = await document.SetAsync(machine, SetOptions.MergeAll); var easternZone = TimeZoneInfo.FindSystemTimeZoneById("Eastern Standard Time"); var updateDate = TimeZoneInfo.ConvertTimeFromUtc(result.UpdateTime.ToDateTime(), easternZone); Console.WriteLine("{0} Updated at: {1}", machine.Name, updateDate); } catch (Exception ex) { Console.WriteLine("UpdateMachine Exception: {0}", ex.ToString()); } }
public async Task <Google.Cloud.Firestore.WriteResult> DeleteFieldData(string collectionName, string documentName, List <string> keys) { FirestoreClient client = FirestoreClient.Create(channel); FirestoreDb db = await FirestoreDb.CreateAsync(configuration["GCPSetting:PROJECTNAME"], client); var document = db.Collection(collectionName).Document(documentName); var snapshot = await document.GetSnapshotAsync(); if (snapshot.Exists) { Dictionary <string, object> updates = new Dictionary <string, object>(); keys.ForEach(key => { updates.Add(key, FieldValue.Delete); }); Google.Cloud.Firestore.WriteResult writeResult = await document.UpdateAsync(updates); return(writeResult); } return(null); }