First Initial
This commit is contained in:
90
ViewControllers/homeViewController.cs
Normal file
90
ViewControllers/homeViewController.cs
Normal file
@@ -0,0 +1,90 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using TodoAPI2.Models;
|
||||
using STAFF_API.Models;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using TodoAPI2.Controllers;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
|
||||
namespace TodoAPI2.Controllers
|
||||
{
|
||||
public class homeController : Controller
|
||||
{
|
||||
private IConfiguration Configuration { get; set; }
|
||||
private Iexternal_employeeService _repository;
|
||||
|
||||
/// <summary>
|
||||
/// Default constructure for dependency injection
|
||||
/// </summary>
|
||||
/// <param name="repository"></param>
|
||||
/// <param name="configuration"></param>
|
||||
public homeController(Iexternal_employeeService repository, IConfiguration configuration)
|
||||
{
|
||||
Configuration = configuration;
|
||||
_repository = repository;
|
||||
}
|
||||
|
||||
public IActionResult index()
|
||||
{
|
||||
get_login();
|
||||
|
||||
return View();
|
||||
}
|
||||
|
||||
public IActionResult index_report()
|
||||
{
|
||||
get_login();
|
||||
|
||||
return View();
|
||||
}
|
||||
|
||||
public IActionResult testlogin()
|
||||
{
|
||||
return View();
|
||||
}
|
||||
|
||||
public IActionResult dotestlogin()
|
||||
{
|
||||
if (!string.IsNullOrEmpty(HttpContext.Request.Query["user_id"]))
|
||||
{
|
||||
CookieOptions option = new CookieOptions();
|
||||
Response.Cookies.Delete("user_id");
|
||||
Response.Cookies.Append("user_id", HttpContext.Request.Query["user_id"], option);
|
||||
}
|
||||
|
||||
return Redirect("/eva/home/index");
|
||||
}
|
||||
|
||||
public void get_login()
|
||||
{
|
||||
if (!string.IsNullOrEmpty(HttpContext.Request.Cookies["user_id"]))
|
||||
{
|
||||
string loginid = HttpContext.Request.Cookies["user_id"];
|
||||
var emp = _repository.GetEmployeeForLogin(Convert.ToInt32(loginid));
|
||||
if (emp != null)
|
||||
{
|
||||
Response.Cookies.Delete("emp_name");
|
||||
Response.Cookies.Delete("emp_id");
|
||||
|
||||
CookieOptions option = new CookieOptions();
|
||||
option.Expires = DateTime.Now.AddHours(3);
|
||||
Response.Cookies.Append("emp_name", emp.fullname, option);
|
||||
Response.Cookies.Append("emp_id", emp.id.ToString(), option);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
|
||||
public IActionResult Error()
|
||||
{
|
||||
return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user