예제 #1
0
        public async void UpdateRepair(RepairViewModel model)
        {
            FirestoreDb db = connection.GetFirestoreDb();

            QuerySnapshot snapshot = db
                                     .Collection("service-repairs")
                                     .WhereEqualTo("RepairId", model.RepairId)
                                     .Limit(1)
                                     .GetSnapshotAsync()
                                     .Result;

            Repair repair = snapshot
                            .FirstOrDefault()
                            .ConvertTo <Repair>();

            repair       = NewRepair(model);
            repair.Notes = model.Notes;

            Dictionary <string, object> d = repair
                                            .GetType()
                                            .GetProperties()
                                            .ToDictionary(x => x.Name, x => x.GetValue(repair, null));

            string logDesc = "Update repair card";

            await snapshot.Documents
            .FirstOrDefault()
            .Reference
            .UpdateAsync(d);

            //modelAsDict
            //	.ToList()
            //	.ForEach(x => {
            //		if(repairAsDict.ContainsKey(x.Key)) {
            //			if(repairAsDict[x.Key] != x.Value) {
            //				logDesc += $"\\n{x.Key} from {repairAsDict[x.Key]} to {x.Value}";
            //			}
            //		}
            //	});

            RepairLog log = new RepairLog()
            {
                TimeOfEvent = DateTime.UtcNow,
                Description = logDesc,
                TypeOfEvent = "update"
            };

            await new LogService()
            .UploadLogToExistingRepair(model.RepairId, log);
        }