-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4430a93
commit 771712b
Showing
85 changed files
with
74,815 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
|
||
Microsoft Visual Studio Solution File, Format Version 12.00 | ||
# Visual Studio Version 17 | ||
VisualStudioVersion = 17.3.32929.385 | ||
MinimumVisualStudioVersion = 10.0.40219.1 | ||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MVCBASICCRUD", "MVCBASICCRUD\MVCBASICCRUD.csproj", "{9A4DE5BC-2443-4613-98D6-30497647FD49}" | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|Any CPU = Debug|Any CPU | ||
Release|Any CPU = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{9A4DE5BC-2443-4613-98D6-30497647FD49}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{9A4DE5BC-2443-4613-98D6-30497647FD49}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{9A4DE5BC-2443-4613-98D6-30497647FD49}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{9A4DE5BC-2443-4613-98D6-30497647FD49}.Release|Any CPU.Build.0 = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(SolutionProperties) = preSolution | ||
HideSolutionNode = FALSE | ||
EndGlobalSection | ||
GlobalSection(ExtensibilityGlobals) = postSolution | ||
SolutionGuid = {99305D05-8D5C-44E0-91B4-966343449A39} | ||
EndGlobalSection | ||
EndGlobal |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
using Microsoft.AspNetCore.Mvc; | ||
using MVCBASICCRUD.Models; | ||
using System.Diagnostics; | ||
|
||
namespace MVCBASICCRUD.Controllers | ||
{ | ||
public class HomeController : Controller | ||
{ | ||
private readonly ILogger<HomeController> _logger; | ||
|
||
public HomeController(ILogger<HomeController> logger) | ||
{ | ||
_logger = logger; | ||
} | ||
|
||
public IActionResult Index() | ||
{ | ||
return View(); | ||
} | ||
|
||
public IActionResult Privacy() | ||
{ | ||
return View(); | ||
} | ||
|
||
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)] | ||
public IActionResult Error() | ||
{ | ||
return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier }); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,162 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
using Microsoft.AspNetCore.Mvc; | ||
using Microsoft.AspNetCore.Mvc.Rendering; | ||
using Microsoft.EntityFrameworkCore; | ||
using MVCBASICCRUD.Models; | ||
|
||
namespace MVCBASICCRUD.Controllers | ||
{ | ||
public class UsersController : Controller | ||
{ | ||
private readonly CRUDMVCContext _context; | ||
|
||
public UsersController(CRUDMVCContext context) | ||
{ | ||
_context = context; | ||
} | ||
|
||
// GET: Users | ||
public async Task<IActionResult> Index() | ||
{ | ||
return _context.Users != null ? | ||
View(await _context.Users.ToListAsync()) : | ||
Problem("Entity set 'CRUDMVCContext.Users' is null."); | ||
} | ||
|
||
// GET: Users/Details/5 | ||
public async Task<IActionResult> Details(int? id) | ||
{ | ||
if (id == null || _context.Users == null) | ||
{ | ||
return NotFound(); | ||
} | ||
|
||
var user = await _context.Users | ||
.FirstOrDefaultAsync(m => m.Id == id); | ||
if (user == null) | ||
{ | ||
return NotFound(); | ||
} | ||
|
||
return View(user); | ||
} | ||
|
||
// GET: Users/Create | ||
public IActionResult Create() | ||
{ | ||
return View(); | ||
} | ||
|
||
// POST: Users/Create | ||
// To protect from overposting attacks, enable the specific properties you want to bind to. | ||
// For more details, see http://go.microsoft.com/fwlink/?LinkId=317598. | ||
[HttpPost] | ||
[ValidateAntiForgeryToken] | ||
public async Task<IActionResult> Create([Bind("Id,Nombre,Fecha,Clave")] User user) | ||
{ | ||
if (ModelState.IsValid) | ||
{ | ||
_context.Add(user); | ||
await _context.SaveChangesAsync(); | ||
return RedirectToAction(nameof(Index)); | ||
} | ||
return View(user); | ||
} | ||
|
||
// GET: Users/Edit/5 | ||
public async Task<IActionResult> Edit(int? id) | ||
{ | ||
if (id == null || _context.Users == null) | ||
{ | ||
return NotFound(); | ||
} | ||
|
||
var user = await _context.Users.FindAsync(id); | ||
if (user == null) | ||
{ | ||
return NotFound(); | ||
} | ||
return View(user); | ||
} | ||
|
||
// POST: Users/Edit/5 | ||
// To protect from overposting attacks, enable the specific properties you want to bind to. | ||
// For more details, see http://go.microsoft.com/fwlink/?LinkId=317598. | ||
[HttpPost] | ||
[ValidateAntiForgeryToken] | ||
public async Task<IActionResult> Edit(int id, [Bind("Id,Nombre,Fecha,Clave")] User user) | ||
{ | ||
if (id != user.Id) | ||
{ | ||
return NotFound(); | ||
} | ||
|
||
if (ModelState.IsValid) | ||
{ | ||
try | ||
{ | ||
_context.Update(user); | ||
await _context.SaveChangesAsync(); | ||
} | ||
catch (DbUpdateConcurrencyException) | ||
{ | ||
if (!UserExists(user.Id)) | ||
{ | ||
return NotFound(); | ||
} | ||
else | ||
{ | ||
throw; | ||
} | ||
} | ||
return RedirectToAction(nameof(Index)); | ||
} | ||
return View(user); | ||
} | ||
|
||
// GET: Users/Delete/5 | ||
public async Task<IActionResult> Delete(int? id) | ||
{ | ||
if (id == null || _context.Users == null) | ||
{ | ||
return NotFound(); | ||
} | ||
|
||
var user = await _context.Users | ||
.FirstOrDefaultAsync(m => m.Id == id); | ||
if (user == null) | ||
{ | ||
return NotFound(); | ||
} | ||
|
||
return View(user); | ||
} | ||
|
||
// POST: Users/Delete/5 | ||
[HttpPost, ActionName("Delete")] | ||
[ValidateAntiForgeryToken] | ||
public async Task<IActionResult> DeleteConfirmed(int id) | ||
{ | ||
if (_context.Users == null) | ||
{ | ||
return Problem("Entity set 'CRUDMVCContext.Users' is null."); | ||
} | ||
var user = await _context.Users.FindAsync(id); | ||
if (user != null) | ||
{ | ||
_context.Users.Remove(user); | ||
} | ||
|
||
await _context.SaveChangesAsync(); | ||
return RedirectToAction(nameof(Index)); | ||
} | ||
|
||
private bool UserExists(int id) | ||
{ | ||
return (_context.Users?.Any(e => e.Id == id)).GetValueOrDefault(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<Project Sdk="Microsoft.NET.Sdk.Web"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net6.0</TargetFramework> | ||
<Nullable>enable</Nullable> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="6.0.26" /> | ||
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="6.0.26"> | ||
<PrivateAssets>all</PrivateAssets> | ||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||
</PackageReference> | ||
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="6.0.16" /> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using Microsoft.EntityFrameworkCore; | ||
using Microsoft.EntityFrameworkCore.Metadata; | ||
|
||
namespace MVCBASICCRUD.Models | ||
{ | ||
public partial class CRUDMVCContext : DbContext | ||
{ | ||
public CRUDMVCContext() | ||
{ | ||
} | ||
|
||
public CRUDMVCContext(DbContextOptions<CRUDMVCContext> options) | ||
: base(options) | ||
{ | ||
} | ||
|
||
public virtual DbSet<User> Users { get; set; } = null!; | ||
|
||
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) | ||
{ | ||
if (!optionsBuilder.IsConfigured) | ||
{ | ||
//#warning To protect potentially sensitive information in your connection string, you should move it out of source code. You can avoid scaffolding the connection string by using the Name= syntax to read it from configuration - see https://go.microsoft.com/fwlink/?linkid=2131148. For more guidance on storing connection strings, see http://go.microsoft.com/fwlink/?LinkId=723263. | ||
// optionsBuilder.UseSqlServer("server=NESTOR\\SQLEXPRESS01; database=CRUDMVC; integrated security=true"); | ||
} | ||
} | ||
|
||
protected override void OnModelCreating(ModelBuilder modelBuilder) | ||
{ | ||
modelBuilder.Entity<User>(entity => | ||
{ | ||
entity.Property(e => e.Id).HasColumnName("id"); | ||
|
||
entity.Property(e => e.Clave) | ||
.HasMaxLength(50) | ||
.IsUnicode(false) | ||
.HasColumnName("clave"); | ||
|
||
entity.Property(e => e.Fecha) | ||
.HasColumnType("date") | ||
.HasColumnName("fecha"); | ||
|
||
entity.Property(e => e.Nombre) | ||
.HasMaxLength(50) | ||
.IsUnicode(false) | ||
.HasColumnName("nombre"); | ||
}); | ||
|
||
OnModelCreatingPartial(modelBuilder); | ||
} | ||
|
||
partial void OnModelCreatingPartial(ModelBuilder modelBuilder); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
namespace MVCBASICCRUD.Models | ||
{ | ||
public class ErrorViewModel | ||
{ | ||
public string? RequestId { get; set; } | ||
|
||
public bool ShowRequestId => !string.IsNullOrEmpty(RequestId); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
|
||
namespace MVCBASICCRUD.Models | ||
{ | ||
public partial class User | ||
{ | ||
public int Id { get; set; } | ||
public string? Nombre { get; set; } | ||
public DateTime? Fecha { get; set; } | ||
public string? Clave { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
using Microsoft.EntityFrameworkCore; | ||
using MVCBASICCRUD.Models; | ||
|
||
var builder = WebApplication.CreateBuilder(args); | ||
|
||
// Add services to the container. | ||
builder.Services.AddControllersWithViews(); | ||
|
||
builder.Services.AddDbContext<CRUDMVCContext>(options => | ||
options.UseSqlServer(builder.Configuration.GetConnectionString("conexion"))); | ||
|
||
var app = builder.Build(); | ||
|
||
// Configure the HTTP request pipeline. | ||
if (!app.Environment.IsDevelopment()) | ||
{ | ||
app.UseExceptionHandler("/Home/Error"); | ||
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts. | ||
app.UseHsts(); | ||
} | ||
|
||
app.UseHttpsRedirection(); | ||
app.UseStaticFiles(); | ||
|
||
app.UseRouting(); | ||
|
||
app.UseAuthorization(); | ||
|
||
app.MapControllerRoute( | ||
name: "default", | ||
pattern: "{controller=Home}/{action=Index}/{id?}"); | ||
|
||
app.Run(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
{ | ||
"iisSettings": { | ||
"windowsAuthentication": false, | ||
"anonymousAuthentication": true, | ||
"iisExpress": { | ||
"applicationUrl": "http://localhost:9137", | ||
"sslPort": 44312 | ||
} | ||
}, | ||
"profiles": { | ||
"MVCBASICCRUD": { | ||
"commandName": "Project", | ||
"dotnetRunMessages": true, | ||
"launchBrowser": true, | ||
"applicationUrl": "https://localhost:7037;http://localhost:5037", | ||
"environmentVariables": { | ||
"ASPNETCORE_ENVIRONMENT": "Development" | ||
} | ||
}, | ||
"IIS Express": { | ||
"commandName": "IISExpress", | ||
"launchBrowser": true, | ||
"environmentVariables": { | ||
"ASPNETCORE_ENVIRONMENT": "Development" | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
@{ | ||
ViewData["Title"] = "Home Page"; | ||
} | ||
|
||
<div class="text-center"> | ||
<h1 class="display-4">Welcome</h1> | ||
<p>Learn about <a href="https://docs.microsoft.com/aspnet/core">building Web apps with ASP.NET Core</a>.</p> | ||
</div> |
Oops, something went wrong.