I need to change the property IsOpen
to false
from a SupportTicket
with a button click in the ticket list and refresh the view so it only displays open tickets (IsOpen = true
).
I tried with public IActionResult Resolve(int number)
but doesn't work
HomeController.cs:
using Ev02.Models;
using Microsoft.AspNetCore.Mvc;
namespace Ev02.Controllers
{
public class HomeController : Controller
{
private readonly IRepository _repository;
public HomeController(IRepository repository)
{
this._repository = repository;
}
public IActionResult Index()
{
return View(this._repository.TicketList());
}
public IActionResult Save(SupportTicket ticket)
{
if(ModelState.IsValid)
{
this._repository.Add(ticket);
ViewBag.Message = "Ticket guardado con éxito";
return RedirectToAction(nameof(Index));
}
return View("Index", ticket);
}
public IActionResult Closed()
{
return View(this._repository.TicketList());
}
public IActionResult New()
{
SupportTicket ticket = new SupportTicket();
return View(ticket);
}
public IActionResult Resolve(int number)
{
SupportTicket ticket = this._repository.TicketGetByNumber(number);
ticket.IsOpen = false;
return View(ticket);
}
}
}
Index.cshtml:
@{
Layout = "_Layout";
}
@model List<Ev02.Models.SupportTicket>
<h2>Tickets pendientes de resolución</h2>
<div class="col-2">
<table class="table">
<thead>
<tr>
<th scope="col">N° de ticket</th>
<th scope="col">Asunto</th>
<th scope="col">Descripción</th>
<th scope="col">Fecha de creación</th>
<th scope="col">Acción</th>
</tr>
</thead>
<tbody>
@foreach (var ticket in Model)
if (ticket.IsOpen)
{
<tr>
<td>@ticket.TicketNumber</td>
<td>@ticket.Subject</td>
<td>@ticket.Description</td>
<td>@ticket.CreatedDate</td>
@using (Html.BeginForm("Resolve", "Home", FormMethod.Post))
{
<td>
<button name="btn" type="submit" class="btn btn-light btn-sm">Marcar como resuelto</button>
</td>
}
</tr>
}
</tbody>
</table>
</div>
I tried with public IActionResult Resolve(int number)
but doesn't work