官术网_书友最值得收藏!

How to do it...

  1. Navigate to the Integrate tab of the RegisterUser HTTP trigger function.
  2. Click on the New Output button and select Azure Table Storage then click on the Select button:
  1. Once you click on the Select button in the previous step, you will be prompted to choose the following settings of the Azure Table storage output bindings:
    • Table parameter name: This is the name of the parameter that you will be using in the Run method of the Azure Function. For this example, please provide objUserProfileTable as the value.
    • Table name: A new table in the Azure Table storage will be created to persist the data. If the table doesn't exist already, Azure will automatically create one for you! For this example, please provide tblUserProfile as the table name.
    • Storage account connection: If you don't see the Storage account connection string, click on the new (shown in the following screenshot) to create a new one or to choose an existing storage account.
    • The Azure Table storage output bindings should be as shown in the following screenshot:
  1. Click on Save to save the changes.
  1. Navigate to the code editor by clicking on the function name and paste the following code:
        #r "Microsoft.WindowsAzure.Storage"
using System.Net;
using Microsoft.WindowsAzure.Storage.Table;

public static async Task<HttpResponseMessage>
Run(HttpRequestMessage req,TraceWriter
log,CloudTable objUserProfileTable)
{
dynamic data = await
req.Content.ReadAsAsync<object>();
string firstname= data.firstname;
string lastname=data.lastname;

UserProfile objUserProfile = new UserProfile(firstname,
lastname);
TableOperation objTblOperationInsert =
TableOperation.Insert(objUserProfile);
objUserProfileTable.Execute(objTblOperationInsert);

return req.CreateResponse(HttpStatusCode.OK,
"Thank you for Registering..");
}

public class UserProfile : TableEntity
{
public UserProfile(string lastName, string firstName)
{
this.PartitionKey = "p1";
this.RowKey = Guid.NewGuid().ToString();;
this.FirstName = firstName;
this.LastName = lastName;
}
public UserProfile() { }
public string FirstName { get; set; }
public string LastName { get; set; }
}
  1. Let's execute the function by clicking on the Run button of the Test tab by passing firstname and lastname parameters in the Request body as shown in the following screenshot:
  1. If everything went well, you should get a Status 200 OK message in the Output box as shown in the preceding screenshot. Let's navigate to Azure Storage Explorer and view the table storage to see if the table named tblUserProfile was created successfully:
主站蜘蛛池模板: 祁连县| 山阴县| 桂东县| 盐亭县| 双江| 景宁| 墨竹工卡县| 阿荣旗| 洛南县| 汉寿县| 怀远县| 福泉市| 宁国市| 北票市| 比如县| 博兴县| 楚雄市| 涟水县| 平江县| 满洲里市| 凤翔县| 民和| 商水县| 奈曼旗| 仁化县| 乌兰浩特市| 岗巴县| 白玉县| 常山县| 马尔康县| 杭锦后旗| 宝应县| 获嘉县| 荥经县| 铜川市| 改则县| 龙山县| 隆德县| 宁武县| 徐汇区| 垣曲县|