新增從大暪口紀錄數據
This commit is contained in:
parent
f58be7970d
commit
53287bb390
123
WebApi_data_value/Controllers/Yuntech_in_car_tableController.cs
Normal file
123
WebApi_data_value/Controllers/Yuntech_in_car_tableController.cs
Normal file
@ -0,0 +1,123 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Microsoft.AspNetCore.Http;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using WebApi_data_value.Models;
|
||||||
|
using WebApi_data_value.Services;
|
||||||
|
using WebApi_data_value.ViewModel;
|
||||||
|
|
||||||
|
namespace WebApi_data_value.Controllers
|
||||||
|
{
|
||||||
|
[Route("api/[controller]")]
|
||||||
|
[ApiController]
|
||||||
|
public class Yuntech_in_car_tableController : ControllerBase
|
||||||
|
{
|
||||||
|
private readonly SqlContext _context;
|
||||||
|
|
||||||
|
public Yuntech_in_car_tableController(SqlContext context)
|
||||||
|
{
|
||||||
|
_context = context;
|
||||||
|
}
|
||||||
|
|
||||||
|
// GET: api/Yuntech_in_car_table
|
||||||
|
[HttpGet]
|
||||||
|
public async Task<ActionResult<IEnumerable<Yuntech_in_car_table>>> Getyuntech_in_car_table()
|
||||||
|
{
|
||||||
|
var in_car_table = await (from c in _context.yuntech_in_car_table
|
||||||
|
orderby c.in_time descending
|
||||||
|
select new Yuntech_in_car_table
|
||||||
|
{
|
||||||
|
license_plate_number = c.license_plate_number,
|
||||||
|
in_time = c.in_time,
|
||||||
|
out_time = c.out_time,
|
||||||
|
location = c.location,
|
||||||
|
}
|
||||||
|
).ToListAsync();
|
||||||
|
|
||||||
|
|
||||||
|
return in_car_table;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#region 獲取進入的單獨地區的所有資料
|
||||||
|
// GET: api/Yuntech_in_car_table/5
|
||||||
|
[HttpGet("location-{id}")]
|
||||||
|
public async Task<IEnumerable<Yuntech_in_car_table>> GetYuntech_in_car_table(string id)
|
||||||
|
{
|
||||||
|
var in_car_table = await (from c in _context.yuntech_in_car_table
|
||||||
|
where c.location == id
|
||||||
|
orderby c.in_time descending
|
||||||
|
select new Yuntech_in_car_table
|
||||||
|
{
|
||||||
|
license_plate_number = c.license_plate_number,
|
||||||
|
in_time = c.in_time,
|
||||||
|
out_time = c.out_time,
|
||||||
|
location = c.location,
|
||||||
|
}
|
||||||
|
).ToListAsync();
|
||||||
|
|
||||||
|
|
||||||
|
return in_car_table;
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region 獲取進入的單獨地區的所有資料
|
||||||
|
// GET: api/Yuntech_in_car_table/5
|
||||||
|
[HttpGet("location-{id}-time-{time}")]
|
||||||
|
public async Task<ActionResult<Yuntech_in_car_table>> One_data(string id, DateTime time)
|
||||||
|
{
|
||||||
|
var in_car_table = await (from c in _context.yuntech_in_car_table
|
||||||
|
where c.location == id
|
||||||
|
where c.in_time == time
|
||||||
|
select c).FirstAsync();
|
||||||
|
|
||||||
|
|
||||||
|
return in_car_table;
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// POST: api/Yuntech_in_car_table
|
||||||
|
// To protect from overposting attacks, see https://go.microsoft.com/fwlink/?linkid=2123754
|
||||||
|
[HttpPost]
|
||||||
|
public async Task<ActionResult<Yuntech_in_car_table>> PostYuntech_in_car_table(Yuntech_in_car_table yuntech_in_car_table)
|
||||||
|
{
|
||||||
|
if (_context.yuntech_in_car_table == null)
|
||||||
|
{
|
||||||
|
return Problem("Entity set 'SqlContext.yuntech_in_car_table' is null.");
|
||||||
|
}
|
||||||
|
_context.yuntech_in_car_table.Add(yuntech_in_car_table);
|
||||||
|
try
|
||||||
|
{
|
||||||
|
yuntech_in_car_table.in_time = DateTime.Now;
|
||||||
|
yuntech_in_car_table.out_time = null;
|
||||||
|
await _context.SaveChangesAsync();
|
||||||
|
}
|
||||||
|
catch (DbUpdateException)
|
||||||
|
{
|
||||||
|
if (Yuntech_in_car_tableExists(yuntech_in_car_table.in_time))
|
||||||
|
{
|
||||||
|
return Conflict();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return CreatedAtAction("GetYuntech_in_car_table", new { id = yuntech_in_car_table.in_time }, yuntech_in_car_table);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
private bool Yuntech_in_car_tableExists(DateTime? id)
|
||||||
|
{
|
||||||
|
return (_context.yuntech_in_car_table?.Any(e => e.in_time == id)).GetValueOrDefault();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
11
WebApi_data_value/Models/Yuntech_in_car_table.cs
Normal file
11
WebApi_data_value/Models/Yuntech_in_car_table.cs
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
namespace WebApi_data_value.Models
|
||||||
|
{
|
||||||
|
public class Yuntech_in_car_table
|
||||||
|
{
|
||||||
|
public string? license_plate_number { get; set; }
|
||||||
|
public string? car_img { get; set; }
|
||||||
|
public string? location { get; set; }
|
||||||
|
public DateTime? in_time { get; set; }
|
||||||
|
public DateTime? out_time { get; set; }
|
||||||
|
}
|
||||||
|
}
|
@ -17,8 +17,8 @@ builder.Services.AddCors();
|
|||||||
builder.Services.AddControllers();
|
builder.Services.AddControllers();
|
||||||
|
|
||||||
// 連線PostgreSQL資料庫
|
// 連線PostgreSQL資料庫
|
||||||
//var connectionString = "Server=140.125.20.183;UserID=postgres;password=EL404el404;Database=postgres;port=5432;Search Path=public;CommandTimeout=1800";
|
var connectionString = "Server=140.125.20.183;UserID=postgres;password=EL404el404;Database=postgres;port=5432;Search Path=public;CommandTimeout=1800";
|
||||||
var connectionString = "Server=127.0.0.1;UserID=postgres;password=EL404el404;Database=postgres;port=5432;Search Path=public;CommandTimeout=1800";
|
//var connectionString = "Server=127.0.0.1;UserID=postgres;password=EL404el404;Database=postgres;port=5432;Search Path=public;CommandTimeout=1800";
|
||||||
builder.Services.AddDbContext<SqlContext>(opt => opt.UseNpgsql(connectionString));
|
builder.Services.AddDbContext<SqlContext>(opt => opt.UseNpgsql(connectionString));
|
||||||
|
|
||||||
|
|
||||||
|
@ -46,6 +46,9 @@ namespace WebApi_data_value.Services
|
|||||||
// 演算法
|
// 演算法
|
||||||
public DbSet<Parking_space_algorithm> parking_space_algorithm { get; set; } = null!;
|
public DbSet<Parking_space_algorithm> parking_space_algorithm { get; set; } = null!;
|
||||||
|
|
||||||
|
//大門口
|
||||||
|
public DbSet<Yuntech_in_car_table> yuntech_in_car_table { get; set; } = null!;
|
||||||
|
|
||||||
|
|
||||||
protected override void OnModelCreating(ModelBuilder builder)
|
protected override void OnModelCreating(ModelBuilder builder)
|
||||||
{
|
{
|
||||||
@ -71,6 +74,7 @@ namespace WebApi_data_value.Services
|
|||||||
|
|
||||||
builder.Entity<Parking_space_algorithm>().HasKey(o => new { o.algorithm_serial_num }); //Primary Key
|
builder.Entity<Parking_space_algorithm>().HasKey(o => new { o.algorithm_serial_num }); //Primary Key
|
||||||
|
|
||||||
|
builder.Entity<Yuntech_in_car_table>().HasKey(o => new { o.in_time }); //Primary Key
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -22,6 +22,7 @@
|
|||||||
<PackageReference Include="JWT" Version="10.0.2" />
|
<PackageReference Include="JWT" Version="10.0.2" />
|
||||||
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="6.0.7" />
|
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="6.0.7" />
|
||||||
<PackageReference Include="Microsoft.AspNetCore.Authorization" Version="6.0.7" />
|
<PackageReference Include="Microsoft.AspNetCore.Authorization" Version="6.0.7" />
|
||||||
|
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="6.0.26" />
|
||||||
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="7.0.4" />
|
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="7.0.4" />
|
||||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="7.0.4">
|
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="7.0.4">
|
||||||
<PrivateAssets>all</PrivateAssets>
|
<PrivateAssets>all</PrivateAssets>
|
||||||
|
Loading…
Reference in New Issue
Block a user