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); } }
public static Classification CreateFromDriverClassification(DriverClassification driverClassification) { return(new Classification { Timestamp = driverClassification.Timestamp, Value = driverClassification.Classification }); }
public static Classification CreateFromDriverClassification(DriverClassification driverClassification) { return new Classification { Timestamp = driverClassification.Timestamp, Value = driverClassification.Classification }; }
public static DriverStyle CreateFromDriverClassification(DriverClassification driverClassification) { return(new DriverStyle { DriverId = driverClassification.DriverId, ClassificationAvg = driverClassification.Classification, Classifications = new[] { new Classification { Timestamp = driverClassification.Timestamp, Value = driverClassification.Classification } } }); }
public static DriverStyle CreateFromDriverClassification(DriverClassification driverClassification) { return new DriverStyle { DriverId = driverClassification.DriverId, ClassificationAvg = driverClassification.Classification, Classifications = new[] { new Classification { Timestamp = driverClassification.Timestamp, Value = driverClassification.Classification } } }; }