﻿using System.Web.Mvc;
using Castle.Core.Logging;


namespace SOURCE.BackOffice.Web.Controllers.Modularity
{
    public class ExtendedController : Controller
    {
        protected readonly ILogger _logger;

        public ExtendedController(ILogger logger)
        {
            _logger = logger;
        }

        public string GetControllerName()
        {
            return ControllerContext.Controller.ValueProvider.GetValue("controller").RawValue.ToString();
        }

        public string GetActionName()
        {
            return ControllerContext.Controller.ValueProvider.GetValue("action").RawValue.ToString();
        }

        public string GetUserIP()
        {
            // Si le client passe à travers le Reverse Proxy
            string usrIp = HttpContext.Request.ServerVariables["HTTP_CLIENT_IP"];

            // Dans le cas contraire,
            if (usrIp == null || usrIp == "")
                usrIp = HttpContext.Request.UserHostAddress;

            return usrIp;
        }
    }
}
