62 lines
1.9 KiB
C#
62 lines
1.9 KiB
C#
using Microsoft.AspNetCore.Authorization;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using System.Linq;
|
|
using System.Threading.Tasks;
|
|
using vita_asistente.Data;
|
|
using vita_asistente.Data.Models;
|
|
|
|
namespace vita_asistente.Controllers
|
|
{
|
|
[Authorize]
|
|
public class PacientesController : Controller
|
|
{
|
|
private readonly ApplicationDbContext _context;
|
|
|
|
public PacientesController(ApplicationDbContext context)
|
|
{
|
|
_context = context;
|
|
}
|
|
|
|
// GET: Pacientes
|
|
public async Task<IActionResult> Index(string nombreBusqueda)
|
|
{
|
|
var pacientes = _context.Pacientes.AsNoTracking();
|
|
|
|
if (!string.IsNullOrWhiteSpace(nombreBusqueda))
|
|
{
|
|
pacientes = pacientes.Where(p =>
|
|
(p.Nombre + " " + p.Apellido).Contains(nombreBusqueda.Trim()) ||
|
|
p.Documento.Contains(nombreBusqueda.Trim()));
|
|
}
|
|
|
|
ViewBag.NombreBusqueda = nombreBusqueda;
|
|
return View(await pacientes.OrderByDescending(p => p.FechaRegistro).ToListAsync());
|
|
}
|
|
|
|
// GET: Pacientes/Details/5
|
|
public async Task<IActionResult> Details(string id)
|
|
{
|
|
if (id == null) return NotFound();
|
|
var paciente = await _context.Pacientes.FindAsync(id);
|
|
if (paciente == null) return NotFound();
|
|
return View(paciente);
|
|
}
|
|
|
|
// POST: Pacientes/Activate/5
|
|
[HttpPost]
|
|
[Authorize(Roles = "Admin")]
|
|
[ValidateAntiForgeryToken]
|
|
public async Task<IActionResult> Activate(string id)
|
|
{
|
|
var paciente = await _context.Pacientes.FindAsync(id);
|
|
if (paciente == null) return NotFound();
|
|
|
|
paciente.IsActive = true;
|
|
_context.Pacientes.Update(paciente);
|
|
await _context.SaveChangesAsync();
|
|
|
|
return RedirectToAction(nameof(Index));
|
|
}
|
|
}
|
|
} |