public static async System.Threading.Tasks.Task <IActionResult> Update( [HttpTrigger(AuthorizationLevel.Function, "get", Route = "efcore_test_update")] HttpRequest req, ILogger log ) { log.LogInformation("start EntityFrameworkTestController_Update"); // jsonリクエストを取得 string requestBody = await new StreamReader(req.Body).ReadToEndAsync(); dynamic data = JsonConvert.DeserializeObject(requestBody); // jsonリクエストで掲示板更新 using (var _dbContext = new DBContextFactory().CreateDbContext()) { var board = _dbContext.Boards.Find((long)data?.Id); if (board != null) { board.Title = data?.Title; board.UserName = data?.UserName; board.AboutText = data?.AboutText; board.Password = data?.Password; _dbContext.SaveChanges(); } } return(new OkResult()); }
public static async System.Threading.Tasks.Task <IActionResult> Insert( [HttpTrigger(AuthorizationLevel.Function, "get", Route = "efcore_test_insert")] HttpRequest req, ILogger log) { log.LogInformation("start EntityFrameworkTestController_Insert"); // jsonリクエストを取得 string requestBody = await new StreamReader(req.Body).ReadToEndAsync(); dynamic data = JsonConvert.DeserializeObject(requestBody); // jsonリクエストで掲示板登録 using (var _dbContext = new DBContextFactory().CreateDbContext()) { var board = new Board { Title = data?.Title, UserName = data?.UserName, AboutText = data?.AboutText, Password = data?.Password }; _dbContext.Boards.Add(board); _dbContext.SaveChanges(); } return(new OkResult()); }
public static IActionResult Delete( [HttpTrigger(AuthorizationLevel.Function, "get", Route = "efcore_test_delete/{id:long}")] HttpRequest req, long Id, ILogger log ) { log.LogInformation("start EntityFrameworkTestController_Delete"); using (var _dbContext = new DBContextFactory().CreateDbContext()) { var board = _dbContext.Boards.Find(Id); if (board == null) { return(new UnprocessableEntityObjectResult("board is null")); } _dbContext.Boards.Remove(board); _dbContext.SaveChanges(); } return(new OkObjectResult($"Delete Id: {Id}")); }