public static IActionResult GetStudentById( [HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = "GetStudentById/{id}/{key}")] HttpRequest httpRequest, [Table(tableName: "Student", partitionKey: "{key}", rowKey: "{id}", Connection = "tableStorageConnection")] StudentTableEntity studentTableEntity, string id, string key ) { try { if (studentTableEntity == null) { return(new NotFoundObjectResult(studentTableEntity)); } return(new OkObjectResult(studentTableEntity)); } catch (Exception ex) { return(new BadRequestObjectResult(ex.Message)); } }
public static async Task <IActionResult> CreateStudent1( [HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = "Student")] HttpRequest req, [Table("Student", Connection = "tableStorageConnection")] IAsyncCollector <StudentTableEntity> student, ILogger log) { log.LogInformation("Add to Table storage"); string requestBody = await new StreamReader(req.Body).ReadToEndAsync(); StudentTableEntity data = JsonConvert.DeserializeObject <StudentTableEntity>(requestBody); try { // Add to DB, instead just add to static list data.StudId = Guid.NewGuid(); await student.AddAsync(data); return(new OkObjectResult(data)); } catch (Exception ex) { log.LogInformation(ex.Message); return(new BadRequestObjectResult(ex.Message)); } }