新增 雲科出去車輛post的api 及 刪除指定車輛的api
This commit is contained in:
parent
e92347e5fa
commit
e16bd91350
|
@ -257,11 +257,12 @@ namespace Parking_space_WebAPI.Controllers
|
||||||
{
|
{
|
||||||
return Problem("Entity set 'SqlContext.yuntech_in_car_table' is null.");
|
return Problem("Entity set 'SqlContext.yuntech_in_car_table' is null.");
|
||||||
}
|
}
|
||||||
_context.yuntech_in_car_table.Add(yuntech_in_car_table);
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
yuntech_in_car_table.in_time = DateTime.Now;
|
yuntech_in_car_table.in_time = DateTime.Now;
|
||||||
yuntech_in_car_table.out_time = null;
|
yuntech_in_car_table.out_time = null;
|
||||||
|
_context.yuntech_in_car_table.Add(yuntech_in_car_table);
|
||||||
await _context.SaveChangesAsync();
|
await _context.SaveChangesAsync();
|
||||||
}
|
}
|
||||||
catch (DbUpdateException)
|
catch (DbUpdateException)
|
||||||
|
@ -281,6 +282,75 @@ namespace Parking_space_WebAPI.Controllers
|
||||||
#endregion
|
#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("out_car")]
|
||||||
|
public async Task<ActionResult<Yuntech_in_car_table>> PostYuntech_out_car_table(Yuntech_in_car_table yuntech_out_car_table)
|
||||||
|
{
|
||||||
|
if (_context.yuntech_in_car_table == null)
|
||||||
|
{
|
||||||
|
return Problem("Entity set 'SqlContext.yuntech_in_car_table' is null.");
|
||||||
|
}
|
||||||
|
var license_plate_number = yuntech_out_car_table.license_plate_number;
|
||||||
|
var out_car_img = yuntech_out_car_table.out_car_img;
|
||||||
|
var in_car_data = await(from c in _context.yuntech_in_car_table
|
||||||
|
where c.license_plate_number == license_plate_number
|
||||||
|
where c.out_time ==null
|
||||||
|
orderby c.in_time descending
|
||||||
|
select c).FirstOrDefaultAsync();
|
||||||
|
if (in_car_data != null)
|
||||||
|
{
|
||||||
|
// 处理找到记录的情况
|
||||||
|
_context.yuntech_in_car_table.Remove(in_car_data);
|
||||||
|
await _context.SaveChangesAsync();
|
||||||
|
in_car_data.out_time = DateTime.Now;
|
||||||
|
in_car_data.out_car_img = out_car_img;
|
||||||
|
_context.yuntech_in_car_table.Add(in_car_data);
|
||||||
|
await _context.SaveChangesAsync();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// 处理未找到记录的情况
|
||||||
|
await _context.SaveChangesAsync();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
return Ok();
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region 刪除資料
|
||||||
|
/// <summary>
|
||||||
|
/// 刪除指定資料
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="license_plate_number">車牌號碼</param>
|
||||||
|
/// <param name="time">資料新增時間</param>
|
||||||
|
/// <returns></returns>
|
||||||
|
[HttpDelete("license_plate_number-{license_plate_number}-time-{time}")]
|
||||||
|
public async Task<IActionResult> Deletein_car_table(string license_plate_number, DateTime time)
|
||||||
|
{
|
||||||
|
var in_car_table = await (from c in _context.yuntech_in_car_table
|
||||||
|
where c.license_plate_number == license_plate_number
|
||||||
|
where c.in_time == time
|
||||||
|
|
||||||
|
select c).FirstAsync();
|
||||||
|
|
||||||
|
|
||||||
|
_context.yuntech_in_car_table.Remove(in_car_table);
|
||||||
|
await _context.SaveChangesAsync();
|
||||||
|
|
||||||
|
return NoContent();
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
|
|
||||||
private bool Yuntech_in_car_tableExists(DateTime? id)
|
private bool Yuntech_in_car_tableExists(DateTime? id)
|
||||||
{
|
{
|
||||||
return (_context.yuntech_in_car_table?.Any(e => e.in_time == id)).GetValueOrDefault();
|
return (_context.yuntech_in_car_table?.Any(e => e.in_time == id)).GetValueOrDefault();
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
{
|
{
|
||||||
public string? license_plate_number { get; set; }
|
public string? license_plate_number { get; set; }
|
||||||
public string? car_img { get; set; }
|
public string? car_img { get; set; }
|
||||||
|
public string? out_car_img { get; set; }
|
||||||
public string? location { get; set; }
|
public string? location { get; set; }
|
||||||
public DateTime? in_time { get; set; }
|
public DateTime? in_time { get; set; }
|
||||||
public DateTime? out_time { get; set; }
|
public DateTime? out_time { get; set; }
|
||||||
|
|
Loading…
Reference in New Issue
Block a user