
    using Entidades.Dto;
    using Modelo;
    using Microsoft.AspNetCore.Mvc;
    namespace AlquilaFacil.Controllers;

    public class LoginController: Controller
    {
        public IActionResult Index(){
            return View();
        }

        [HttpPost("api/login")]
        public IActionResult Login([FromForm] LoginDto loginDto) { 

            var usuario = RepositorioUsuarios.Singleton.CheckUsuario(loginDto);
            if (usuario == null){
                return Content(errorAlert); 
            }
            else {
                Response.Headers["HX-Redirect"] = "/Home";
                return Ok();  
            }
        }

        private const string errorAlert = @"
                <div class='alert alert-warning alert-dismissible fade show' role='alert'>
                    <strong>Error!</strong> Usuario o contraseña incorrectos.
                </div>";
    }   