Files
GPW/HOME/Controllers/HomeController.cs
Samuele Locatelli 8b9b080912 HOME
- fix bootstrap
- fix 4.8.0
2024-02-29 15:57:47 +01:00

106 lines
3.6 KiB
C#

using HOME.Models;
using NLog;
using System;
using System.Linq;
using System.Web.Configuration;
using System.Web.Mvc;
namespace HOME.Controllers
{
public class HomeController : Controller
{
#region Public Fields
public Logger lg = LogManager.GetCurrentClassLogger();
#endregion Public Fields
#region Public Methods
public ActionResult About()
{
ViewBag.Title = "GPW";
ViewBag.Message = "Gestione Presenze Web - powered by EgalWare";
return View();
}
public ActionResult Contact()
{
ViewBag.Title = "GPW";
ViewBag.Message = "I nostri recapiti di contatto";
return View();
}
public ActionResult Index()
{
ViewBag.Title = "GPW";
int logLevel = 0;
try
{
logLevel = Convert.ToInt32(WebConfigurationManager.AppSettings["_logLevel"]);
}
catch
{ }
ViewBag.Environment = WebConfigurationManager.AppSettings["Environment"];
if (logLevel > 5) lg.Info("Environment = " + ViewBag.Environment);
using (var ctx = new GPWEntities())
{
if (logLevel > 5) lg.Info(string.Format("Inizio connessione DB con Entity Framework, connString:{0}{1}", Environment.NewLine, ctx.Database.Connection.ConnectionString));
try
{
// esegue stored procedure come function, recuperando chiave desiderata...
var keyVal = ctx.stp_AKV_getByKey("Environment").ToList<AnagKeyValue>();
// imposto URL dei vari siti
string UrlInt = getAKV("UrlInt");
string UrlExt = getAKV("UrlExt");
ViewBag.UrlAdmin = $"https://{UrlInt}/GPW/{getAKV("UrlAdmin")}/";
ViewBag.UrlBCode = $"https://{UrlInt}/GPW/{getAKV("UrlBCode")}/";
ViewBag.UrlSmart = $"https://{UrlExt}/GPW/{getAKV("UrlSmart")}/";
ViewBag.UrlSmartCore = $"https://{UrlExt}/GPW/{getAKV("UrlSmartCore")}/";
ViewBag.UrlWrkLg = $"https://{UrlInt}/GPW/{getAKV("UrlWrkLg")}/";
ViewBag.UrlWrkLgCore = $"https://{UrlInt}/GPW/{getAKV("UrlWrkLgCore")}/";
if (logLevel > 5) lg.Info("DB: UrlAdmin = " + ViewBag.UrlAdmin);
}
catch (Exception exc)
{
lg.Error(string.Format("Errore in decodifica valori da conf DB:{0}{1}", Environment.NewLine, exc));
if (logLevel > 5) lg.Info("Web.config: UrlAdmin = " + ViewBag.UrlAdmin);
}
}
return View();
}
#endregion Public Methods
#region Protected Methods
/// <summary>
/// Recupero chiave da DB o da config
/// </summary>
/// <param name="chiave"></param>
/// <returns></returns>
protected string getAKV(string chiave)
{
string answ = "";
using (var ctx = new GPWEntities())
{
try
{
// recupero chiave da DB
answ = ctx.stp_AKV_getByKey(chiave).ToList<AnagKeyValue>()[0].valString;
}
catch
{
///altrimenti da config
answ = WebConfigurationManager.AppSettings[chiave]; //"office.egalware.com";
}
}
return answ;
}
#endregion Protected Methods
}
}