我试图弄清楚在Azure函数中使用BindAsync将记录添加之前如何检查记录是否存在。有没有办法使用我现有的实现来做到这一点,或者我需要使用其他方法吗?
具体检查函数底部是否包含“输出”局部变量。
[FunctionName("Signup")]
public static async Task<IActionResult> Signup([HttpTrigger(AuthorizationLevel.Anonymous, "post", Route ="user/signup")] HttpRequest Req, Binder binder, ILogger log)
{
var UserId = System.Guid.NewGuid().ToString();
var FirstName = Req.Form["FirstName"];
var LastName = Req.Form["LastName"];
string FbId = null;
if (Req.Form.ContainsKey("FbId"))
{
FbId = Req.Form["FbId"];
}
var Email = Req.Form["Email"];
var PasswordPlain = Req.Form["Password"];
string hash;
hash = BCrypt.Net.BCrypt.HashPassword(PasswordPlain);
var ProfilePic = Req.Form.Files.GetFile("ProfilePic");
var ProfilePicStream = ProfilePic.OpenReadStream();
var ProfilePicFileName = await UploadImage(ProfilePicStream, UserId, binder);
if (FbId == null)
{
log.LogInformation("No FB detected");
}
else
{
log.LogInformation("FB detected");
}
var NewUser = new UserTableEntity
{
PartitionKey = 1.ToString(),
RowKey = UserId,
FirstName = FirstName,
LastName = LastName,
FbId = FbId,
Email = Email,
ProfilePic = ProfilePicFileName,
Password = hash
};
var attributes = new System.Attribute[]
{
new StorageAccountAttribute("TabbrDevCosmosDb"),
new TableAttribute("Users")
};
var output = await binder.BindAsync<IAsyncCollector<UserTableEntity>>(attributes);
await output.AddAsync(NewUser);
return new OkObjectResult(JsonConvert.SerializeObject(NewUser));
}
答案 0 :(得分:1)
我们必须以一种基本的方式来做到这一点,执行查询以查找是否有记录重复。
为查询添加声明性表输入绑定
ApplicationArguments
执行查询,以-- variable declaration
DECLARE @PCOL VARCHAR(20);
-- assigning values to the variable
SELECT @PCOL += (QUOTENAME (X.TD) + ',')
FROM
(
SELECT DISTINCT YEAR(TRANSACTION_DATE) AS TD
FROM TRANSACTION_INFO
) AS X;
-- Check the result
PRINT @PCOL
为例。
public static async Task<IActionResult> Signup(
[HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = "user/signup")] HttpRequest Req,
[Table("Users", Connection = "TabbrDevCosmosDb")]CloudTable table,
Binder binder, ILogger log)