Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 66 additions & 0 deletions .github/workflows/master_contactdatabasewebapp-hpc.yml
Original file line number Diff line number Diff line change
@@ -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: .

97 changes: 78 additions & 19 deletions Controllers/UserController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}

}
}
53 changes: 53 additions & 0 deletions deploy.json
Original file line number Diff line number Diff line change
@@ -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'))]"
}
}
]
}
53 changes: 53 additions & 0 deletions deploy.parameters.json
Original file line number Diff line number Diff line change
@@ -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'))]"
}
}
]
}