From 03019b3900cba63f247dce18c2aa075b74ede0e1 Mon Sep 17 00:00:00 2001 From: Your Name Date: Sat, 15 Apr 2023 13:17:27 +0700 Subject: [PATCH 1/4] 5 mlab --- 20230415.3/w230415/CinemaHall.cs | 22 ++++ 20230415.3/w230415/Hall.cs | 104 ++++++++++++++++++ 20230415.3/w230415/HallPlace.cs | 15 +++ 20230415.3/w230415/w230415.sln | 25 +++++ 20230415.3/w230415/w230415_classes.csproj | 13 +++ 20230415.3/w230415_console/Program.cs | 21 ++++ .../w230415_console/w230415_console.csproj | 14 +++ 7 files changed, 214 insertions(+) create mode 100644 20230415.3/w230415/CinemaHall.cs create mode 100644 20230415.3/w230415/Hall.cs create mode 100644 20230415.3/w230415/HallPlace.cs create mode 100644 20230415.3/w230415/w230415.sln create mode 100644 20230415.3/w230415/w230415_classes.csproj create mode 100644 20230415.3/w230415_console/Program.cs create mode 100644 20230415.3/w230415_console/w230415_console.csproj diff --git a/20230415.3/w230415/CinemaHall.cs b/20230415.3/w230415/CinemaHall.cs new file mode 100644 index 0000000..065f042 --- /dev/null +++ b/20230415.3/w230415/CinemaHall.cs @@ -0,0 +1,22 @@ +namespace w230415_classes +{ + public class CinemaHall : Hall + { + public CinemaHall() + { + int iW = 10; + int iH = 3; + for (int iX = 0; iX < iW; iX++) + { + for (int iY = 0; iY < iH; iY++) + { + HallPlaceList.Add(new HallPlace() + { + SeatPosition = iX, + SeatRow = iY + }); + } + } + } + } +} diff --git a/20230415.3/w230415/Hall.cs b/20230415.3/w230415/Hall.cs new file mode 100644 index 0000000..a36051f --- /dev/null +++ b/20230415.3/w230415/Hall.cs @@ -0,0 +1,104 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace w230415_classes +{ + public class Hall + { + public string Name { get; set; } + + protected List HallPlaceList { get; set; } = new List(); + + + /// + /// Read [R] + /// + /// + public List GetNotBookedPlaceList() + { + List hpl = new List(); + foreach (var item in HallPlaceList) + { + if (item.FlagBooked) continue; + hpl.Add(item); + } + return hpl; + } + + /// + /// Read [R] + /// + /// + /// + /// + public HallPlace? ReadPlace(int iRow, int iPosition) + { + var el = HallPlaceList.FirstOrDefault(hp => hp.SeatPosition == iPosition && hp.SeatRow == iRow); + return el; + } + + + + /// + /// Update [U] + /// + /// + /// + /// + public bool BookPlace(int iRow, int iPosition) + { + var el = HallPlaceList.FirstOrDefault(hp => hp.SeatPosition == iPosition && hp.SeatRow == iRow); + if (el == null) + { + return false; + } + if (el.FlagBooked) + { + return false; + } + el.FlagBooked = true; + return true; + } + + /// + /// Create [C] + /// + /// + /// + /// + public bool AddPlace(int iRow, int iPosition) + { + var el = HallPlaceList.FirstOrDefault(hp => hp.SeatPosition == iPosition && hp.SeatRow == iRow); + if (el != null) + { + return false; + } + HallPlaceList.Add(new HallPlace() + { + SeatPosition = iPosition, + SeatRow = iRow, + }); + return true; + } + + /// + /// Delete [D] + /// + /// + /// + /// + public bool DeletePlace(int iRow, int iPosition) + { + var el = HallPlaceList.FirstOrDefault(hp => hp.SeatPosition == iPosition && hp.SeatRow == iRow); + if (el == null) + { + return false; + } + return HallPlaceList.Remove(el); + } + + } +} diff --git a/20230415.3/w230415/HallPlace.cs b/20230415.3/w230415/HallPlace.cs new file mode 100644 index 0000000..1005181 --- /dev/null +++ b/20230415.3/w230415/HallPlace.cs @@ -0,0 +1,15 @@ +namespace w230415_classes +{ + public class HallPlace + { + public HallPlace() + { + Uid = Guid.NewGuid().ToString("N"); + } + + public string Uid { get; set; } + public int SeatPosition { get; set; } + public int SeatRow { get; set; } + public bool FlagBooked { get; set; } + } +} \ No newline at end of file diff --git a/20230415.3/w230415/w230415.sln b/20230415.3/w230415/w230415.sln new file mode 100644 index 0000000..3810909 --- /dev/null +++ b/20230415.3/w230415/w230415.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.2.32616.157 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "w230415_classes", "w230415_classes.csproj", "{3B2A3797-78B5-42F6-9C7E-5F9F20838C3F}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {3B2A3797-78B5-42F6-9C7E-5F9F20838C3F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {3B2A3797-78B5-42F6-9C7E-5F9F20838C3F}.Debug|Any CPU.Build.0 = Debug|Any CPU + {3B2A3797-78B5-42F6-9C7E-5F9F20838C3F}.Release|Any CPU.ActiveCfg = Release|Any CPU + {3B2A3797-78B5-42F6-9C7E-5F9F20838C3F}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {819D4FAE-A124-443D-B564-39D533244A18} + EndGlobalSection +EndGlobal diff --git a/20230415.3/w230415/w230415_classes.csproj b/20230415.3/w230415/w230415_classes.csproj new file mode 100644 index 0000000..30d4703 --- /dev/null +++ b/20230415.3/w230415/w230415_classes.csproj @@ -0,0 +1,13 @@ + + + + net6.0 + enable + enable + + + + + + + diff --git a/20230415.3/w230415_console/Program.cs b/20230415.3/w230415_console/Program.cs new file mode 100644 index 0000000..ae28b44 --- /dev/null +++ b/20230415.3/w230415_console/Program.cs @@ -0,0 +1,21 @@ +using w230415_classes; + +namespace w230415_console +{ + internal class Program + { + static void Main(string[] args) + { + CinemaHall ch = new CinemaHall(); + h_Process(ch); + } + + private static void h_Process(CinemaHall ch) + { + foreach (var item in ch.GetNotBookedPlaceList()) + { + Console.WriteLine($"{item.SeatRow}/{item.SeatPosition}: {item.Uid}"); + } + } + } +} \ No newline at end of file diff --git a/20230415.3/w230415_console/w230415_console.csproj b/20230415.3/w230415_console/w230415_console.csproj new file mode 100644 index 0000000..cea817f --- /dev/null +++ b/20230415.3/w230415_console/w230415_console.csproj @@ -0,0 +1,14 @@ + + + + Exe + net6.0 + enable + enable + + + + + + + -- 2.30.2 From 9b74c6dbb30f2253bf3137f194817925d4ac36fb Mon Sep 17 00:00:00 2001 From: Your Name Date: Sat, 15 Apr 2023 13:53:20 +0700 Subject: [PATCH 2/4] webapi server --- 20230415.3/w230415/Hall.cs | 7 +- 20230415.3/w230415/HallPlace.cs | 6 +- 20230415.3/w230415/Intf/IHall.cs | 13 ++++ 20230415.3/w230415/Intf/IHallPlace.cs | 10 +++ 20230415.3/w230415/w230415.sln | 12 +++ 20230415.3/w230415/w230415_classes.csproj | 4 - 20230415.3/w230415_console/Program.cs | 7 +- .../Controllers/HallController.cs | 78 +++++++++++++++++++ 20230415.3/w230415_webapi/Program.cs | 34 ++++++++ .../Properties/launchSettings.json | 31 ++++++++ .../appsettings.Development.json | 8 ++ 20230415.3/w230415_webapi/appsettings.json | 9 +++ .../w230415_webapi/w230415_webapi.csproj | 17 ++++ 13 files changed, 224 insertions(+), 12 deletions(-) create mode 100644 20230415.3/w230415/Intf/IHall.cs create mode 100644 20230415.3/w230415/Intf/IHallPlace.cs create mode 100644 20230415.3/w230415_webapi/Controllers/HallController.cs create mode 100644 20230415.3/w230415_webapi/Program.cs create mode 100644 20230415.3/w230415_webapi/Properties/launchSettings.json create mode 100644 20230415.3/w230415_webapi/appsettings.Development.json create mode 100644 20230415.3/w230415_webapi/appsettings.json create mode 100644 20230415.3/w230415_webapi/w230415_webapi.csproj diff --git a/20230415.3/w230415/Hall.cs b/20230415.3/w230415/Hall.cs index a36051f..cc06a56 100644 --- a/20230415.3/w230415/Hall.cs +++ b/20230415.3/w230415/Hall.cs @@ -3,10 +3,11 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; +using w230415_classes.Intf; namespace w230415_classes { - public class Hall + public class Hall : IHall { public string Name { get; set; } @@ -17,7 +18,7 @@ namespace w230415_classes /// Read [R] /// /// - public List GetNotBookedPlaceList() + public IEnumerable GetNotBookedPlaceList() { List hpl = new List(); foreach (var item in HallPlaceList) @@ -34,7 +35,7 @@ namespace w230415_classes /// /// /// - public HallPlace? ReadPlace(int iRow, int iPosition) + public IHallPlace? ReadPlace(int iRow, int iPosition) { var el = HallPlaceList.FirstOrDefault(hp => hp.SeatPosition == iPosition && hp.SeatRow == iRow); return el; diff --git a/20230415.3/w230415/HallPlace.cs b/20230415.3/w230415/HallPlace.cs index 1005181..9307c26 100644 --- a/20230415.3/w230415/HallPlace.cs +++ b/20230415.3/w230415/HallPlace.cs @@ -1,6 +1,8 @@ -namespace w230415_classes +using w230415_classes.Intf; + +namespace w230415_classes { - public class HallPlace + public class HallPlace : IHallPlace { public HallPlace() { diff --git a/20230415.3/w230415/Intf/IHall.cs b/20230415.3/w230415/Intf/IHall.cs new file mode 100644 index 0000000..1b19efd --- /dev/null +++ b/20230415.3/w230415/Intf/IHall.cs @@ -0,0 +1,13 @@ +namespace w230415_classes.Intf +{ + public interface IHall + { + string Name { get; set; } + + bool AddPlace(int iRow, int iPosition); + bool BookPlace(int iRow, int iPosition); + bool DeletePlace(int iRow, int iPosition); + IEnumerable GetNotBookedPlaceList(); + IHallPlace? ReadPlace(int iRow, int iPosition); + } +} \ No newline at end of file diff --git a/20230415.3/w230415/Intf/IHallPlace.cs b/20230415.3/w230415/Intf/IHallPlace.cs new file mode 100644 index 0000000..c97af25 --- /dev/null +++ b/20230415.3/w230415/Intf/IHallPlace.cs @@ -0,0 +1,10 @@ +namespace w230415_classes.Intf +{ + public interface IHallPlace + { + bool FlagBooked { get; set; } + int SeatPosition { get; set; } + int SeatRow { get; set; } + string Uid { get; set; } + } +} \ No newline at end of file diff --git a/20230415.3/w230415/w230415.sln b/20230415.3/w230415/w230415.sln index 3810909..b2ee3d8 100644 --- a/20230415.3/w230415/w230415.sln +++ b/20230415.3/w230415/w230415.sln @@ -5,6 +5,10 @@ VisualStudioVersion = 17.2.32616.157 MinimumVisualStudioVersion = 10.0.40219.1 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "w230415_classes", "w230415_classes.csproj", "{3B2A3797-78B5-42F6-9C7E-5F9F20838C3F}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "w230415_console", "..\w230415_console\w230415_console.csproj", "{9A1651B3-A3D4-49ED-9257-419F42F66FF2}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "w230415_webapi", "..\w230415_webapi\w230415_webapi.csproj", "{465CAE58-3BB5-4933-8AB8-FE30DDCFB9C4}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -15,6 +19,14 @@ Global {3B2A3797-78B5-42F6-9C7E-5F9F20838C3F}.Debug|Any CPU.Build.0 = Debug|Any CPU {3B2A3797-78B5-42F6-9C7E-5F9F20838C3F}.Release|Any CPU.ActiveCfg = Release|Any CPU {3B2A3797-78B5-42F6-9C7E-5F9F20838C3F}.Release|Any CPU.Build.0 = Release|Any CPU + {9A1651B3-A3D4-49ED-9257-419F42F66FF2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {9A1651B3-A3D4-49ED-9257-419F42F66FF2}.Debug|Any CPU.Build.0 = Debug|Any CPU + {9A1651B3-A3D4-49ED-9257-419F42F66FF2}.Release|Any CPU.ActiveCfg = Release|Any CPU + {9A1651B3-A3D4-49ED-9257-419F42F66FF2}.Release|Any CPU.Build.0 = Release|Any CPU + {465CAE58-3BB5-4933-8AB8-FE30DDCFB9C4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {465CAE58-3BB5-4933-8AB8-FE30DDCFB9C4}.Debug|Any CPU.Build.0 = Debug|Any CPU + {465CAE58-3BB5-4933-8AB8-FE30DDCFB9C4}.Release|Any CPU.ActiveCfg = Release|Any CPU + {465CAE58-3BB5-4933-8AB8-FE30DDCFB9C4}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/20230415.3/w230415/w230415_classes.csproj b/20230415.3/w230415/w230415_classes.csproj index 30d4703..132c02c 100644 --- a/20230415.3/w230415/w230415_classes.csproj +++ b/20230415.3/w230415/w230415_classes.csproj @@ -6,8 +6,4 @@ enable - - - - diff --git a/20230415.3/w230415_console/Program.cs b/20230415.3/w230415_console/Program.cs index ae28b44..4408fa3 100644 --- a/20230415.3/w230415_console/Program.cs +++ b/20230415.3/w230415_console/Program.cs @@ -1,4 +1,5 @@ using w230415_classes; +using w230415_classes.Intf; namespace w230415_console { @@ -6,13 +7,13 @@ namespace w230415_console { static void Main(string[] args) { - CinemaHall ch = new CinemaHall(); + IHall ch = new CinemaHall(); h_Process(ch); } - private static void h_Process(CinemaHall ch) + private static void h_Process(IHall ch) { - foreach (var item in ch.GetNotBookedPlaceList()) + foreach (IHallPlace item in ch.GetNotBookedPlaceList()) { Console.WriteLine($"{item.SeatRow}/{item.SeatPosition}: {item.Uid}"); } diff --git a/20230415.3/w230415_webapi/Controllers/HallController.cs b/20230415.3/w230415_webapi/Controllers/HallController.cs new file mode 100644 index 0000000..d8d7e7a --- /dev/null +++ b/20230415.3/w230415_webapi/Controllers/HallController.cs @@ -0,0 +1,78 @@ +using Microsoft.AspNetCore.Mvc; +using w230415_classes.Intf; + +namespace w230415_webapi.Controllers +{ + [ApiController] + [Route("v1/hall")] + public class HallController : ControllerBase + { + private readonly IHall _hall; + + public HallController(IHall hall) + { + _hall = hall; + } + + [HttpGet(Name = "GetNotBookedPlaces")] + public IEnumerable GetNotBooked() + { + return _hall.GetNotBookedPlaceList(); + } + + [HttpGet("seat/{iRow}/{iPosition}", Name = "GetPlace")] + public IHallPlace GetHallPlace( + int iRow, + int iPosition) + { + var place = _hall.ReadPlace(iRow, iPosition); + Response.StatusCode = place != null ? 200 : 404; + return place; + } + + [HttpGet("seat", Name = "GetPlace by query params")] + public IHallPlace GetHallPlace2( + int iRow, + int iPosition) + { + var place = _hall.ReadPlace(iRow, iPosition); + Response.StatusCode = place != null ? 200 : 404; + return place; + } + + [HttpPost("seat", Name = "Add place by form params")] + public void AddHallPlace( + [FromForm] + int iRow, + [FromForm] + int iPosition) + { + bool result = _hall.AddPlace(iRow, iPosition); + Response.StatusCode = result ? 200 : 500; + } + + + + [HttpDelete("seat", Name = "Remove place by form params")] + public void RemoveHallPlace( + [FromHeader] + int iRow, + [FromHeader] + int iPosition) + { + bool result = _hall.DeletePlace(iRow, iPosition); + Response.StatusCode = result ? 200 : 500; + } + + [HttpPatch("seat/booking/{iRow}/{iPosition}", Name = "Set booking status by params")] + public void SetBooking( + int iRow, + int iPosition) + { + bool result = _hall.BookPlace(iRow, iPosition); + Response.StatusCode = result ? 200 : 500; + } + + + } +} \ No newline at end of file diff --git a/20230415.3/w230415_webapi/Program.cs b/20230415.3/w230415_webapi/Program.cs new file mode 100644 index 0000000..84218ff --- /dev/null +++ b/20230415.3/w230415_webapi/Program.cs @@ -0,0 +1,34 @@ +using w230415_classes; +using w230415_classes.Intf; + +namespace w230415_webapi +{ + public class Program + { + public static void Main(string[] args) + { + var builder = WebApplication.CreateBuilder(args); + + // Add services to the container. + var pHall = new CinemaHall(); + builder.Services.AddSingleton(pHall); + builder.Services.AddControllers(); + // Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle + builder.Services.AddEndpointsApiExplorer(); + builder.Services.AddSwaggerGen(); + + var app = builder.Build(); + + // Configure the HTTP request pipeline. + if (app.Environment.IsDevelopment()) + { + app.UseSwagger(); + app.UseSwaggerUI(); + } + + app.MapControllers(); + + app.Run(); + } + } +} \ No newline at end of file diff --git a/20230415.3/w230415_webapi/Properties/launchSettings.json b/20230415.3/w230415_webapi/Properties/launchSettings.json new file mode 100644 index 0000000..52dd947 --- /dev/null +++ b/20230415.3/w230415_webapi/Properties/launchSettings.json @@ -0,0 +1,31 @@ +{ + "$schema": "https://json.schemastore.org/launchsettings.json", + "iisSettings": { + "windowsAuthentication": false, + "anonymousAuthentication": true, + "iisExpress": { + "applicationUrl": "http://localhost:21569", + "sslPort": 0 + } + }, + "profiles": { + "w230415_webapi": { + "commandName": "Project", + "dotnetRunMessages": true, + "launchBrowser": true, + "launchUrl": "swagger", + "applicationUrl": "http://localhost:5095", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + }, + "IIS Express": { + "commandName": "IISExpress", + "launchBrowser": true, + "launchUrl": "swagger", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + } + } +} diff --git a/20230415.3/w230415_webapi/appsettings.Development.json b/20230415.3/w230415_webapi/appsettings.Development.json new file mode 100644 index 0000000..0c208ae --- /dev/null +++ b/20230415.3/w230415_webapi/appsettings.Development.json @@ -0,0 +1,8 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + } +} diff --git a/20230415.3/w230415_webapi/appsettings.json b/20230415.3/w230415_webapi/appsettings.json new file mode 100644 index 0000000..10f68b8 --- /dev/null +++ b/20230415.3/w230415_webapi/appsettings.json @@ -0,0 +1,9 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + }, + "AllowedHosts": "*" +} diff --git a/20230415.3/w230415_webapi/w230415_webapi.csproj b/20230415.3/w230415_webapi/w230415_webapi.csproj new file mode 100644 index 0000000..02a78eb --- /dev/null +++ b/20230415.3/w230415_webapi/w230415_webapi.csproj @@ -0,0 +1,17 @@ + + + + net6.0 + enable + enable + + + + + + + + + + + -- 2.30.2 From f690ecc527e8cdc7da39c5f0a69b1c38a8263b64 Mon Sep 17 00:00:00 2001 From: Your Name Date: Sat, 15 Apr 2023 14:13:59 +0700 Subject: [PATCH 3/4] webapi server --- 20230415.3/w230415/w230415.sln | 6 +++ 20230415.3/w230415_consoleapi/Program.cs | 42 +++++++++++++++++++ .../w230415_consoleapi.csproj | 18 ++++++++ 3 files changed, 66 insertions(+) create mode 100644 20230415.3/w230415_consoleapi/Program.cs create mode 100644 20230415.3/w230415_consoleapi/w230415_consoleapi.csproj diff --git a/20230415.3/w230415/w230415.sln b/20230415.3/w230415/w230415.sln index b2ee3d8..7ea15dd 100644 --- a/20230415.3/w230415/w230415.sln +++ b/20230415.3/w230415/w230415.sln @@ -9,6 +9,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "w230415_console", "..\w2304 EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "w230415_webapi", "..\w230415_webapi\w230415_webapi.csproj", "{465CAE58-3BB5-4933-8AB8-FE30DDCFB9C4}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "w230415_consoleapi", "..\w230415_consoleapi\w230415_consoleapi.csproj", "{96A7178E-082A-4E3B-A377-948D0B1E66DA}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -27,6 +29,10 @@ Global {465CAE58-3BB5-4933-8AB8-FE30DDCFB9C4}.Debug|Any CPU.Build.0 = Debug|Any CPU {465CAE58-3BB5-4933-8AB8-FE30DDCFB9C4}.Release|Any CPU.ActiveCfg = Release|Any CPU {465CAE58-3BB5-4933-8AB8-FE30DDCFB9C4}.Release|Any CPU.Build.0 = Release|Any CPU + {96A7178E-082A-4E3B-A377-948D0B1E66DA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {96A7178E-082A-4E3B-A377-948D0B1E66DA}.Debug|Any CPU.Build.0 = Debug|Any CPU + {96A7178E-082A-4E3B-A377-948D0B1E66DA}.Release|Any CPU.ActiveCfg = Release|Any CPU + {96A7178E-082A-4E3B-A377-948D0B1E66DA}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/20230415.3/w230415_consoleapi/Program.cs b/20230415.3/w230415_consoleapi/Program.cs new file mode 100644 index 0000000..e76b8c2 --- /dev/null +++ b/20230415.3/w230415_consoleapi/Program.cs @@ -0,0 +1,42 @@ +using Newtonsoft.Json; +using Newtonsoft.Json.Linq; +using w230415_classes; + +namespace w230415_consoleapi +{ + internal class Program + { + static void Main(string[] args) + { + h_Process(); + } + + private static void h_Process() + { + HttpClient client = new HttpClient(); + var res = client.GetAsync("http://localhost:5095/v1/hall").Result; + if (res.StatusCode == System.Net.HttpStatusCode.OK) + { + string sJson = res.Content.ReadAsStringAsync().Result; + //// 1. self + List? chList = JsonConvert.DeserializeObject>(sJson); + foreach (HallPlace item in chList) + { + Console.WriteLine($"{item.SeatRow}/{item.SeatPosition}: {item.Uid}"); + } + // 2. dynamic + //dynamic json = JsonConvert.DeserializeObject(sJson); + //foreach (dynamic item in json) + //{ + // Console.WriteLine($"{item.seatRow}/{item.seatPosition}: {item.uid}"); + //} + // 3. JToken + //JToken json = JsonConvert.DeserializeObject(sJson); + //foreach (JToken item in json) + //{ + // Console.WriteLine($"{item["seatRow"]}/{item["seatPosition"]}: {item["uid"]}"); + //} + } + } + } +} \ No newline at end of file diff --git a/20230415.3/w230415_consoleapi/w230415_consoleapi.csproj b/20230415.3/w230415_consoleapi/w230415_consoleapi.csproj new file mode 100644 index 0000000..7a634fa --- /dev/null +++ b/20230415.3/w230415_consoleapi/w230415_consoleapi.csproj @@ -0,0 +1,18 @@ + + + + Exe + net6.0 + enable + enable + + + + + + + + + + + -- 2.30.2 From f911c6cbbae5e231780859d91b8190fdfb50f970 Mon Sep 17 00:00:00 2001 From: Your Name Date: Sat, 15 Apr 2023 14:18:00 +0700 Subject: [PATCH 4/4] +postman --- .../webApp230415_hall.postman_collection.json | 212 ++++++++++++++++++ 1 file changed, 212 insertions(+) create mode 100644 20230415.3/webApp230415_hall.postman_collection.json diff --git a/20230415.3/webApp230415_hall.postman_collection.json b/20230415.3/webApp230415_hall.postman_collection.json new file mode 100644 index 0000000..15d81d4 --- /dev/null +++ b/20230415.3/webApp230415_hall.postman_collection.json @@ -0,0 +1,212 @@ +{ + "info": { + "_postman_id": "ed89b8b7-813e-4589-970c-0b6090d7e7cd", + "name": "webApp230415_hall", + "schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json", + "_exporter_id": "26683763" + }, + "item": [ + { + "name": "get not booked", + "request": { + "method": "GET", + "header": [], + "url": { + "raw": "{{baseurl}}/", + "host": [ + "{{baseurl}}" + ], + "path": [ + "" + ] + } + }, + "response": [] + }, + { + "name": "seat info", + "request": { + "method": "GET", + "header": [], + "url": { + "raw": "{{baseurl}}/seat/1/5", + "host": [ + "{{baseurl}}" + ], + "path": [ + "seat", + "1", + "5" + ] + } + }, + "response": [] + }, + { + "name": "seat add", + "request": { + "method": "POST", + "header": [], + "body": { + "mode": "formdata", + "formdata": [ + { + "key": "iRow", + "value": "1", + "type": "text" + }, + { + "key": "iPosition", + "value": "11", + "type": "text" + } + ] + }, + "url": { + "raw": "{{baseurl}}/seat", + "host": [ + "{{baseurl}}" + ], + "path": [ + "seat" + ] + } + }, + "response": [] + }, + { + "name": "seat de3lete", + "request": { + "method": "DELETE", + "header": [ + { + "key": "iRow", + "value": "1", + "type": "text" + }, + { + "key": "iPosition", + "value": "11", + "type": "text" + } + ], + "body": { + "mode": "formdata", + "formdata": [ + { + "key": "iRow", + "value": "1", + "type": "text", + "disabled": true + }, + { + "key": "iPosition", + "value": "11", + "type": "text", + "disabled": true + } + ] + }, + "url": { + "raw": "{{baseurl}}/seat", + "host": [ + "{{baseurl}}" + ], + "path": [ + "seat" + ] + } + }, + "response": [] + }, + { + "name": "seat booking", + "request": { + "method": "PATCH", + "header": [], + "body": { + "mode": "formdata", + "formdata": [ + { + "key": "iRow", + "value": "1", + "type": "text" + }, + { + "key": "iPosition", + "value": "11", + "type": "text" + } + ] + }, + "url": { + "raw": "{{baseurl}}/seat/booking/1/2", + "host": [ + "{{baseurl}}" + ], + "path": [ + "seat", + "booking", + "1", + "2" + ] + } + }, + "response": [] + }, + { + "name": "seat info query", + "request": { + "method": "GET", + "header": [], + "url": { + "raw": "{{baseurl}}/seat?iRow=1&iPosition=1", + "host": [ + "{{baseurl}}" + ], + "path": [ + "seat" + ], + "query": [ + { + "key": "iRow", + "value": "1" + }, + { + "key": "iPosition", + "value": "1" + } + ] + } + }, + "response": [] + } + ], + "event": [ + { + "listen": "prerequest", + "script": { + "type": "text/javascript", + "exec": [ + "" + ] + } + }, + { + "listen": "test", + "script": { + "type": "text/javascript", + "exec": [ + "" + ] + } + } + ], + "variable": [ + { + "key": "baseurl", + "value": "http://localhost:5095/v1/hall", + "type": "string" + } + ] +} \ No newline at end of file -- 2.30.2