diff --git a/.github/workflows/master_contactdatabaseappabb.yml b/.github/workflows/master_contactdatabaseappabb.yml new file mode 100644 index 00000000..673cdad9 --- /dev/null +++ b/.github/workflows/master_contactdatabaseappabb.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 - contactDatabaseAppABB + +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_D3CC6CE549B84F2EA2047F1D86FB3393 }} + tenant-id: ${{ secrets.AZUREAPPSERVICE_TENANTID_5424CE301AE7477CAD2D2176BB8319DB }} + subscription-id: ${{ secrets.AZUREAPPSERVICE_SUBSCRIPTIONID_078963FFAD5947C4B3EA64744CDE0D60 }} + + - name: Deploy to Azure Web App + id: deploy-to-webapp + uses: azure/webapps-deploy@v2 + with: + app-name: 'contactDatabaseAppABB' + slot-name: 'Production' + package: . + \ No newline at end of file diff --git a/CRUD application 2.csproj b/CRUD application 2.csproj index 553546be..53b84bec 100644 --- a/CRUD application 2.csproj +++ b/CRUD application 2.csproj @@ -45,6 +45,9 @@ 4 + + packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.2.0.1\lib\net45\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.dll + @@ -111,11 +114,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 - - @@ -222,4 +220,4 @@ --> - + \ No newline at end of file diff --git a/CRUD application 2.sln b/CRUD application 2.sln index 98ddfc3a..2daa2c19 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.10.34916.146 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..49568782 100644 --- a/Controllers/UserController.cs +++ b/Controllers/UserController.cs @@ -10,26 +10,42 @@ public class UserController : Controller // GET: User public ActionResult Index() { - // Implement the Index method here + return View(userlist); } - + public ActionResult Search(string searchTerm) + { + var results = userlist.Where(u => u.Name.Contains(searchTerm)).ToList(); + return View(results); + } + // 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 + if (ModelState.IsValid) + { + userlist.Add(user); + return RedirectToAction("Index"); + } + + return View(user); } // GET: User/Edit/5 @@ -37,6 +53,12 @@ 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 @@ -48,19 +70,51 @@ 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. + // Find the user to be updated + var userToUpdate = userlist.FirstOrDefault(u => u.Id == id); + if (userToUpdate == null) + { + return HttpNotFound(); + } + + // Check if the model state is valid + if (ModelState.IsValid) + { + // Update the user's details + userToUpdate.Name = user.Name; + userToUpdate.Email = user.Email; + + // Redirect to the Index view + return RedirectToAction("Index"); + } + + // If model state is not valid, return the Edit view to display any validation errors + 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 + var user = userlist.FirstOrDefault(u => u.Id == id); + if (user == null) + { + return HttpNotFound(); + } + + userlist.Remove(user); + return RedirectToAction("Index"); } } } diff --git a/Views/User/Index.cshtml b/Views/User/Index.cshtml index 543196b1..e2da2dcb 100644 --- a/Views/User/Index.cshtml +++ b/Views/User/Index.cshtml @@ -5,10 +5,18 @@ }

Index

+@using (Html.BeginForm("Index", "User", FormMethod.Get)) +{ +

+ Find by name: @Html.TextBox("searchString") + +

+}

@Html.ActionLink("Create New", "Create")

+ -@foreach (var item in Model) { - - - - - -} + @foreach (var item in Model) + { + + + + + + }
@@ -20,20 +28,21 @@
- @Html.DisplayFor(modelItem => item.Name) - - @Html.DisplayFor(modelItem => item.Email) - - @Html.ActionLink("Edit", "Edit", new { id=item.Id }) | - @Html.ActionLink("Details", "Details", new { id=item.Id }) | - @Html.ActionLink("Delete", "Delete", new { id=item.Id }) -
+ @Html.DisplayFor(modelItem => item.Name) + + @Html.DisplayFor(modelItem => item.Email) + + @Html.ActionLink("Edit", "Edit", new { id = item.Id }) | + @Html.ActionLink("Details", "Details", new { id = item.Id }) | + @Html.ActionLink("Delete", "Delete", new { id = item.Id }) +
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..0f16383b --- /dev/null +++ b/deploy.json @@ -0,0 +1,129 @@ +{ + "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#", + "contentVersion": "1.0.0.0", + "parameters": { + "webAppName": { + "type": "string", + "defaultValue": "myWebApp", + "metadata": { + "description": "Name for the Web App" + } + }, + "hostingPlanName": { + "type": "string", + "defaultValue": "myHostingPlan", + "metadata": { + "description": "Name for the Hosting Plan" + } + } + }, + "resources": [ + { + "type": "Microsoft.Web/serverfarms", + "apiVersion": "2021-01-01", + "name": "[parameters('hostingPlanName')]", + "location": "[resourceGroup().location]", + "sku": { + "name": "F1", + "capacity": 1 + }, + "kind": "app" + }, + { + "type": "Microsoft.Web/sites", + "apiVersion": "2021-01-01", + "name": "[parameters('webAppName')]", + "location": "[resourceGroup().location]", + "dependsOn": [ + "[resourceId('Microsoft.Web/serverfarms', parameters('hostingPlanName'))]" + ], + "kind": "app", + "properties": { + "serverFarmId": "[resourceId('Microsoft.Web/serverfarms', parameters('hostingPlanName'))]", + "siteConfig": { + "alwaysOn": true, + "scmType": "None" + } + }, + "resources": [ + { + "name": "authsettings", + "type": "config", + "apiVersion": "2021-01-01", + "dependsOn": [ + "[resourceId('Microsoft.Web/sites', parameters('webAppName'))]" + ], + "properties": { + "enabled": true, + "unauthenticatedClientAction": "RedirectToLoginPage", + "defaultProvider": "AzureActiveDirectory" + } + } + ] + } + ] +{ + "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#", + "contentVersion": "1.0.0.0", + "parameters": { + "webAppName": { + "type": "string", + "defaultValue": "myWebApp", + "metadata": { + "description": "Name for the Web App" + } + }, + "hostingPlanName": { + "type": "string", + "defaultValue": "myHostingPlan", + "metadata": { + "description": "Name for the Hosting Plan" + } + } + }, + "resources": [ + { + "type": "Microsoft.Web/serverfarms", + "apiVersion": "2021-01-01", + "name": "[parameters('hostingPlanName')]", + "location": "[resourceGroup().location]", + "sku": { + "name": "F1", + "capacity": 1 + }, + "kind": "app" + }, + { + "type": "Microsoft.Web/sites", + "apiVersion": "2021-01-01", + "name": "[parameters('webAppName')]", + "location": "[resourceGroup().location]", + "dependsOn": [ + "[resourceId('Microsoft.Web/serverfarms', parameters('hostingPlanName'))]" + ], + "kind": "app", + "properties": { + "serverFarmId": "[resourceId('Microsoft.Web/serverfarms', parameters('hostingPlanName'))]", + "siteConfig": { + "alwaysOn": true, + "scmType": "None" + } + }, + "resources": [ + { + "name": "authsettings", + "type": "config", + "apiVersion": "2021-01-01", + "dependsOn": [ + "[resourceId('Microsoft.Web/sites', parameters('webAppName'))]" + ], + "properties": { + "enabled": true, + "unauthenticatedClientAction": "RedirectToLoginPage", + "defaultProvider": "AzureActiveDirectory" + } + } + ] + } + ] +} \ No newline at end of file diff --git a/deploy.parameters.json b/deploy.parameters.json new file mode 100644 index 00000000..60d26fe4 --- /dev/null +++ b/deploy.parameters.json @@ -0,0 +1,12 @@ +{ + "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentParameters.json#", + "contentVersion": "1.0.0.0", + "parameters": { + "webAppName": { + "value": "myWebApp" + }, + "hostingPlanName": { + "value": "myHostingPlan" + } + } +} \ No newline at end of file