コード例 #1
0
        public static IActionResult Write(ILogger log)
        {
            var connectionString = "Data Source=localhost;Initial Catalog=Merchant;User ID=sa;Password=P@ssw0rd;Connection Timeout=25;";

            log.LogInformation("Using connection string -> {0}", connectionString);

            var repo = new SqlRepository(connectionString);

            var merchant = MerchantFactory.CreateMerchant();

            log.LogInformation("Writing merchant object with ID {0}.", merchant.Id);

            var      message = "";
            Merchant doc     = null;

            try
            {
                doc     = repo.CreateMerchant(merchant);
                message = "Wrote Merchant " + merchant.Id;
            }
            catch (Exception e)
            {
                message = "Failed due to " + e.Message;
            }

            return(doc != null
                ? (ActionResult) new OkObjectResult(message)
                : new BadRequestObjectResult(message));
        }
コード例 #2
0
        public static ActionResult Write(ILogger log)
        {
            var server         = "https://localhost:8081";
            var databaseName   = "CosmosTest";
            var collectionName = "Merchants";
            var key            = "C2y6yDjf5/R+ob0N8A7Cgv30VRDJIWEHLM+4QDU5DE2nQ9nDuVTqobD4b8mGGyPMbIZnqyMsEcaGQy67XIw/Jw==";

            log.LogInformation("Connecting to {0}. Getting or creating db {1} and getting or creating collection {2}.", server, databaseName, collectionName);

            var repo = new CosmosRepository(server, databaseName, collectionName, key);

            log.LogInformation("Writing merchant object.");
            var merchant = MerchantFactory.CreateMerchant();

            var doc = repo.CreateDoc(merchant);

            return(doc != null
                ? (ActionResult) new OkObjectResult("Wrote Merchant " + merchant.Id)
                : new BadRequestObjectResult("No document created."));
        }