新增 雲科出去車輛post的api 及 刪除指定車輛的api

This commit is contained in:
leo890808 2024-04-30 14:53:22 +08:00
parent e92347e5fa
commit e16bd91350
2 changed files with 72 additions and 1 deletions

View File

@ -257,11 +257,12 @@ namespace Parking_space_WebAPI.Controllers
{
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;
_context.yuntech_in_car_table.Add(yuntech_in_car_table);
await _context.SaveChangesAsync();
}
catch (DbUpdateException)
@ -281,6 +282,75 @@ namespace Parking_space_WebAPI.Controllers
#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)
{
return (_context.yuntech_in_car_table?.Any(e => e.in_time == id)).GetValueOrDefault();

View File

@ -4,6 +4,7 @@
{
public string? license_plate_number { get; set; }
public string? car_img { get; set; }
public string? out_car_img { get; set; }
public string? location { get; set; }
public DateTime? in_time { get; set; }
public DateTime? out_time { get; set; }