public async Task UpdateDocument() { string databaseName = ""; DocumentCollection collectionName = null; InsertCollAndDatabase(ref databaseName, ref collectionName); string id = ProgramHelper.EnterText("Enter document id"); WorldBankModel model = await _repository.ReadDocumentByIdAsync <WorldBankModel>(id, UriFactory.CreateDocumentCollectionUri(databaseName, collectionName.Id)); model.Status = "Inactive"; Document updatedModel = await _repository.UpdateDocument <Document>(UriFactory.CreateDocumentUri(databaseName, collectionName.Id, model.Id), model); Success("Document with id >>> " + updatedModel.Id + " <<< updated."); }
public async Task ReadDocument() { string databaseName = ""; DocumentCollection collectionName = null; if (!InsertCollAndDatabase(ref databaseName, ref collectionName)) { Warning("Collection >>> " + collectionName + " <<< don't exist."); return; } WriteLine("1. Dynamic"); WriteLine("2. Document"); WriteLine("3. Model"); WriteLine("4. To JSON output"); ReadOptionEnum option = (ReadOptionEnum)ProgramHelper.EnterInt(""); string id = ProgramHelper.EnterText("Enter document id"); switch (option) { case ReadOptionEnum.Dynamic: { dynamic documentDynamic = await _repository.ReadDocumentByIdAsync <dynamic>(id, UriFactory.CreateDocumentCollectionUri(databaseName, collectionName.Id)); WriteLine("Id:\t" + documentDynamic.id); WriteLine("Country code:\t" + documentDynamic.countrycode); WriteLine("Country name:\t" + documentDynamic.countryname); List <dynamic> lstMajorSector = documentDynamic.majorsector_percent.ToObject <List <dynamic> >(); foreach (var majorSector in lstMajorSector) { WriteLine(" Sector name:\t\t" + majorSector.Name); WriteLine(" Sector percent:\t" + majorSector.Percent); ProgramHelper.Divider(); } break; } case ReadOptionEnum.Document: { Document document = await _repository.ReadDocumentByIdAsync <Document>(id, UriFactory.CreateDocumentCollectionUri(databaseName, collectionName.Id)); WriteLine("Id:\t" + document.GetPropertyValue <string>("id")); WriteLine("Country code:\t" + document.GetPropertyValue <string>("countrycode")); WriteLine("Country name:\t" + document.GetPropertyValue <string>("countryname")); JArray childArrayDocument = document.GetPropertyValue <JArray>("majorsector_percent"); foreach (var item in childArrayDocument) { WriteLine(" Sector name:\t\t" + item["Name"]); WriteLine(" Sector percent:\t" + item["Percent"]); ProgramHelper.Divider(); } break; } case ReadOptionEnum.Model: { WorldBankModel model = await _repository.ReadDocumentByIdAsync <WorldBankModel>(id, UriFactory.CreateDocumentCollectionUri(databaseName, collectionName.Id)); WriteLine("Id:\t" + model.Id); WriteLine("Country code:\t" + model.Countrycode); WriteLine("Country name:\t" + model.Countryname); ProgramHelper.Divider(); foreach (var majorSector in model.MajorsectorPercent) { WriteLine(" Sector name:\t\t" + majorSector.Name); WriteLine(" Sector percent:\t" + majorSector.Percent); ProgramHelper.Divider(); } break; } case ReadOptionEnum.ToJSONOutput: { Document document = await _repository.ReadDocumentByIdAsync <Document>(id, UriFactory.CreateDocumentCollectionUri(databaseName, collectionName.Id)); WriteLine(document.ToString()); break; } default: break; } }