public async Task <IActionResult> Get(int id) { using (var db = AppDb.GetAppDb()) { if (db == null) { return(ResultUtil.GetFailureResult(StatusCodes.Status500InternalServerError, "Do not found mysql instance")); } var query = new UserInfoQuery(db); var result = await query.FindOneAsync(id); if (result == null) { return(ResultUtil.GetFailureResult(StatusCodes.Status404NotFound, "user not found")); } return(ResultUtil.GetSuccessResult(result)); } }
public async Task <IActionResult> Delete(int id) { using (var db = AppDb.GetAppDb()) { if (db == null) { return(StatusCode(StatusCodes.Status500InternalServerError, "Do not found mysql instance")); } await db.Connection.OpenAsync(); var query = new UserInfoQuery(db); var result = await query.FindOneAsync(id); if (result == null) { return(new NotFoundResult()); } await result.DeleteAsync(); return(new OkResult()); } }
public async Task <IActionResult> Update(int id, [FromBody] UserInfo body) { using (var db = AppDb.GetAppDb()) { if (db == null) { return(StatusCode(StatusCodes.Status500InternalServerError, "Do not found mysql instance")); } var query = new UserInfoQuery(db); var result = await query.FindOneAsync(id); if (result == null) { return(new NotFoundResult()); } result.Name = body.Name; result.Address = body.Address; result.Age = body.Age; result.Gender = body.Gender; await result.UpdateAsync(); return(new OkObjectResult(result)); } }