using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using LinqToDB; using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Logging; namespace SyBaseTestWebApp.Controllers { [ApiController] [Route("[controller]")] public class WeatherForecastController : ControllerBase { private readonly AppDataConnection _connection; private readonly ILogger _logger; public WeatherForecastController( AppDataConnection connection ,ILogger logger) { _connection = connection; _logger = logger; } [HttpGet] public Task ListUser() { return _connection.Part.ToArrayAsync(); } [HttpGet("{id}")] public async Task GetUser(int id) { var parts =await _connection.Part.Where(p => p.Id == id).ToListAsync(); return parts[0]; // return _connection.Part.FirstOrDefaultAsync(person => person.Id == id); } [HttpDelete("{id}")] public Task DeleteUser(int id) { return _connection.Part.Where(person => person.Id == id).DeleteAsync(); } [HttpPut] public Task UpdateUser(Part person) { return _connection.UpdateAsync(person); } [HttpPatch("{id}/new-name")] public Task UpdateUserName(int id, string newName) { return _connection.Part.Where(person => person.Id == id) .Set(person => person.Name, newName) .UpdateAsync(); } [HttpPost] public Task InsertUser(Part person) { return _connection.InsertAsync(person); } } }