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; } }
public async Task Run() { string databaseName = ""; DocumentCollection collectionName = null; if (!InsertCollAndDatabase(ref databaseName, ref collectionName)) { Warning("Collection >>> " + collectionName + " <<< don't exist."); return; } WriteLine("1. Call sp, insert StoreModel"); WriteLine("2. Create"); SPOption option = (SPOption)ProgramHelper.EnterInt(""); switch (option) { case SPOption.Read: { StoreModel storeModel = new StoreModel() { Address = new AddressModel() { AddressType = "Back Office", CountryRegionName = "Neum", Location = new LocationModel() { City = "Neum", StateProvinceName = "Jadran" }, PostalCode = "88390" }, Name = "Super new Network bank RVS" }; try { Document resultSP = await _baseRepository.RunStoredProcedureAsync(UriFactory.CreateStoredProcedureUri(databaseName, collectionName.Id, "spCreateDocIfIdIsUnique"), storeModel); ProgramHelper.Divider(); Success("Result: "); WriteLine(resultSP.ToString()); } catch (Exception ex) { Error(ex.Message); } break; } case SPOption.Create: { StoredProcedure sprocDefinition = new StoredProcedure { Id = "spGetCountByRegion", Body = File.ReadAllText(@"Scripts\spGetCountByRegion.js") }; StoredProcedure result = await _baseRepository.CreateStoredProcedureAsync(UriFactory.CreateDocumentCollectionUri(databaseName, collectionName.Id), sprocDefinition); Success("Created stored procedure " + result.Id + " RID: " + result.ResourceId); /////////////////////////////////////////////// sprocDefinition.Id = "spCreateDocIfIdlsUnique"; sprocDefinition.Body = File.ReadAllText(@"Scripts\spCreateDocIfIdlsUnique.js"); result = await _baseRepository.CreateStoredProcedureAsync(UriFactory.CreateDocumentCollectionUri(databaseName, collectionName.Id), sprocDefinition); Success("Created stored procedure " + result.Id + " RID: " + result.ResourceId); break; } } }