/// <summary> /// Builds a response DTO for the GET Document (via ID lookup) request. /// </summary> /// <param name="dbService">The database service.</param> /// <param name="collectionName">Name of the collection.</param> /// <param name="document">The document.</param> /// <param name="elapsed">The elapsed time.</param> /// <returns></returns> public static ExpandoObject BuildDocumentResponseDto(this DbService dbService, string collectionName, Document document, TimeSpan elapsed) { dynamic dynamicDto = new ExpandoObject(); dynamicDto.from = collectionName; dynamicDto.document = document.AsExpando(); dynamicDto.timestamp = DateTime.UtcNow; dynamicDto.elapsed = elapsed.ToString(); return dynamicDto; }
/// <summary> /// Converts the Schema object to a Document object. /// </summary> /// <param name="schema">The Schema.</param> /// <returns></returns> public static Document ToDocument(this Schema schema) { var document = new Document(); document._id = schema._id ?? Guid.NewGuid(); dynamic expando = document.AsExpando(); expando.Name = schema.Name; var fieldsList = schema.Fields.Values.Select(f => f.ToDictionary()).ToList(); expando.Fields = fieldsList; expando._createdTimestamp = schema._createdTimestamp; expando._modifiedTimestamp = schema._modifiedTimestamp; return document; }