From e37076d2a45dee14f12c731633ed024eed86a5a3 Mon Sep 17 00:00:00 2001 From: github-cloudlabsuser-721 <167430410+github-cloudlabsuser-721@users.noreply.github.com> Date: Wed, 8 May 2024 03:34:02 +0000 Subject: [PATCH 1/6] Add or update the Azure App Service build and deployment workflow config --- .github/workflows/master_contactdatabase.yml | 66 ++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 .github/workflows/master_contactdatabase.yml diff --git a/.github/workflows/master_contactdatabase.yml b/.github/workflows/master_contactdatabase.yml new file mode 100644 index 00000000..1d323dc3 --- /dev/null +++ b/.github/workflows/master_contactdatabase.yml @@ -0,0 +1,66 @@ +# Docs for the Azure Web Apps Deploy action: https://github.com/Azure/webapps-deploy +# More GitHub Actions for Azure: https://github.com/Azure/actions + +name: Build and deploy ASP app to Azure Web App - ContactDatabase + +on: + push: + branches: + - master + workflow_dispatch: + +jobs: + build: + runs-on: windows-latest + + steps: + - uses: actions/checkout@v4 + + - name: Setup MSBuild path + uses: microsoft/setup-msbuild@v1.0.2 + + - name: Setup NuGet + uses: NuGet/setup-nuget@v1.0.5 + + - name: Restore NuGet packages + run: nuget restore + + - name: Publish to folder + run: msbuild /nologo /verbosity:m /t:Build /t:pipelinePreDeployCopyAllFilesToOneFolder /p:_PackageTempDir="\published\" + + - name: Upload artifact for deployment job + uses: actions/upload-artifact@v3 + with: + name: ASP-app + path: '/published/**' + + deploy: + runs-on: windows-latest + needs: build + environment: + name: 'Production' + url: ${{ steps.deploy-to-webapp.outputs.webapp-url }} + permissions: + id-token: write #This is required for requesting the JWT + + steps: + - name: Download artifact from build job + uses: actions/download-artifact@v3 + with: + name: ASP-app + + - name: Login to Azure + uses: azure/login@v1 + with: + client-id: ${{ secrets.AZUREAPPSERVICE_CLIENTID_EE81D81FF43E46B7BCCB09C9132C6C74 }} + tenant-id: ${{ secrets.AZUREAPPSERVICE_TENANTID_362D8DE799534C58B9C8E5B27DED6E26 }} + subscription-id: ${{ secrets.AZUREAPPSERVICE_SUBSCRIPTIONID_97C93876D5774F3C9119269003F3BD28 }} + + - name: Deploy to Azure Web App + id: deploy-to-webapp + uses: azure/webapps-deploy@v2 + with: + app-name: 'ContactDatabase' + slot-name: 'Production' + package: . + \ No newline at end of file From e8279a61784be6b83a8a287dc19931f64a5c91ba Mon Sep 17 00:00:00 2001 From: "github_cloudlabsuser_721@cloudlabsaiuser.com" Date: Wed, 8 May 2024 03:40:30 +0000 Subject: [PATCH 2/6] test --- CRUD application 2.csproj | 24 +++++++++++---- CRUD application 2.sln | 10 ++++-- Controllers/UserController.cs | 52 +++++++++++++++++++++++++++----- Web.config | 2 +- deploy.json | 57 +++++++++++++++++++++++++++++++++++ deploy.parameters.json | 35 +++++++++++++++++++++ packages.config | 3 ++ 7 files changed, 167 insertions(+), 16 deletions(-) create mode 100644 deploy.json create mode 100644 deploy.parameters.json diff --git a/CRUD application 2.csproj b/CRUD application 2.csproj index 553546be..cf64e913 100644 --- a/CRUD application 2.csproj +++ b/CRUD application 2.csproj @@ -1,5 +1,6 @@  + @@ -45,10 +46,25 @@ 4 + + packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.2.0.1\lib\net45\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.dll + + + packages\NUnit.4.1.0\lib\net462\nunit.framework.dll + + + packages\NUnit.4.1.0\lib\net462\nunit.framework.legacy.dll + + + packages\System.Runtime.CompilerServices.Unsafe.4.5.3\lib\net461\System.Runtime.CompilerServices.Unsafe.dll + + + packages\System.Threading.Tasks.Extensions.4.5.4\lib\net461\System.Threading.Tasks.Extensions.dll + @@ -111,11 +127,6 @@ packages\Antlr.3.5.0.2\lib\Antlr3.Runtime.dll - - - packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.2.0.1\lib\net45\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.dll - - @@ -215,6 +226,7 @@ This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. + - + \ No newline at end of file diff --git a/CRUD application 2.sln b/CRUD application 2.sln index 98ddfc3a..79aebc94 100644 --- a/CRUD application 2.sln +++ b/CRUD application 2.sln @@ -1,10 +1,12 @@  Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio Version 16 -VisualStudioVersion = 16.0.33801.447 +# Visual Studio Version 17 +VisualStudioVersion = 17.9.34728.123 MinimumVisualStudioVersion = 10.0.40219.1 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CRUD application 2", "CRUD application 2.csproj", "{D44C1C21-0289-4DD0-B139-6825EE5C13B2}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UserController.Tests", "..\UserController.Tests\UserController.Tests.csproj", "{6637840B-9561-465F-8281-8C6C853170E8}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -15,6 +17,10 @@ Global {D44C1C21-0289-4DD0-B139-6825EE5C13B2}.Debug|Any CPU.Build.0 = Debug|Any CPU {D44C1C21-0289-4DD0-B139-6825EE5C13B2}.Release|Any CPU.ActiveCfg = Release|Any CPU {D44C1C21-0289-4DD0-B139-6825EE5C13B2}.Release|Any CPU.Build.0 = Release|Any CPU + {6637840B-9561-465F-8281-8C6C853170E8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {6637840B-9561-465F-8281-8C6C853170E8}.Debug|Any CPU.Build.0 = Debug|Any CPU + {6637840B-9561-465F-8281-8C6C853170E8}.Release|Any CPU.ActiveCfg = Release|Any CPU + {6637840B-9561-465F-8281-8C6C853170E8}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/Controllers/UserController.cs b/Controllers/UserController.cs index f9ecbda2..16a4e28e 100644 --- a/Controllers/UserController.cs +++ b/Controllers/UserController.cs @@ -11,34 +11,51 @@ public class UserController : Controller public ActionResult Index() { // Implement the Index method here + return View(userlist); } - + // GET: User/Details/5 public ActionResult Details(int id) { // Implement the details method here + var user = userlist.FirstOrDefault(u => u.Id == id); + if (user == null) + { + return HttpNotFound(); + } + return View(user); } - + // GET: User/Create public ActionResult Create() { //Implement the Create method here + + return View(); } - + // POST: User/Create [HttpPost] public ActionResult Create(User user) { // Implement the Create method (POST) here + userlist.Add(user); + return RedirectToAction("Index"); } - + // GET: User/Edit/5 public ActionResult Edit(int id) { // This method is responsible for displaying the view to edit an existing user with the specified ID. // It retrieves the user from the userlist based on the provided ID and passes it to the Edit view. + var user = userlist.FirstOrDefault(u => u.Id == id); + if (user == null) + { + return HttpNotFound(); + } + return View(user); } - + // POST: User/Edit/5 [HttpPost] public ActionResult Edit(int id, User user) @@ -48,19 +65,40 @@ public ActionResult Edit(int id, User user) // If successful, it redirects to the Index action to display the updated list of users. // If no user is found with the provided ID, it returns a HttpNotFoundResult. // If an error occurs during the process, it returns the Edit view to display any validation errors. + var existingUser = userlist.FirstOrDefault(u => u.Id == id); + if (existingUser == null) + { + return HttpNotFound(); + } + existingUser.Name = user.Name; + existingUser.Email = user.Email; + return RedirectToAction("Index"); } - + // GET: User/Delete/5 public ActionResult Delete(int id) { // Implement the Delete method here + var user = userlist.FirstOrDefault(u => u.Id == id); + if (user == null) + { + return HttpNotFound(); + } + return View(user); } - + // POST: User/Delete/5 [HttpPost] public ActionResult Delete(int id, FormCollection collection) { // Implement the Delete method (POST) here + var user = userlist.FirstOrDefault(u => u.Id == id); + if (user == null) + { + return HttpNotFound(); + } + userlist.Remove(user); + return RedirectToAction("Index"); } } } diff --git a/Web.config b/Web.config index d246aab1..8ce4f449 100644 --- a/Web.config +++ b/Web.config @@ -30,7 +30,7 @@ - + diff --git a/deploy.json b/deploy.json new file mode 100644 index 00000000..03352655 --- /dev/null +++ b/deploy.json @@ -0,0 +1,57 @@ +{ + "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#", + "contentVersion": "1.0.0.0", + "resources": [ + { + "type": "Microsoft.Web/sites", + "apiVersion": "2021-02-01", + "name": "[parameters('appName')]", + "location": "[parameters('location')]", + "properties": { + "serverFarmId": "[resourceId('Microsoft.Web/serverfarms', 'appServicePlanName')]" + }, + "dependsOn": [ + "[resourceId('Microsoft.Web/serverfarms', 'appServicePlanName')]" + ] + }, + { + "type": "Microsoft.Web/serverfarms", + "apiVersion": "2021-02-01", + "name": "appServicePlanName", + "location": "[parameters('location')]", + "sku": { + "name": "F1", + "tier": "Free", + "size": "F1", + "family": "F", + "capacity": 1 + } + }, + { + "type": "Microsoft.Sql/servers", + "apiVersion": "2021-02-01-preview", + "name": "[concat(parameters('appName'), '-sqlserver')]", + "location": "[parameters('location')]", + "properties": { + "administratorLogin": "[parameters('databaseUsername')]", + "administratorLoginPassword": "[parameters('databasePassword')]", + "version": "12.0" + } + }, + { + "type": "Microsoft.Sql/servers/databases", + "apiVersion": "2021-02-01-preview", + "name": "[concat(parameters('appName'), '-database')]", + "location": "[parameters('location')]", + "dependsOn": [ + "[resourceId('Microsoft.Sql/servers', concat(parameters('appName'), '-sqlserver'))]" + ], + "properties": { + "collation": "SQL_Latin1_General_CP1_CI_AS", + "edition": "Basic", + "maxSizeBytes": "1073741824", + "requestedServiceObjectiveName": "Basic" + } + } + ] +} diff --git a/deploy.parameters.json b/deploy.parameters.json new file mode 100644 index 00000000..eda10a1d --- /dev/null +++ b/deploy.parameters.json @@ -0,0 +1,35 @@ +{ + "parameters": { + "appName": { + "type": "string", + "metadata": { + "description": "ContactDatabase" + } + }, + "location": { + "type": "string", + "metadata": { + "description": "The Azure region where the resources will be deployed." + }, + "defaultValue": "[resourceGroup().location]" + }, + "databaseName": { + "type": "string", + "metadata": { + "description": "The name of the Contact Database." + } + }, + "databaseUsername": { + "type": "string", + "metadata": { + "description": "The username for the Contact Database." + } + }, + "databasePassword": { + "type": "securestring", + "metadata": { + "description": "The password for the Contact Database." + } + } +} +} \ No newline at end of file diff --git a/packages.config b/packages.config index 40f85c9e..cbfca4c5 100644 --- a/packages.config +++ b/packages.config @@ -13,5 +13,8 @@ + + + \ No newline at end of file From 55d9f7e9fa88aa42b41a331ef2c61efb5e9dcea0 Mon Sep 17 00:00:00 2001 From: "github_cloudlabsuser_721@cloudlabsaiuser.com" Date: Wed, 8 May 2024 04:13:42 +0000 Subject: [PATCH 3/6] remove the farm --- deploy.json | 18 +----------------- 1 file changed, 1 insertion(+), 17 deletions(-) diff --git a/deploy.json b/deploy.json index 03352655..8f6befb1 100644 --- a/deploy.json +++ b/deploy.json @@ -8,23 +8,7 @@ "name": "[parameters('appName')]", "location": "[parameters('location')]", "properties": { - "serverFarmId": "[resourceId('Microsoft.Web/serverfarms', 'appServicePlanName')]" - }, - "dependsOn": [ - "[resourceId('Microsoft.Web/serverfarms', 'appServicePlanName')]" - ] - }, - { - "type": "Microsoft.Web/serverfarms", - "apiVersion": "2021-02-01", - "name": "appServicePlanName", - "location": "[parameters('location')]", - "sku": { - "name": "F1", - "tier": "Free", - "size": "F1", - "family": "F", - "capacity": 1 + "serverFarmId": null } }, { From f7e656e7418639d3ecef7a9ee1f062c71d1c4799 Mon Sep 17 00:00:00 2001 From: github-cloudlabsuser-721 <167430410+github-cloudlabsuser-721@users.noreply.github.com> Date: Wed, 8 May 2024 04:21:52 +0000 Subject: [PATCH 4/6] Add or update the Azure App Service build and deployment workflow config --- .../workflows/dev_contactapplicationtest.yml | 57 +++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 .github/workflows/dev_contactapplicationtest.yml diff --git a/.github/workflows/dev_contactapplicationtest.yml b/.github/workflows/dev_contactapplicationtest.yml new file mode 100644 index 00000000..cef505bc --- /dev/null +++ b/.github/workflows/dev_contactapplicationtest.yml @@ -0,0 +1,57 @@ +# Docs for the Azure Web Apps Deploy action: https://github.com/Azure/webapps-deploy +# More GitHub Actions for Azure: https://github.com/Azure/actions + +name: Build and deploy ASP app to Azure Web App - ContactApplicationTest + +on: + push: + branches: + - dev + workflow_dispatch: + +jobs: + build: + runs-on: windows-latest + + steps: + - uses: actions/checkout@v4 + + - name: Setup MSBuild path + uses: microsoft/setup-msbuild@v1.0.2 + + - name: Setup NuGet + uses: NuGet/setup-nuget@v1.0.5 + + - name: Restore NuGet packages + run: nuget restore + + - name: Publish to folder + run: msbuild /nologo /verbosity:m /t:Build /t:pipelinePreDeployCopyAllFilesToOneFolder /p:_PackageTempDir="\published\" + + - name: Upload artifact for deployment job + uses: actions/upload-artifact@v3 + with: + name: ASP-app + path: '/published/**' + + deploy: + runs-on: windows-latest + needs: build + environment: + name: 'Production' + url: ${{ steps.deploy-to-webapp.outputs.webapp-url }} + + steps: + - name: Download artifact from build job + uses: actions/download-artifact@v3 + with: + name: ASP-app + + - name: Deploy to Azure Web App + id: deploy-to-webapp + uses: azure/webapps-deploy@v2 + with: + app-name: 'ContactApplicationTest' + slot-name: 'Production' + publish-profile: ${{ secrets.AZUREAPPSERVICE_PUBLISHPROFILE_AB7BFC6B72F94FA4A1860A5B28EDC4A0 }} + package: . From 23f2486a06f1b0e4435c379a11e5f5228d05932b Mon Sep 17 00:00:00 2001 From: "github_cloudlabsuser_721@cloudlabsaiuser.com" Date: Wed, 8 May 2024 04:28:12 +0000 Subject: [PATCH 5/6] add name --- deploy.parameters.json | 58 +++++++++++++++++++++--------------------- 1 file changed, 29 insertions(+), 29 deletions(-) diff --git a/deploy.parameters.json b/deploy.parameters.json index eda10a1d..bc1b7ca4 100644 --- a/deploy.parameters.json +++ b/deploy.parameters.json @@ -1,35 +1,35 @@ { "parameters": { - "appName": { - "type": "string", - "metadata": { - "description": "ContactDatabase" - } - }, - "location": { - "type": "string", - "metadata": { - "description": "The Azure region where the resources will be deployed." + "appName": { + "type": "string", + "metadata": { + "description": "ContactApplicationTest" + } }, - "defaultValue": "[resourceGroup().location]" - }, - "databaseName": { - "type": "string", - "metadata": { - "description": "The name of the Contact Database." - } - }, - "databaseUsername": { - "type": "string", - "metadata": { - "description": "The username for the Contact Database." - } - }, - "databasePassword": { - "type": "securestring", - "metadata": { - "description": "The password for the Contact Database." + "location": { + "type": "string", + "metadata": { + "description": "The Azure region where the resources will be deployed." + }, + "defaultValue": "[resourceGroup().location]" + }, + "databaseName": { + "type": "string", + "metadata": { + "description": "The name of the Contact Database." + } + }, + "databaseUsername": { + "type": "string", + "metadata": { + "description": "The username for the Contact Database." + } + }, + "databasePassword": { + "type": "securestring", + "metadata": { + "description": "The password for the Contact Database." + } } } -} } \ No newline at end of file From f122e0ae71f32be8f80003de8835a4d4bcb1ccc0 Mon Sep 17 00:00:00 2001 From: "github_cloudlabsuser_721@cloudlabsaiuser.com" Date: Wed, 8 May 2024 04:34:11 +0000 Subject: [PATCH 6/6] remove test --- CRUD application 2.sln | 6 ------ 1 file changed, 6 deletions(-) diff --git a/CRUD application 2.sln b/CRUD application 2.sln index 79aebc94..802ab0bd 100644 --- a/CRUD application 2.sln +++ b/CRUD application 2.sln @@ -5,8 +5,6 @@ VisualStudioVersion = 17.9.34728.123 MinimumVisualStudioVersion = 10.0.40219.1 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CRUD application 2", "CRUD application 2.csproj", "{D44C1C21-0289-4DD0-B139-6825EE5C13B2}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UserController.Tests", "..\UserController.Tests\UserController.Tests.csproj", "{6637840B-9561-465F-8281-8C6C853170E8}" -EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -17,10 +15,6 @@ Global {D44C1C21-0289-4DD0-B139-6825EE5C13B2}.Debug|Any CPU.Build.0 = Debug|Any CPU {D44C1C21-0289-4DD0-B139-6825EE5C13B2}.Release|Any CPU.ActiveCfg = Release|Any CPU {D44C1C21-0289-4DD0-B139-6825EE5C13B2}.Release|Any CPU.Build.0 = Release|Any CPU - {6637840B-9561-465F-8281-8C6C853170E8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {6637840B-9561-465F-8281-8C6C853170E8}.Debug|Any CPU.Build.0 = Debug|Any CPU - {6637840B-9561-465F-8281-8C6C853170E8}.Release|Any CPU.ActiveCfg = Release|Any CPU - {6637840B-9561-465F-8281-8C6C853170E8}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE