205 lines
8.0 KiB
C#
205 lines
8.0 KiB
C#
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;
|
|
}
|
|
#region 獲取進入雲科的所有資料
|
|
/// <summary>
|
|
/// 獲取進入雲科的所有資料
|
|
/// </summary>
|
|
// 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;
|
|
}
|
|
#endregion
|
|
|
|
#region 獲取進入的單獨地區的所有資料
|
|
/// <summary>
|
|
/// 獲取進入的單獨地區的所有資料
|
|
/// </summary>
|
|
/// <param name="id"> 哪個門口</param>
|
|
/// <returns></returns>
|
|
// 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 獲取時間內的車輛
|
|
/// <summary>
|
|
/// 獲取時間內的車輛
|
|
/// </summary>
|
|
/// <param name="id">位置名稱</param>
|
|
/// <param name="start_time">起始時間</param>
|
|
/// <param name="end_time">結束時間</param>
|
|
/// <returns></returns>
|
|
[HttpGet("location_name_1_-{id}-start_time-{start_time}-end_time-{end_time}")]
|
|
public async Task<IEnumerable<Yuntech_in_car_table>> GetYuntech_in_car_table_date(string id,DateTime start_time, DateTime end_time)
|
|
{
|
|
|
|
var in_car_table = await (from c in _context.yuntech_in_car_table
|
|
where c.location == id
|
|
where c.in_time >= start_time
|
|
where c.in_time <= end_time
|
|
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 透過車牌號碼搜尋所有資料
|
|
/// <summary>
|
|
/// 透過車牌號碼搜尋所有資料
|
|
/// </summary>
|
|
/// <param name="id">車牌號碼 ex:ABC4321</param>
|
|
/// <returns></returns>
|
|
[HttpGet("license_plate_number-{id}")]
|
|
public async Task<IEnumerable<Yuntech_in_car_table>> Getlicense_plate_number(string id)
|
|
{
|
|
|
|
var in_car_table = await (from c in _context.yuntech_in_car_table
|
|
where c.license_plate_number == 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 獲取進入的單獨地區的單筆資料
|
|
/// <summary>
|
|
/// 獲取進入的單獨地區的單筆資料
|
|
/// </summary>
|
|
/// <param name="id">地區</param>
|
|
/// <param name="time">進入時間 ex:2024-02-05T12:21:48.395Z</param>
|
|
/// <returns></returns>
|
|
// GET: api/Yuntech_in_car_table/5
|
|
[HttpGet("location_name-{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 new Yuntech_in_car_table
|
|
{
|
|
license_plate_number= c.license_plate_number,
|
|
in_time = c.in_time,
|
|
out_time = c.out_time,
|
|
car_img = c.car_img,
|
|
location = c.location,
|
|
}).FirstAsync();
|
|
|
|
|
|
return in_car_table;
|
|
}
|
|
#endregion
|
|
|
|
|
|
|
|
#region 新增資料
|
|
/// <summary>
|
|
/// 新增進入雲科的車輛資料
|
|
/// </summary>
|
|
/// <param name="yuntech_in_car_table"></param>
|
|
/// <returns></returns>
|
|
// 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);
|
|
}
|
|
#endregion
|
|
|
|
|
|
private bool Yuntech_in_car_tableExists(DateTime? id)
|
|
{
|
|
return (_context.yuntech_in_car_table?.Any(e => e.in_time == id)).GetValueOrDefault();
|
|
}
|
|
}
|
|
}
|