Skip to content

Updated packages, added unit tests, and improved UserController #32

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
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_userapp124.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 - userApp124

on:
push:
branches:
- master
workflow_dispatch:

jobs:
build:
runs-on: windows-latest

steps:
- uses: actions/checkout@v4

- name: Setup MSBuild path
uses: microsoft/[email protected]

- name: Setup NuGet
uses: NuGet/[email protected]

- 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_D6D4FAAD52464D5C85E05B4FBBC20E28 }}
tenant-id: ${{ secrets.AZUREAPPSERVICE_TENANTID_4EB6EDC292D346DBA08192CD5B3693FB }}
subscription-id: ${{ secrets.AZUREAPPSERVICE_SUBSCRIPTIONID_1A12925687414AFE8A34F49FC22F0108 }}

- name: Deploy to Azure Web App
id: deploy-to-webapp
uses: azure/webapps-deploy@v2
with:
app-name: 'userApp124'
slot-name: 'Production'
package: .

25 changes: 18 additions & 7 deletions CRUD application 2.csproj
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.2.0.1\build\net46\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.props" Condition="Exists('packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.2.0.1\build\net46\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.props')" />
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
Expand Down Expand Up @@ -45,6 +44,9 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.4.1.0\lib\net472\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.dll</HintPath>
</Reference>
<Reference Include="Microsoft.CSharp" />
<Reference Include="System" />
<Reference Include="System.Data" />
Expand Down Expand Up @@ -110,17 +112,22 @@
<Private>True</Private>
<HintPath>packages\Antlr.3.5.0.2\lib\Antlr3.Runtime.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
<Reference Include="Microsoft.CodeDom.Providers.DotNetCompilerPlatform">
<HintPath>packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.2.0.1\lib\net45\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.dll</HintPath>
<Reference Include="xunit.abstractions, Version=2.0.0.0, Culture=neutral, PublicKeyToken=8d05b1bb7a6fdb6c, processorArchitecture=MSIL">
<HintPath>packages\xunit.abstractions.2.0.3\lib\net35\xunit.abstractions.dll</HintPath>
</Reference>
<Reference Include="xunit.assert, Version=2.8.1.0, Culture=neutral, PublicKeyToken=8d05b1bb7a6fdb6c, processorArchitecture=MSIL">
<HintPath>packages\xunit.assert.2.8.1\lib\netstandard1.1\xunit.assert.dll</HintPath>
</Reference>
<Reference Include="xunit.core, Version=2.8.1.0, Culture=neutral, PublicKeyToken=8d05b1bb7a6fdb6c, processorArchitecture=MSIL">
<HintPath>packages\xunit.extensibility.core.2.8.1\lib\net452\xunit.core.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="App_Start\BundleConfig.cs" />
<Compile Include="App_Start\FilterConfig.cs" />
<Compile Include="App_Start\RouteConfig.cs" />
<Compile Include="Controllers\UserController.cs" />
<Compile Include="Controllers\UserControllerTests.cs" />
<Compile Include="Global.asax.cs">
<DependentUpon>Global.asax</DependentUpon>
</Compile>
Expand All @@ -138,6 +145,9 @@
<Content Include="Content\Site.css" />
<Content Include="Scripts\bootstrap.js" />
<Content Include="Scripts\bootstrap.min.js" />
<Content Include="deploy.json" />
<Content Include="deploy.parameters.json" />
<Content Include="README.MD" />
<None Include="Scripts\jquery-3.4.1.intellisense.js" />
<Content Include="Scripts\jquery-3.4.1.js" />
<Content Include="Scripts\jquery-3.4.1.min.js" />
Expand Down Expand Up @@ -210,16 +220,17 @@
</FlavorProperties>
</VisualStudio>
</ProjectExtensions>
<Import Project="packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.4.1.0\build\net472\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.targets" Condition="Exists('packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.4.1.0\build\net472\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.targets')" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>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}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.2.0.1\build\net46\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.props')" Text="$([System.String]::Format('$(ErrorText)', 'packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.2.0.1\build\net46\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.props'))" />
<Error Condition="!Exists('packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.4.1.0\build\net472\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.targets')" Text="$([System.String]::Format('$(ErrorText)', 'packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.4.1.0\build\net472\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.targets'))" />
</Target>
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target> -->
</Project>
</Project>
120 changes: 92 additions & 28 deletions Controllers/UserController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,60 +7,124 @@ namespace CRUD_application_2.Controllers
public class UserController : Controller
{
public static System.Collections.Generic.List<User> userlist = new System.Collections.Generic.List<User>();
// GET: User

/// <summary>
/// Retrieves the list of users and displays them in the Index view.
/// </summary>
/// <returns>The Index view with the list of users.</returns>
public ActionResult Index()
{
// Implement the Index method here
return View(userlist);
}

// GET: User/Details/5

/// <summary>
/// Retrieves the details of a specific user based on the provided ID and displays them in the Details view.
/// </summary>
/// <param name="id">The ID of the user to retrieve.</param>
/// <returns>The Details view with the details of the user.</returns>
public ActionResult Details(int id)
{
// Implement the details method here
return View(userlist.FirstOrDefault(x => x.Id == id));
}

// GET: User/Create

/// <summary>
/// Displays the view to create a new user.
/// </summary>
/// <returns>The Create view.</returns>
public ActionResult Create()
{
//Implement the Create method here
return View();
}

// POST: User/Create

/// <summary>
/// Handles the HTTP POST request to create a new user.
/// </summary>
/// <param name="user">The user object containing the information of the new user.</param>
/// <returns>Redirects to the Index action to display the updated list of users.</returns>
[HttpPost]
public ActionResult Create(User user)
{
// Implement the Create method (POST) here
userlist.Add(user);
return RedirectToAction("Index");
}

// GET: User/Edit/5

/// <summary>
/// Displays the view to edit an existing user with the specified ID.
/// </summary>
/// <param name="id">The ID of the user to edit.</param>
/// <returns>The Edit view with the user to edit.</returns>
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.
User user = userlist.FirstOrDefault(x => x.Id == id);
if (user == null)
{
return HttpNotFound();
}
return View(user);
}

// POST: User/Edit/5

/// <summary>
/// Handles the HTTP POST request to update an existing user with the specified ID.
/// </summary>
/// <param name="id">The ID of the user to update.</param>
/// <param name="user">The user object containing the updated information.</param>
/// <returns>Redirects to the Index action to display the updated list of users.</returns>
[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.
User existingUser = userlist.FirstOrDefault(x => x.Id == id);
if (existingUser == null)
{
return HttpNotFound();
}
existingUser.Name = user.Name;
existingUser.Email = user.Email;

return RedirectToAction("Index");
}

// GET: User/Delete/5

/// <summary>
/// Displays the view to delete an existing user with the specified ID.
/// </summary>
/// <param name="id">The ID of the user to delete.</param>
/// <returns>The Delete view with the user to delete.</returns>
public ActionResult Delete(int id)
{
// Implement the Delete method here
User user = userlist.FirstOrDefault(x => x.Id == id);
if (user == null)
{
return HttpNotFound();
}
return View(user);
}

// POST: User/Delete/5

/// <summary>
/// Handles the HTTP POST request to delete an existing user with the specified ID.
/// </summary>
/// <param name="id">The ID of the user to delete.</param>
/// <param name="collection">The form collection.</param>
/// <returns>Redirects to the Index action to display the updated list of users.</returns>
[HttpPost]
public ActionResult Delete(int id, FormCollection collection)
{
// Implement the Delete method (POST) here
User user = userlist.FirstOrDefault(x => x.Id == id);
if (user == null)
{
return HttpNotFound();
}
userlist.Remove(user);
return RedirectToAction("Index");
}

/// <summary>
/// Retrieves the list of users that match the provided search term and displays them in the Search view.
/// </summary>
/// <param name="searchTerm">The search term to match against user names.</param>
/// <returns>The Search view with the list of matching users.</returns>
public ActionResult Search(string searchTerm)
{
var searchResults = userlist.Where(user => user.Name.Contains(searchTerm)).ToList();
return View(searchResults);
}
}
}
Loading