diff --git a/WebApi_data_value/Controllers/Yuntech_in_car_tableController.cs b/WebApi_data_value/Controllers/Yuntech_in_car_tableController.cs index abac20c..8171d4f 100644 --- a/WebApi_data_value/Controllers/Yuntech_in_car_tableController.cs +++ b/WebApi_data_value/Controllers/Yuntech_in_car_tableController.cs @@ -84,15 +84,15 @@ namespace WebApi_data_value.Controllers public async Task> 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(); + 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; @@ -108,7 +108,7 @@ namespace WebApi_data_value.Controllers /// 結束時間 /// [HttpGet("location_name_1_-{id}-start_time-{start_time}-end_time-{end_time}")] - public async Task> GetYuntech_in_car_table_date(string id,DateTime start_time, DateTime end_time) + public async Task> 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 @@ -170,7 +170,7 @@ namespace WebApi_data_value.Controllers where c.in_time == time select new Yuntech_in_car_table { - license_plate_number= c.license_plate_number, + license_plate_number = c.license_plate_number, in_time = c.in_time, out_time = c.out_time, car_img = c.car_img, @@ -197,12 +197,12 @@ namespace WebApi_data_value.Controllers DateTime DaysAgo = today.AddDays(-day); var dateValue = new List(); // 使用 for 迴圈逐日計算次數 - for (int i = 1;i<= day; i++) + for (int i = 1; i <= day; i++) { DateTime date_1 = DaysAgo; date_1 = date_1.AddDays(i); DateTime date_2 = DaysAgo; - date_2 = date_2.AddDays(i+1); + date_2 = date_2.AddDays(i + 1); var dailyCount = await _context.yuntech_in_car_table .Where(c => c.in_time >= date_1.Date) // 只選擇指定日期的資料 .Where(c => c.in_time <= date_2.Date) // 只選擇指定日期的資料 @@ -218,6 +218,27 @@ namespace WebApi_data_value.Controllers } #endregion + #region 尋找所有進出校園的地點 + /// + ///尋找所有進出校園的地點 + /// + /// + [HttpGet("location_name")] + public async Task> Get_in_Yuntech_location_name() + { + var location_name_table = await _context.yuntech_in_car_table + .GroupBy(c=>c.location) + .Select(group => new + { + location_name = group.Key, + }) + .ToListAsync(); + + + return location_name_table; + } + #endregion + #region 新增資料 /// diff --git a/WebApi_data_value/Program.cs b/WebApi_data_value/Program.cs index d8dc62b..c6e436a 100644 --- a/WebApi_data_value/Program.cs +++ b/WebApi_data_value/Program.cs @@ -17,8 +17,8 @@ builder.Services.AddCors(); builder.Services.AddControllers(); // 連線PostgreSQL資料庫 -//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=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"; builder.Services.AddDbContext(opt => opt.UseNpgsql(connectionString));