コード例 #1
0
        public static async Task <HttpResponseMessage> Run([HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)] HttpRequestMessage req, ILogger log)
        {
            log.LogTrace("C# HTTP trigger function processed a request.");

            dynamic body = await req.Content.ReadAsStringAsync();

            var data = JsonConvert.DeserializeObject <CompanyStrategicInfo> (body as string);

            // parse query parameter
            Guid?CompanyId = data.CompanyId;

            string connectionstring2 = "DefaultEndpointsProtocol=https;AccountName=workconnectuser;AccountKey=Kv56s3lKZhE9WriAvDMubc5pmenB+NF1vkv6rINS0wlEOJfQVvRIrntpuKaqgpomqkF/4M99pMtmo7Egjq9MvQ==;EndpointSuffix=core.windows.net";


            if (CompanyId == null)
            {
                return(req.CreateResponse(HttpStatusCode.BadRequest, "Please pass a company name"));
            }


            //this code will do a insert and do a check for the id
            CloudStorageAccount storageAccount = CloudStorageAccount.Parse(connectionstring2);
            CloudTableClient    tableClient    = storageAccount.CreateCloudTableClient();

            CloudTable cloudTable = tableClient.GetTableReference("companyvisionsurvey");

            TableOperation tableOperation = TableOperation.Retrieve <CompanyStrategicInfo>(CompanyId.Value.ToString(), CompanyId.Value.ToString());

            TableResult tableResult = await cloudTable.ExecuteAsync(tableOperation);

            CompanyStrategicInfo person = tableResult.Result as CompanyStrategicInfo;

            string json = null;

            if (person == null)
            {
                try
                {
                    // add the code here to pass the id back to the client
                    json = JsonConvert.SerializeObject(person);
                }
                catch (StorageException se)
                {
                    log.LogTrace(se.Message);
                }
                catch (Exception ex)
                {
                    log.LogTrace(ex.Message);
                }
            }


            //change this to return the companyid
            return(new HttpResponseMessage(HttpStatusCode.OK)
            {
                Content = new StringContent(json, Encoding.UTF8, "application/json")
            });
        }
コード例 #2
0
        public static async Task <HttpResponseMessage> Run(
            [HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)] HttpRequestMessage req,
            ILogger log)
        {
            log.LogInformation("C# HTTP trigger function processed a request.");

            dynamic body = await req.Content.ReadAsStringAsync();

            var data = JsonConvert.DeserializeObject <CompanyStrategicInfo>(body as string);

            //name = name ?? data?.name;

            // parse query parameter
            Guid?  CompanyId           = data?.CompanyId;
            string Vision              = data?.Vision;
            string Values              = data?.Values;
            string Mission             = data?.Mission;
            string MissionOutComes     = data?.MissionOutComes;
            string CompetitiveStrategy = data?.CompetitiveStrategy;
            string StrategyOutComes    = data?.StrategyOutComes;
            string RegulatoryOutComes  = data?.RegulatoryOutComes;


            string connectionstring2 = "DefaultEndpointsProtocol=https;AccountName=spassessservices20190227;AccountKey=KLx/VDJ279oOZ2Z2wELr90GauiVlEN4pr8r2ss2xAiokZJGAi4PF6eGz0nI0Vz0IieEwtKxqkgoM+ukeVoWxMw==;EndpointSuffix=core.windows.net";


            if (CompanyId == null)
            {
                return(req.CreateResponse(HttpStatusCode.BadRequest, "Please pass a full Regisration in the request body"));
            }


            //this code will do a insert and do a check for the id
            CloudStorageAccount storageAccount = CloudStorageAccount.Parse(connectionstring2);
            CloudTableClient    tableClient    = storageAccount.CreateCloudTableClient();

            CloudTable cloudTable = tableClient.GetTableReference("Registration");

            //Email is the unique data
            TableOperation tableOperation = TableOperation.Retrieve <CompanyStrategicInfo>(CompanyId.Value.ToString(), CompanyId.Value.ToString());

            TableResult tableResult = await cloudTable.ExecuteAsync(tableOperation);

            CompanyStrategicInfo person = tableResult.Result as CompanyStrategicInfo;


            if (person == null)
            {
                try
                {
                    var registration = new CompanyStrategicInfo()
                    {
                        PartitionKey        = CompanyId.Value.ToString(),
                        RowKey              = CompanyId.Value.ToString(),
                        CompanyId           = CompanyId,
                        Vision              = Vision,
                        Values              = Values,
                        Mission             = Mission,
                        MissionOutComes     = MissionOutComes,
                        CompetitiveStrategy = CompetitiveStrategy,
                        StrategyOutComes    = StrategyOutComes,
                        RegulatoryOutComes  = RegulatoryOutComes
                    };

                    TableOperation insertOperation = TableOperation.Insert(registration);
                    TableResult    insertResult    = await cloudTable.ExecuteAsync(insertOperation);


                    var login = new CompanyStrategicInfo()
                    {
                        PartitionKey        = CompanyId.Value.ToString(),
                        RowKey              = CompanyId.Value.ToString(),
                        CompanyId           = CompanyId,
                        Vision              = Vision,
                        Values              = Values,
                        Mission             = Mission,
                        MissionOutComes     = MissionOutComes,
                        CompetitiveStrategy = CompetitiveStrategy,
                        StrategyOutComes    = StrategyOutComes,
                        RegulatoryOutComes  = RegulatoryOutComes
                    };

                    CloudTable     cloudTable1      = tableClient.GetTableReference("Login");
                    TableOperation insertOperation1 = TableOperation.Insert(login);
                    TableResult    insertResult1    = await cloudTable1.ExecuteAsync(insertOperation1);
                }

                catch (StorageException se)
                {
                    log.LogTrace(se.Message);
                }
                catch (Exception ex)
                {
                    log.LogTrace(ex.Message);
                }
            }
            else
            {
                //do the update
            }



            return(req.CreateResponse(HttpStatusCode.Created, "successful"));
        }