From 38a921067388b7d5cb9f4e1f937394cb57fb7aa4 Mon Sep 17 00:00:00 2001 From: github-cloudlabsuser-2089 <169064114+github-cloudlabsuser-2089@users.noreply.github.com> Date: Wed, 29 May 2024 12:21:47 +0000 Subject: [PATCH 1/4] Create deploy.json --- deploy.json | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 deploy.json diff --git a/deploy.json b/deploy.json new file mode 100644 index 00000000..3f27d489 --- /dev/null +++ b/deploy.json @@ -0,0 +1,53 @@ +{ + "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#", + "contentVersion": "1.0.0.0", + "parameters": { + "webAppName": { + "type": "string", + "defaultValue": "ContactDatabaseWebApp", + "metadata": { + "description": "Name for the Web App" + } + }, + "hostingPlanName": { + "type": "string", + "defaultValue": "ContactDatabaseServicePlan", + "metadata": { + "description": "Name for the App Service plan" + } + }, + "skuName": { + "type": "string", + "defaultValue": "F1", + "metadata": { + "description": "The SKU of App Service Plan" + } + } + }, + "resources": [ + { + "type": "Microsoft.Web/serverfarms", + "apiVersion": "2020-06-01", + "name": "[parameters('hostingPlanName')]", + "location": "[resourceGroup().location]", + "sku": { + "name": "[parameters('skuName')]" + }, + "properties": { + "name": "[parameters('hostingPlanName')]" + } + }, + { + "type": "Microsoft.Web/sites", + "apiVersion": "2020-06-01", + "name": "[parameters('webAppName')]", + "location": "[resourceGroup().location]", + "dependsOn": [ + "[resourceId('Microsoft.Web/serverfarms', parameters('hostingPlanName'))]" + ], + "properties": { + "serverFarmId": "[resourceId('Microsoft.Web/serverfarms', parameters('hostingPlanName'))]" + } + } + ] +} From 25d4d5e644ef28a6d76c9519865b16ccaab316d5 Mon Sep 17 00:00:00 2001 From: github-cloudlabsuser-2089 <169064114+github-cloudlabsuser-2089@users.noreply.github.com> Date: Wed, 29 May 2024 12:22:53 +0000 Subject: [PATCH 2/4] Create deploy.parameters.json --- deploy.parameters.json | 53 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 deploy.parameters.json diff --git a/deploy.parameters.json b/deploy.parameters.json new file mode 100644 index 00000000..3f27d489 --- /dev/null +++ b/deploy.parameters.json @@ -0,0 +1,53 @@ +{ + "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#", + "contentVersion": "1.0.0.0", + "parameters": { + "webAppName": { + "type": "string", + "defaultValue": "ContactDatabaseWebApp", + "metadata": { + "description": "Name for the Web App" + } + }, + "hostingPlanName": { + "type": "string", + "defaultValue": "ContactDatabaseServicePlan", + "metadata": { + "description": "Name for the App Service plan" + } + }, + "skuName": { + "type": "string", + "defaultValue": "F1", + "metadata": { + "description": "The SKU of App Service Plan" + } + } + }, + "resources": [ + { + "type": "Microsoft.Web/serverfarms", + "apiVersion": "2020-06-01", + "name": "[parameters('hostingPlanName')]", + "location": "[resourceGroup().location]", + "sku": { + "name": "[parameters('skuName')]" + }, + "properties": { + "name": "[parameters('hostingPlanName')]" + } + }, + { + "type": "Microsoft.Web/sites", + "apiVersion": "2020-06-01", + "name": "[parameters('webAppName')]", + "location": "[resourceGroup().location]", + "dependsOn": [ + "[resourceId('Microsoft.Web/serverfarms', parameters('hostingPlanName'))]" + ], + "properties": { + "serverFarmId": "[resourceId('Microsoft.Web/serverfarms', parameters('hostingPlanName'))]" + } + } + ] +} From bfe19224c49da7ea9983a5a0c47b1a9766f9698d Mon Sep 17 00:00:00 2001 From: github-cloudlabsuser-2089 <169064114+github-cloudlabsuser-2089@users.noreply.github.com> Date: Wed, 29 May 2024 13:02:11 +0000 Subject: [PATCH 3/4] Add or update the Azure App Service build and deployment workflow config --- .../master_contactdatabasewebapp-hpc.yml | 66 +++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 .github/workflows/master_contactdatabasewebapp-hpc.yml diff --git a/.github/workflows/master_contactdatabasewebapp-hpc.yml b/.github/workflows/master_contactdatabasewebapp-hpc.yml new file mode 100644 index 00000000..f1d54cd7 --- /dev/null +++ b/.github/workflows/master_contactdatabasewebapp-hpc.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 - ContactDatabaseWebApp-HPC + +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_BA4DA61F4EA14D129B7416127446A5F8 }} + tenant-id: ${{ secrets.AZUREAPPSERVICE_TENANTID_26A209A144934B8F8C0EFB0090E403D3 }} + subscription-id: ${{ secrets.AZUREAPPSERVICE_SUBSCRIPTIONID_6E5C027AE78E46F5B4B28E2ACAC8B2B3 }} + + - name: Deploy to Azure Web App + id: deploy-to-webapp + uses: azure/webapps-deploy@v2 + with: + app-name: 'ContactDatabaseWebApp-HPC' + slot-name: 'Production' + package: . + \ No newline at end of file From 6f4a7cb307f49acbfe278e296b8cd66c5ae6b2ce Mon Sep 17 00:00:00 2001 From: github-cloudlabsuser-2089 <169064114+github-cloudlabsuser-2089@users.noreply.github.com> Date: Tue, 18 Jun 2024 08:25:19 +0000 Subject: [PATCH 4/4] Update UserController.cs --- Controllers/UserController.cs | 97 ++++++++++++++++++++++++++++------- 1 file changed, 78 insertions(+), 19 deletions(-) diff --git a/Controllers/UserController.cs b/Controllers/UserController.cs index f9ecbda2..52678dab 100644 --- a/Controllers/UserController.cs +++ b/Controllers/UserController.cs @@ -11,56 +11,115 @@ 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 + try + { + // Add user to the list + userlist.Add(user); + // Redirect to the Index view after successful addition + return RedirectToAction("Index"); + } + catch + { + // Return the same view with the user object in case of an error + return View(user); + } } - + + // 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] + [HttpPost] public ActionResult Edit(int id, User user) { - // This method is responsible for handling the HTTP POST request to update an existing user with the specified ID. - // It receives user input from the form submission and updates the corresponding user's information in the userlist. - // 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. + try + { + var userToUpdate = userlist.FirstOrDefault(u => u.Id == id); + if (userToUpdate == null) + { + return HttpNotFound(); + } + + // Update the user details here + userToUpdate.Name = user.Name; + userToUpdate.Email = user.Email; + userToUpdate.Age = user.Age; + + return RedirectToAction("Index"); + } + catch + { + return View(user); + } } - + + // 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 + try + { + var userToDelete = userlist.FirstOrDefault(u => u.Id == id); + if (userToDelete != null) + { + userlist.Remove(userToDelete); + } + return RedirectToAction("Index"); + } + catch + { + return View(); + } } + } }