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: . 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 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..802ab0bd 100644 --- a/CRUD application 2.sln +++ b/CRUD application 2.sln @@ -1,7 +1,7 @@  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 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..8f6befb1 --- /dev/null +++ b/deploy.json @@ -0,0 +1,41 @@ +{ + "$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": null + } + }, + { + "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..bc1b7ca4 --- /dev/null +++ b/deploy.parameters.json @@ -0,0 +1,35 @@ +{ + "parameters": { + "appName": { + "type": "string", + "metadata": { + "description": "ContactApplicationTest" + } + }, + "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