// GET: Factory public async Task <ActionResult> Index() { ViewBag.Version = Global._sfAdminVersion; EmployeeSession empSession = null; if (Session["empSession"] != null) { empSession = EmployeeSession.LoadByJsonString(Session["empSession"].ToString()); } try { RestfulAPIHelper apiHelper = new RestfulAPIHelper(); ViewBag.FactoryList = await apiHelper.callAPIService("GET", Global._factoryInCompanyEndPoint, null); ViewBag.CultureInfoList = await apiHelper.callAPIService("GET", Global._cultureInfoEndPoint, null); /* Setup Company Name and Company Photo on Page */ CompanyModel companyModel = new CompanyModel(); CompanySession compSession = await companyModel.GetCompanySessionData(); ViewBag.CompanyName = compSession.shortName; ViewBag.CompanyPhotoURL = compSession.photoURL; ViewBag.CompanyLat = compSession.lat; ViewBag.CompanyLng = compSession.lng; /* Setup Employee Data on Page */ ViewBag.FirstName = empSession.firstName; ViewBag.LastName = empSession.lastName; ViewBag.Email = empSession.email; ViewBag.PhotoURL = empSession.photoURL; ViewBag.PermissionList = empSession.permissions; /* Setup Menu Item Active */ ViewBag.MenuNavigation = empSession.navigationMenu; ViewBag.MenuItem = "menuFactory"; } catch (Exception ex) { LoginMsgSession loginMsgSession = new LoginMsgSession(); if (ex.Message.ToLower() == "invalid session") { loginMsgSession.toastLevel = "warning"; loginMsgSession.message = "[[[Please Login]]]"; } else { loginMsgSession.toastLevel = "error"; loginMsgSession.message = "[[[Authentication Fail]]]."; StringBuilder logMessage = new StringBuilder(); logMessage.AppendLine("audit: Authentication Fail."); logMessage.AppendLine("email:" + empSession.email); logMessage.AppendLine("password:"******"loginMsgSession"] = loginMsgSession.Serialize(); return(RedirectToAction("Index", "Home")); } return(View()); }
public async Task <ActionResult> ShowProfile() { EmployeeSession empSession = null; if (Session["empSession"] != null) { empSession = EmployeeSession.LoadByJsonString(Session["empSession"].ToString()); } try { /* Setup Company Name and Company Photo on Page */ CompanyModel companyModel = new CompanyModel(); CompanySession compSession = await companyModel.GetCompanySessionData(); ViewBag.CompanyName = compSession.shortName; ViewBag.CompanyPhotoURL = compSession.photoURL; ViewBag.CompanyID = compSession.id; /* Setup Employee Data on Page */ ViewBag.FirstName = empSession.firstName; ViewBag.LastName = empSession.lastName; ViewBag.Email = empSession.email; ViewBag.PhotoURL = empSession.photoURL; ViewBag.PermissionList = empSession.permissions; ViewBag.Id = empSession.id; ViewBag.EmployeeNumber = empSession.employeeNumber; ViewBag.AdminFlag = empSession.adminFlag; ViewBag.Lang = empSession.Lang; KeyValuePair <string, i18n.LanguageTag>[] langx = LanguageHelpers.GetAppLanguages().OrderBy(x => x.Key).ToArray(); ViewBag.langs = JsonConvert.SerializeObject(langx); } catch (Exception ex) { LoginMsgSession loginMsgSession = new LoginMsgSession(); if (ex.Message.ToLower() == "invalid session") { loginMsgSession.toastLevel = "warning"; loginMsgSession.message = "[[[Please Login]]]"; } else { loginMsgSession.toastLevel = "error"; loginMsgSession.message = "[[[Authentication Fail]]]."; StringBuilder logMessage = new StringBuilder(); logMessage.AppendLine("audit: Authentication Fail."); logMessage.AppendLine("email:" + empSession.email); logMessage.AppendLine("password:"******"loginMsgSession"] = loginMsgSession.Serialize(); return(RedirectToAction("Index", "Home")); } return(PartialView("Profile")); }
public async Task <ActionResult> FactoryDashboard() { ViewBag.Version = Global._sfAdminVersion; ViewBag.WidgetOutput = "<H2>Nothing Found.</H2>"; ViewBag.GoogleMapAPIKey = Global._sfGoogleMapAPIKey; ViewBag.BaiduMapAPIKey = Global._sfBaiduMapAPIKey; CompanyModel companyModel = new CompanyModel(); CompanySession compSession = await companyModel.GetCompanySessionData(); EmployeeSession empSession = null; if (Session["empSession"] != null) { empSession = EmployeeSession.LoadByJsonString(Session["empSession"].ToString()); } ViewBag.PermissionList = empSession.permissions; if (Request.QueryString["factoryId"] != null || Request.Form["factoryId"] != null) { string factoryId = Request.QueryString["factoryId"] != null ? Request.QueryString["factoryId"] : Request.Form["factoryId"]; try { RestfulAPIHelper apiHelper = new RestfulAPIHelper(); string factoryString = await apiHelper.callAPIService("GET", Global._factoryEndPoint + "/" + factoryId, null); ViewBag.Factory = factoryString; dynamic factoryObj = JObject.Parse(factoryString); string EquipmentString = await apiHelper.callAPIService("GET", Global._equipmentInFactoryEndPoint + "/" + factoryId, null); dynamic EquipmentObjs = JsonConvert.DeserializeObject(EquipmentString); String WidgetCatalog = await apiHelper.callAPIService("GET", Global._widgetCatalogInCompanyEndPoint + "?level=factory", null); ViewBag.WidgetCatalogList = WidgetCatalog.Replace("\r\n", "").Replace("\\\\", "\\\\\\\\"); /* Construct an New JSON String which contain all equipment under the Factory; */ /* Using ExpandoObject to add couple new element into JSON object, which will be use on JavaScript */ List <ExpandoObject> Equipments = new List <ExpandoObject>(); foreach (var equipmentObj in EquipmentObjs) { ExpandoObject newEquipmentObj = JsonConvert.DeserializeObject <ExpandoObject>(JsonConvert.SerializeObject(equipmentObj), new ExpandoObjectConverter()); AddExpandoObjectProperty(newEquipmentObj, "msgTimestamp", ""); AddExpandoObjectProperty(newEquipmentObj, "alarmMsgTimestamp", ""); Equipments.Add(newEquipmentObj); } ViewBag.EquipmentList = JsonConvert.SerializeObject(Equipments); /* End JSON Construct */ string AlarmMessageString = "[]"; try { string endPoint = Global._alarmMessageInFactoryEndPoint + "/" + factoryId + "?hours=24&top=100&order=asc"; AlarmMessageString = await apiHelper.callAPIService("GET", endPoint, null); dynamic alarmObjs = JsonConvert.DeserializeObject(AlarmMessageString); ViewBag.AlarmMessageCount = alarmObjs.Count; //AlarmMessageString = AlarmMessageString.Replace("\\\"", ""); } catch (Exception ex) { ViewBag.AlarmMessageCount = 0; StringBuilder logMessage = new StringBuilder(); logMessage.AppendLine("Error on retrieve AlarmMessage from DocDB"); logMessage.AppendLine("Exeption:" + ex.Message); Global._sfAppLogger.Error(logMessage); } //ViewBag.AlarmMessageList = AlarmMessageString; /* Get Factory Widget */ string factoryDashboardJson = await apiHelper.callAPIService("GET", Global._factoryDashboard + "/" + factoryId, null); try { dynamic factoryDashboardObj = JsonConvert.DeserializeObject(factoryDashboardJson); int DashboardId = (int)factoryDashboardObj[0].Id; if (DashboardId > 0) { string widgetJson = await apiHelper.callAPIService("GET", Global._widgetInDashboardEndPoint + "/" + DashboardId, null); if (!string.IsNullOrEmpty(widgetJson)) { DashboardModel dashboardModel = new DashboardModel(); dashboardModel.GenerateFactoryWidgetHTMLContent(factoryObj, widgetJson, compSession, EquipmentString); ViewBag.WidgetOutput = dashboardModel.GetWidgetHTMLContent(); ViewBag.WidgetUpdateFunctions = dashboardModel.GetWidgetJavaScriptFunction(); ViewBag.DashboardId = DashboardId; } } } catch (Exception) { ; } /* Setup Company Name and Company Photo on Page */ ViewBag.CompanyId = compSession.id; ViewBag.CompanyName = compSession.shortName; ViewBag.CompanyPhotoURL = compSession.photoURL; /* Setup Menu Item Active */ ViewBag.MenuNavigation = ""; ViewBag.MenuItem = ""; } catch (Exception ex) { // EmployeeSession empSession = null; //if (Session["empSession"] != null) // empSession = EmployeeSession.LoadByJsonString(Session["empSession"].ToString()); LoginMsgSession loginMsgSession = new LoginMsgSession(); if (ex.Message.ToLower() == "invalid session") { loginMsgSession.toastLevel = "warning"; loginMsgSession.message = "[[[Please Login]]]"; } else { loginMsgSession.toastLevel = "error"; loginMsgSession.message = "[[[Authentication Fail]]]."; StringBuilder logMessage = new StringBuilder(); logMessage.AppendLine("audit: Authentication Fail."); logMessage.AppendLine("email:" + empSession.email); logMessage.AppendLine("password:"******"loginMsgSession"] = loginMsgSession.Serialize(); return(RedirectToAction("Index", "Home")); } } return(View()); }
public async Task <ActionResult> RunningTask() { ViewBag.Version = Global._sfAdminVersion; EmployeeSession empSession = null; if (Session["empSession"] != null) { empSession = EmployeeSession.LoadByJsonString(Session["empSession"].ToString()); } try { RestfulAPIHelper apiHelper = new RestfulAPIHelper(); String runningTask = await apiHelper.callAPIService("GET", Global._operationTaskSearchEndPoint, null); //JObject jsonObj = JObject.Parse(runningTask); runningTask = runningTask.Replace("\r\n", ""); ViewBag.RunningTaskList = runningTask.Replace("\\\\", "\\\\\\\\"); System.Diagnostics.Debug.Print(runningTask); //ViewBag.RunningTaskList = await apiHelper.callAPIService("GET", Global._operationTaskEndPoint, null); /* Setup Company Name and Company Photo on Page */ CompanyModel companyModel = new CompanyModel(); CompanySession compSession = await companyModel.GetCompanySessionData(); ViewBag.CompanyId = compSession.id; ViewBag.CompanyName = compSession.shortName; ViewBag.CompanyPhotoURL = compSession.photoURL; /* Setup Employee Data on Page */ ViewBag.FirstName = empSession.firstName; ViewBag.LastName = empSession.lastName; ViewBag.Email = empSession.email; ViewBag.PhotoURL = empSession.photoURL; ViewBag.PermissionList = empSession.permissions; /* Setup Menu Item Active */ ViewBag.MenuNavigation = empSession.navigationMenu; ViewBag.MenuItem = "menuMonitor"; } catch (Exception ex) { LoginMsgSession loginMsgSession = new LoginMsgSession(); if (ex.Message.ToLower() == "invalid session") { loginMsgSession.toastLevel = "warning"; loginMsgSession.message = "[[[Please Login]]]"; } else { loginMsgSession.toastLevel = "error"; loginMsgSession.message = "[[[Authentication Fail]]]."; StringBuilder logMessage = new StringBuilder(); logMessage.AppendLine("audit: Authentication Fail."); logMessage.AppendLine("email:" + empSession.email); logMessage.AppendLine("password:"******"loginMsgSession"] = loginMsgSession.Serialize(); return(RedirectToAction("Index", "Home")); } return(View()); }