public async Task <IActionResult> GetOne(int id) { await Db.Connection.OpenAsync(); var query = new UserQuery(Db); var result = await query.FindOneAsync(id); if (result is null) { return(new NotFoundResult()); } return(new OkObjectResult(result)); }
public async Task <IActionResult> GetOne(int id) { using (var db = new AppDb()) { await db.Connection.OpenAsync(); var query = new UserQuery(db); var result = await query.FindOneAsync(id); if (result == null) { return(new NotFoundResult()); } return(new OkObjectResult(result)); } }
public async Task <IActionResult> DeleteOne(int id) { await Db.Connection.OpenAsync(); var query = new UserQuery(Db); var result = await query.FindOneAsync(id); if (result is null) { return(new NotFoundResult()); } result.Deleted = true; await PutOne(id, result); return(new OkResult()); }
public async Task <IActionResult> PutOne(int id, [FromBody] User body) { using (var db = new AppDb()) { await db.Connection.OpenAsync(); var query = new UserQuery(db); var result = await query.FindOneAsync(id); if (result == null) { return(new NotFoundResult()); } result.name = body.name; await result.UpdateAsync(); return(new OkObjectResult(result)); } }
public async Task <IActionResult> PutOne(int id, [FromBody] Users body) { await Db.Connection.OpenAsync(); var query = new UserQuery(Db); var result = await query.FindOneAsync(id); if (result is null) { return(new NotFoundResult()); } result.Name = body.Name; result.Password = body.Password; result.Age = body.Age; result.DateCreated = body.DateCreated; result.Deleted = body.Deleted; await result.UpdateAsync(id); return(new OkObjectResult(result)); }