using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using VentaUniformes.Application.Exceptions;
using VentaUniformes.Application.VentasView;
using VentaUniformes.Application.VentasView.historico.Borrar;

namespace VentaUniformes.app.Controllers
{
    [TypeFilter(typeof(ExceptionManager))]
    public class BorrarVentaController : Controller
    {
        private readonly IVentasViewService ventasViewService;

        public BorrarVentaController(IVentasViewService ventasViewService)
        {
            this.ventasViewService = ventasViewService;
        }

        [Authorize]
        [HttpGet]
        public async Task<IActionResult> Principal(VentaHistoricoBorrarViewModel model)
        {
            return View(model);
        }
        [Authorize]
        [HttpPost]
        public async Task<IActionResult> Borrar(VentaHistoricoBorrarViewModel model)
        {
            if (!await ventasViewService.BorraVenta(model.Id))
            {
                ViewData["Mensaje"] = "Error al Cargar resultados";
                return RedirectToAction("Principal", model);
            }
            model.Alumno = model.AlumnoFiltro;
            return RedirectToAction("Principal", "Historico", model);

        }
    }
}
