public async void AddOrUpdateDocument(DriverClassification driverClassification) { var driverStyle = Get(driverClassification.DriverId); if (driverStyle == null) { var newDriverStyle = DriverStyle.CreateFromDriverClassification(driverClassification); await client.CreateDocumentAsync(documentCollectionDocumentsLink, newDriverStyle); } else { DriverStyle driverStyleToUpdate = driverStyle; var classifications = driverStyleToUpdate.Classifications .OrderByDescending(x => x.Timestamp) .Take(MaxClassificationsPerDriver - 1) .ToList(); classifications.Insert(0, Classification.CreateFromDriverClassification(driverClassification)); driverStyleToUpdate.ClassificationAvg = Convert.ToInt32(classifications.Average(x => x.Value)); driverStyleToUpdate.Classifications = classifications.ToArray(); await client.ReplaceDocumentAsync(driverStyle.SelfLink, driverStyleToUpdate); } }