diff --git a/CRUD application 2.csproj b/CRUD application 2.csproj
index 553546be..6475b0a8 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
-
-
@@ -138,6 +136,7 @@
+
@@ -222,4 +221,4 @@
-->
-
+
\ No newline at end of file
diff --git a/CRUD application 2.sln b/CRUD application 2.sln
index 98ddfc3a..50238b13 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.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
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UnitTestProject2", "..\UnitTestProject2\UnitTestProject2.csproj", "{B1050339-D0AD-437C-86D2-80746A3E6A76}"
+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
+ {B1050339-D0AD-437C-86D2-80746A3E6A76}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {B1050339-D0AD-437C-86D2-80746A3E6A76}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {B1050339-D0AD-437C-86D2-80746A3E6A76}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {B1050339-D0AD-437C-86D2-80746A3E6A76}.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..c106dcaa 100644
--- a/Controllers/UserController.cs
+++ b/Controllers/UserController.cs
@@ -10,37 +10,60 @@ public class UserController : Controller
// GET: User
public ActionResult Index()
{
- // Implement the Index method here
+ return View(userlist);
}
-
+
// GET: User/Details/5
+ [HttpGet]
+ [Route("user/details{id}")]
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
+ [HttpGet]
+ [Route("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
+ [HttpGet]
+ [Route("User/Edit{id}")]
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]
+ [Route("User/Edit{id}")]
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.
@@ -48,19 +71,56 @@ 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();
+ }
+ if (ModelState.IsValid)
+ {
+ existingUser.Name = user.Name;
+ existingUser.Email = user.Email;
+ // Add other properties as needed
+ return RedirectToAction("Index");
+ }
+ return View(user);
+
}
-
+
// GET: User/Delete/5
+ [HttpGet]
+ [Route("User/Search{id}")]
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]
+ [Route("User/Delete{id}")]
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");
+ }
+
+ // GET: User/Search
+ [HttpGet]
+ [Route("User/Search/{name}")]
+ public ActionResult Search(string name)
+ {
+ var users = userlist.Where(u => u.Name.Contains(name)).ToList();
+ return View("Index", users);
}
}
}
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/armtemplate.json b/armtemplate.json
new file mode 100644
index 00000000..397f70c0
--- /dev/null
+++ b/armtemplate.json
@@ -0,0 +1,38 @@
+{
+ "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
+ "contentVersion": "1.0.0.0",
+ "parameters": {
+ "name": {
+ "type": "string",
+ "metadata": {
+ "description": "The name of the web app that you wish to create."
+ }
+ },
+ "hostingPlanName": {
+ "type": "string",
+ "metadata": {
+ "description": "The name of the App Service plan to use for hosting the web app."
+ }
+ },
+ "location": {
+ "type": "string",
+ "metadata": {
+ "description": "The location (region) to create the web app."
+ }
+ }
+ },
+ "resources": [
+ {
+ "type": "Microsoft.Web/sites",
+ "apiVersion": "2018-11-01",
+ "name": "[parameters('name')]",
+ "location": "[parameters('location')]",
+ "dependsOn": [
+ "[resourceId('Microsoft.Web/serverfarms', parameters('hostingPlanName'))]"
+ ],
+ "properties": {
+ "serverFarmId": "[resourceId('Microsoft.Web/serverfarms', parameters('hostingPlanName'))]"
+ }
+ }
+ ]
+}
\ No newline at end of file
diff --git a/deploy.json b/deploy.json
new file mode 100644
index 00000000..d3f68752
--- /dev/null
+++ b/deploy.json
@@ -0,0 +1,77 @@
+{
+ "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
+ "contentVersion": "1.0.0.0",
+ "parameters": {
+ "webAppName": {
+ "type": "string",
+ "metadata": {
+ "description": "Base name of the resource such as web app name and app service plan"
+ }
+ },
+ "location": {
+ "type": "string",
+ "defaultValue": "[resourceGroup().location]",
+ "metadata": {
+ "description": "Location for all resources"
+ }
+ }
+ },
+ "variables": {
+ "appServicePlanName": "[concat(parameters('webAppName'), 'ServicePlan')]"
+ },
+ "resources": [
+ {
+ "type": "Microsoft.Web/serverfarms",
+ "apiVersion": "2020-06-01",
+ "name": "[variables('appServicePlanName')]",
+ "location": "[parameters('location')]",
+ "sku": {
+ "name": "F1",
+ "capacity": 1
+ },
+ "kind": "app"
+ },
+ {
+ "type": "Microsoft.Web/sites",
+ "apiVersion": "2020-06-01",
+ "name": "[parameters('webAppName')]",
+ "location": "[parameters('location')]",
+ "dependsOn": [
+ "[resourceId('Microsoft.Web/serverfarms', variables('appServicePlanName'))]"
+ ],
+ "kind": "app",
+ "properties": {
+ "serverFarmId": "[resourceId('Microsoft.Web/serverfarms', variables('appServicePlanName'))]",
+ "siteConfig": {
+ "alwaysOn": true,
+ "scmType": "None"
+ },
+ "httpsOnly": true
+ },
+ "identity": {
+ "type": "SystemAssigned"
+ },
+ "resources": [
+ {
+ "name": "authsettings",
+ "type": "config",
+ "apiVersion": "2020-06-01",
+ "dependsOn": [
+ "[resourceId('Microsoft.Web/sites', parameters('webAppName'))]"
+ ],
+ "properties": {
+ "enabled": true,
+ "unauthenticatedClientAction": "RedirectToLoginPage",
+ "defaultProvider": "AzureActiveDirectory"
+ }
+ }
+ ]
+ }
+ ],
+ "outputs": {
+ "webAppUrl": {
+ "type": "string",
+ "value": "[concat('https://', parameters('webAppName'), '.azurewebsites.net')]"
+ }
+ }
+}
\ No newline at end of file
diff --git a/deploy.parameters.json b/deploy.parameters.json
new file mode 100644
index 00000000..e42a1c9a
--- /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": "MyCopilottrainingAPP"
+ },
+ "location": {
+ "value": "East US"
+ }
+ }
+}