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
36 changes: 36 additions & 0 deletions SimpleNetCoreApp/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Compiled binary files
bin/
obj/

# User-specific files
*.user
*.suo
*.userosscache
*.sln.docstates

# Logs
*.log

# Visual Studio Code
.vscode/
/SimpleNetCoreApp/bin
# Build results
*.dll
*.exe
*.app
*.so
*.dylib
*.pdb

# Temporary files
*.tmp
*.temp
*.cache
*.csproj.user

# Dependency directories
packages/
node_modules/

# Publish output
publish/
27 changes: 27 additions & 0 deletions SimpleNetCoreApp/Controllers/AddController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using Microsoft.AspNetCore.Mvc;
using SimpleNetCoreApp.Models;

namespace SimpleNetCoreApp.Controllers
{
public class AddController : Controller
{
// GET: Add
public IActionResult Index()
{
return View();
}

// POST: Add
[HttpPost]
public IActionResult Index(ItemModel item)
{
if (ModelState.IsValid)
{
// Logic to add the item (e.g., save to a list or in-memory storage)
// Redirect to the list view or another appropriate action
return RedirectToAction("Index", "List");
}
return View(item);
}
}
}
37 changes: 37 additions & 0 deletions SimpleNetCoreApp/Controllers/EditController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
using Microsoft.AspNetCore.Mvc;
using SimpleNetCoreApp.Models;

namespace SimpleNetCoreApp.Controllers
{
public class EditController : Controller
{
// GET: Edit/5
public IActionResult Index(int id)
{
// Here you would typically retrieve the item from a data source using the id
// For this example, we'll just create a dummy item
var item = new ItemModel
{
Id = id,
Name = "Sample Item",
Description = "This is a sample item description."
};

return View(item);
}

// POST: Edit/5
[HttpPost]
public IActionResult Index(ItemModel item)
{
if (ModelState.IsValid)
{
// Here you would typically update the item in a data source
// Redirect to the list or another appropriate action
return RedirectToAction("Index", "List");
}

return View(item);
}
}
}
12 changes: 12 additions & 0 deletions SimpleNetCoreApp/Controllers/HomeController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using Microsoft.AspNetCore.Mvc;

namespace SimpleNetCoreApp.Controllers
{
public class HomeController : Controller
{
public IActionResult Index()
{
return View();
}
}
}
20 changes: 20 additions & 0 deletions SimpleNetCoreApp/Controllers/ListController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using Microsoft.AspNetCore.Mvc;
using SimpleNetCoreApp.Models;
using System.Collections.Generic;

namespace SimpleNetCoreApp.Controllers
{
public class ListController : Controller
{
private static List<ItemModel> items = new List<ItemModel>
{
new ItemModel { Id = 1, Name = "Item 1", Description = "Description for Item 1" },
new ItemModel { Id = 2, Name = "Item 2", Description = "Description for Item 2" }
};

public IActionResult Index()
{
return View(items);
}
}
}
9 changes: 9 additions & 0 deletions SimpleNetCoreApp/Models/ItemModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace SimpleNetCoreApp.Models
{
public class ItemModel
{
public int Id { get; set; }
public string Name { get; set; }
public string Description { get; set; }
}
}
19 changes: 19 additions & 0 deletions SimpleNetCoreApp/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Hosting;

public class Program
{
public static void Main(string[] args)
{
CreateHostBuilder(args).Build().Run();
}

public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.UseStartup<Startup>();
});


}
55 changes: 55 additions & 0 deletions SimpleNetCoreApp/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# Simple .NET Core Application

This is a simple .NET Core application that demonstrates basic CRUD operations without a database. The application includes functionality for listing, adding, and editing items through a web interface.

## Project Structure

- **Controllers**: Contains the logic for handling requests.
- `HomeController.cs`: Manages the home page.
- `ListController.cs`: Handles the display of the item list.
- `AddController.cs`: Manages the addition of new items.
- `EditController.cs`: Handles the editing of existing items.

- **Models**: Contains the data structures used in the application.
- `ItemModel.cs`: Represents an item with properties such as Id, Name, and Description.

- **Views**: Contains the Razor views for rendering the UI.
- `Home/Index.cshtml`: The home page view.
- `List/Index.cshtml`: The view for displaying the list of items.
- `Add/Index.cshtml`: The view for the add item form.
- `Edit/Index.cshtml`: The view for the edit item form.

- **wwwroot**: Contains static files such as CSS, JavaScript, and third-party libraries.
- `css`: Stylesheets for the application.
- `js`: JavaScript files for client-side functionality.
- `lib`: Third-party libraries (e.g., jQuery, Bootstrap).

- **Configuration Files**:
- `appsettings.json`: Configuration settings for the application.
- `Program.cs`: The entry point of the application.
- `Startup.cs`: Configures services and the request pipeline.

## Setup Instructions

1. Clone the repository to your local machine.
2. Open the project in your preferred IDE.
3. Restore the dependencies using the command:
```
dotnet restore
```
4. Run the application using the command:
```
dotnet run
```
5. Open your web browser and navigate to `http://localhost:5000` to access the application.

## Usage

- Navigate to the home page to see an overview of the application.
- Use the "List" option to view all items.
- Use the "Add" option to create a new item.
- Use the "Edit" option to modify an existing item.

## Troubleshooting

If you encounter issues with certificates, try closing and reopening your IDE.
15 changes: 15 additions & 0 deletions SimpleNetCoreApp/SimpleNetCoreApp.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<!-- Esta línea es innecesaria, porque ya es true por defecto -->
<!-- <EnableDefaultCompileItems>true</EnableDefaultCompileItems> -->
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation" Version="6.0.0" />
</ItemGroup>

</Project>
22 changes: 22 additions & 0 deletions SimpleNetCoreApp/SimpleNetCoreApp.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.0.31903.59
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SimpleNetCoreApp", "SimpleNetCoreApp.csproj", "{7FD36F7C-CCEA-471A-817C-C63AEF0D40CF}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{7FD36F7C-CCEA-471A-817C-C63AEF0D40CF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{7FD36F7C-CCEA-471A-817C-C63AEF0D40CF}.Debug|Any CPU.Build.0 = Debug|Any CPU
{7FD36F7C-CCEA-471A-817C-C63AEF0D40CF}.Release|Any CPU.ActiveCfg = Release|Any CPU
{7FD36F7C-CCEA-471A-817C-C63AEF0D40CF}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
EndGlobal
39 changes: 39 additions & 0 deletions SimpleNetCoreApp/Startup.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;

public class Startup
{
public void ConfigureServices(IServiceCollection services)
{
services.AddControllersWithViews();
}

public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
else
{
app.UseExceptionHandler("/Home/Error");
app.UseHsts();
}

app.UseHttpsRedirection();
app.UseStaticFiles();

app.UseRouting();

app.UseAuthorization();

app.UseEndpoints(endpoints =>
{
endpoints.MapControllerRoute(
name: "default",
pattern: "{controller=Home}/{action=Index}/{id?}");
});
}
}
20 changes: 20 additions & 0 deletions SimpleNetCoreApp/Views/Add/Index.cshtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
@model SimpleNetCoreApp.Models.ItemModel


<h2>Add New Item</h2>

<form asp-action="Create" method="post">
<div class="form-group">
<label asp-for="Name"></label>
<input asp-for="Name" class="form-control" />
<span asp-validation-for="Name" class="text-danger"></span>
</div>
<div class="form-group
<label asp-for="Description"></label>
<textarea asp-for="Description" class="form-control"></textarea>
<span asp-validation-for="Description" class="text-danger"></span>
</div>
<button type="submit" class="btn btn-primary">Add Item</button>
</form>

<a asp-controller="List" asp-action="Index">Back to List</a>
27 changes: 27 additions & 0 deletions SimpleNetCoreApp/Views/Edit/Index.cshtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
@model SimpleNetCoreApp.Models.ItemModel


<h2>Edit Item</h2>

<form asp-action="Edit" method="post">
<input type="hidden" asp-for="Id" />

<div class="form-group">
<label asp-for="Name"></label>
<input asp-for="Name" class="form-control" />
<span asp-validation-for="Name" class="text-danger"></span>
</div>

<div class="form-group">
<label asp-for="Description"></label>
<textarea asp-for="Description" class="form-control"></textarea>
<span asp-validation-for="Description" class="text-danger"></span>
</div>

<button type="submit" class="btn btn-primary">Save</button>
<a asp-action="Index" class="btn btn-secondary">Cancel</a>
</form>

@section Scripts {
@{await Html.RenderPartialAsync("_ValidationScriptsPartial");}
}
17 changes: 17 additions & 0 deletions SimpleNetCoreApp/Views/Home/Index.cshtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Home</title>
<link rel="stylesheet" href="~/css/site.css" />
</head>
<body>
<div class="container">
<h1>Welcome to the Simple .NET Core App</h1>
<p>This is the home page of your application.</p>
<a href="/List">View Items</a>
<a href="/Add">Add New Item</a>
</div>
</body>
</html>
Loading