You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
73 lines
1.8 KiB
73 lines
1.8 KiB
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<WeatherForecastController> _logger;
|
|
|
|
public WeatherForecastController(
|
|
AppDataConnection connection
|
|
,ILogger<WeatherForecastController> logger)
|
|
{
|
|
_connection = connection;
|
|
_logger = logger;
|
|
}
|
|
|
|
|
|
|
|
[HttpGet]
|
|
public Task<Part[]> ListUser()
|
|
{
|
|
return _connection.Part.ToArrayAsync();
|
|
}
|
|
|
|
[HttpGet("{id}")]
|
|
public async Task<Part?> 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<int> DeleteUser(int id)
|
|
{
|
|
return _connection.Part.Where(person => person.Id == id).DeleteAsync();
|
|
}
|
|
|
|
[HttpPut]
|
|
public Task<int> UpdateUser(Part person)
|
|
{
|
|
return _connection.UpdateAsync(person);
|
|
}
|
|
|
|
[HttpPatch("{id}/new-name")]
|
|
public Task<int> UpdateUserName(int id, string newName)
|
|
{
|
|
return _connection.Part.Where(person => person.Id == id)
|
|
.Set(person => person.Name, newName)
|
|
.UpdateAsync();
|
|
}
|
|
|
|
[HttpPost]
|
|
public Task<int> InsertUser(Part person)
|
|
{
|
|
return _connection.InsertAsync(person);
|
|
}
|
|
|
|
}
|
|
}
|
|
|