using Foresight.Data; using Foresight.Fleet.Services.AssetHealth; using Foresight.Fleet.Services.AssetHealth.WorkOrder; using Foresight.Fleet.Services.JobSite; using Foresight.Fleet.Services.User; using Foresight.ServiceModel; using IronIntel.Contractor.Machines; using IronIntel.Contractor.Maintenance; using Newtonsoft.Json; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Web; namespace IronIntel.Contractor.Site.Maintenance { public class AlertsBasePage : ContractorBasePage { protected void ProcessRequest(string method) { object result = null; try { string methodName = Request.Params["MethodName"]; if (methodName != null) { switch (methodName.ToUpper()) { case "GETALERTS": result = GetAlerts(); break; case "GETMACHINEALERTS": result = GetMachineAlerts(); break; case "GETPMALERTSERVICEDESCRIPTIONS": result = GetPMAlertServiceDescriptions(); break; case "SAVEACKNOWLEDGEALERT": result = SaveAcknowledgeAlert(); break; case "ASSIGNEDALERTSTOWORKORDER": result = AssignedAlertsToWorkOrder(); break; case "GETALERTSLISENCE": result = GetAlertsLisence(); break; case "GETWORKORDERALERTS": result = GetWorkOrderAlerts(); break; case "GETASSETALERTS": result = GetAssetAlerts(); break; case "GETASSETGROUPS": result = GetAssetGroups(); break; case "GETALERTTYPES": result = GetAlertTypes(); break; case "GETACKNOWLEDGEDALERTS": result = GetAcknowledgedAlerts(); break; case "GETJOBSITES": result = GetJobsites(); break; case "SAVEAUTOACKNOWLEDGEALERTTYPES": result = SaveAutoAcknowledgeAlertTypes(); break; case "GETAUTOACKNOWLEDGEALERTTYPES": result = GetAutoAcknowledgeAlertTypes(); break; case "GETAUTOACKNOWLEDGEALERTTYPESHISTORY": result = GetAutoAcknowledgeAlertTypesHistory(); break; case "GETWORKORDERGENERATORS": result = GetWorkOrderGenerators(); break; case "SAVEWORKORDERGENERATOR": result = SaveWorkOrderGenerator(); break; case "DELETEWORKORDERGENERATOR": result = DeleteWorkOrderGenerator(); break; case "GETASSIGNTOS": result = GetAssignTos(); break; } } } catch (Exception ex) { SystemParams.WriteLog("error", "AlertsBasePage", ex.Message, ex.ToString()); throw ex; } string json = JsonConvert.SerializeObject(result); Response.Write(json); Response.End(); } private object GetAlerts() { try { var session = GetCurrentLoginSession(); if (GetCurrentLoginSession() != null) { var clientdata = Context.Request.Params["ClientData"]; AlertQueryParams alertparam = JsonConvert.DeserializeObject(clientdata); DateTime beginDate = Helper.DBMinDateTime; DateTime endDate = DateTime.MaxValue; if (!DateTime.TryParse(alertparam.BeginDate, out beginDate)) beginDate = Helper.DBMinDateTime; //else // beginDate = beginDate.ToUniversalTime(); if (!DateTime.TryParse(alertparam.EndDate, out endDate)) endDate = DateTime.MaxValue; int assigned = -1; int completed = -1; if (alertparam.AlertStatus != null && alertparam.AlertStatus.Length > 0) { if (alertparam.AlertStatus.Contains("Unassigned") && !alertparam.AlertStatus.Contains("Assigned")) assigned = 0; if (!alertparam.AlertStatus.Contains("Unassigned") && alertparam.AlertStatus.Contains("Assigned")) assigned = 1; if (alertparam.AlertStatus.Contains("Completed") && !alertparam.AlertStatus.Contains("Uncompleted")) completed = 1; if (!alertparam.AlertStatus.Contains("Completed") && alertparam.AlertStatus.Contains("Uncompleted")) completed = 0; } alertparam.SearchText = HttpUtility.HtmlDecode(alertparam.SearchText); AssetAlertGridViewItem[] assetalerts = null; if (alertparam.AssetID > 0) assetalerts = CreateClient().GetAssetAlertGridViewItemsByAsset(SystemParams.CompanyID, alertparam.AssetID, beginDate, endDate, alertparam.AlertTypes, alertparam.JobSites, assigned, completed, alertparam.SearchText, alertparam.IncludeunCompleted); else assetalerts = CreateClient().GetAssetAlertGridViewItems(SystemParams.CompanyID, beginDate, endDate, alertparam.AlertTypes, alertparam.AssetGroups, alertparam.JobSites, assigned, completed, alertparam.SearchText, session.User.UID, alertparam.IncludeunCompleted); if (assetalerts == null || assetalerts.Length == 0) return new AlertInfo[0]; List list = new List(); foreach (AssetAlertGridViewItem item in assetalerts) { AlertInfo ai = ConvertAlertObj(item); list.Add(ai); } return list.ToArray(); } else return new AlertInfo[0]; } catch (Exception ex) { AddLog("ERROR", "AlertsBasePage.GetAlerts", ex.Message, ex.ToString()); return ex.Message; } } private object GetMachineAlerts() { try { var session = GetCurrentLoginSession(); if (GetCurrentLoginSession() != null) { var clientdata = Context.Request.Params["ClientData"]; AlertQueryParams alertparam = JsonConvert.DeserializeObject(clientdata); DateTime beginDate = Helper.DBMinDateTime; DateTime endDate = DateTime.MaxValue; if (!DateTime.TryParse(alertparam.BeginDate, out beginDate)) beginDate = Helper.DBMinDateTime; //else // beginDate = beginDate.ToUniversalTime(); if (!DateTime.TryParse(alertparam.EndDate, out endDate)) endDate = DateTime.MaxValue; int assigned = -1; int completed = -1; if (alertparam.AlertStatus != null && alertparam.AlertStatus.Length > 0) { if (alertparam.AlertStatus.Contains("Unassigned") && !alertparam.AlertStatus.Contains("Assigned")) assigned = 0; if (!alertparam.AlertStatus.Contains("Unassigned") && alertparam.AlertStatus.Contains("Assigned")) assigned = 1; if (alertparam.AlertStatus.Contains("Completed") && !alertparam.AlertStatus.Contains("Uncompleted")) completed = 1; if (!alertparam.AlertStatus.Contains("Completed") && alertparam.AlertStatus.Contains("Uncompleted")) completed = 0; } alertparam.SearchText = HttpUtility.HtmlDecode(alertparam.SearchText); AssetAlertGridViewItem[] assetalerts = null; if (alertparam.AssetID > 0) assetalerts = CreateClient().GetAssetAlertGridViewItemsByAsset(SystemParams.CompanyID, alertparam.AssetID, beginDate, endDate, alertparam.AlertTypes, alertparam.JobSites, assigned, completed, alertparam.SearchText, alertparam.IncludeunCompleted); else assetalerts = CreateClient().GetAssetAlertGridViewItems(SystemParams.CompanyID, beginDate, endDate, alertparam.AlertTypes, alertparam.AssetGroups, alertparam.JobSites, assigned, completed, alertparam.SearchText, session.User.UID, alertparam.IncludeunCompleted); if (assetalerts == null || assetalerts.Length == 0) return new MachineInfoForAlert[0]; List machinealerts = new List(); foreach (AssetAlertGridViewItem item in assetalerts) { AlertInfo ai = ConvertAlertObj(item); MachineInfoForAlert mi = machinealerts.FirstOrDefault((i) => i.MachineID == ai.MachineID); if (mi == null) { mi = new MachineInfoForAlert(); mi.MachineID = ai.MachineID; mi.MachineName = ai.MachineName; mi.VIN = ai.VIN; mi.Make = ai.Make; mi.Model = ai.Model; mi.EngineHours = ai.CurrentHours; mi.OpenWorkOrders = ai.OpenWorkOrderCount; machinealerts.Add(mi); } mi.Alerts.Add(ai); int count = ai.RepeatedAlerts.Count + 1; if (ai.AlertType == "Preventative Maintenance" || ai.AlertType == "PM_ALERT" || ai.AlertType == "TBM_ALERT" || ai.AlertType == "HM_ALERT" || ai.AlertType == "RDM_ALERT" || ai.AlertType == "ADM_ALERT") mi.PMAlertCount += count; else if (INSPECT.Contains(ai.AlertType, StringComparer.OrdinalIgnoreCase)) mi.InspectAlertCount += count; else mi.DTCAlertCount += count; if (ai.AlertLocalTime > mi.LatestAlertDateTime) mi.LatestAlertDateTime = ai.AlertLocalTime; } return machinealerts.ToArray(); } else return new MachineInfoForAlert[0]; } catch (Exception ex) { AddLog("ERROR", "AlertsBasePage.GetAlerts", ex.Message, ex.ToString()); return ex.Message; } } private object GetPMAlertServiceDescriptions() { try { var session = GetCurrentLoginSession(); if (GetCurrentLoginSession() != null) { var clientdata = Context.Request.Params["ClientData"]; long[] alertids = JsonConvert.DeserializeObject(clientdata); return CreateClient().GetAlertServiceDescriptions(SystemParams.CompanyID, alertids); } return null; } catch (Exception ex) { AddLog("ERROR", "AlertsBasePage.GetPMAlertServiceDescriptions", ex.Message, ex.ToString()); return ex.Message; } } private AlertInfo ConvertAlertObj1(AssetAlertItem item) { AlertInfo ai = new AlertInfo(); ai.AlertID = item.ID; ai.AlertType = item.AlertType; ai.AlertLocalTime = item.AlertLocalTime; ai.Completed = item.Completed; ai.MachineID = item.AssetID; ai.Model = item.ModelName; ai.Make = item.MakeName; ai.VIN = item.VIN; ai.MachineName = item.AssetName; ai.EngineHours = item.EngineHours; ai.Description = item.Description; ai.Description = ai.FormatDescription(ai.Description); ai.ServiceDescription = item.ServiceDescription; ai.RepeatedAlerts = item.RepeatedAlerts; ai.AlertCount = item.RepeatedAlerts.Count + 1; ai.ScheduleID = item.ScheduleID; ai.IntervalID = item.IntervalID; ai.Recurring = item.Recurring; ai.Priority = item.Priority; ai.ExpectedCost = item.ExpectedCost; return ai; } private AlertInfo ConvertAlertObj(AssetAlertGridViewItem item) { AlertInfo ai = new AlertInfo(); ai.AlertID = item.ID; ai.WorkOrderID = item.WorkOrderId; ai.WorkOrderStatus = item.WorkOrderStatus; ai.AlertType = item.AlertType; ai.AlertTime_UTC = item.LastAlertTime; ai.AlertLocalTime = item.AlertLocalTime; ai.Completed = item.Completed; ai.MachineID = item.AssetID; //ai.ModelID = item.ModelName; ai.Model = item.ModelName; //ai.MakeID = item.MakeName; ai.Make = item.MakeName; ai.VIN = item.VIN; ai.MachineName = item.AssetName; ai.EngineHours = item.EngineHours; ai.CurrentHours = item.CurrentEngineHours; ai.Description = item.Description; ai.Description = ai.FormatDescription(ai.Description); //ai.ServiceDescription = item.ServiceDescription; ai.RepeatedAlerts = item.RepeatedAlerts; ai.AlertCount = item.RepeatedAlerts.Count + 1; ai.OpenWorkOrderCount = item.OpenWorkOrderCount; //ai.ScheduleID = item.ScheduleID; //ai.IntervalID = item.IntervalID; //ai.Recurring = item.Recurring; //ai.Priority = item.Priority; //ai.ExpectedCost = item.ExpectedCost; return ai; } private AlertInfo ConvertAlertObj2(AcknowledgedAlertItem item) { AlertInfo ai = new AlertInfo(); ai.AlertID = item.ID; ai.WorkOrderID = item.WorkOrderId; ai.AlertType = item.AlertType; ai.AlertTime_UTC = item.LastAlertTime; ai.AlertLocalTime = item.AlertLocalTime; ai.MachineID = item.AssetID; ai.Model = item.ModelName; ai.Make = item.MakeName; ai.VIN = item.VIN; ai.MachineName = item.AssetName; ai.EngineHours = item.EngineHours; ai.Description = item.Description; ai.Description = ai.FormatDescription(ai.Description); ai.RepeatedAlerts = item.RepeatedAlerts; ai.AlertCount = item.RepeatedAlerts.Count + 1; ai.OpenWorkOrderCount = item.OpenWorkOrderCount; ai.AcknowledgedByName = item.AcknowledgedBy; ai.AcknowledgedTime_UTC = item.AcknowledgedTime; ai.AcknowledgedTime_Local = item.AcknowledgedLocalTime; ai.AcknowledgedComment = item.AcknowledgedComment; return ai; } private object GetAcknowledgedAlerts() { try { var session = GetCurrentLoginSession(); if (GetCurrentLoginSession() != null) { var clientdata = Context.Request.Params["ClientData"]; AlertQueryParams alertparam = JsonConvert.DeserializeObject(clientdata); DateTime beginDate = Helper.DBMinDateTime; DateTime endDate = DateTime.MaxValue; if (!DateTime.TryParse(alertparam.BeginDate, out beginDate)) beginDate = Helper.DBMinDateTime; //else // beginDate = beginDate.ToUniversalTime(); if (!DateTime.TryParse(alertparam.EndDate, out endDate)) endDate = DateTime.MaxValue; alertparam.SearchText = HttpUtility.HtmlDecode(alertparam.SearchText); alertparam.AlertStatus = new string[0]; AcknowledgedAlertItem[] ackalerts = CreateClient().GetAcknowledgedAlerts(SystemParams.CompanyID, beginDate, endDate, alertparam.AlertTypes, alertparam.AssetGroups, alertparam.SearchText); if (ackalerts == null || ackalerts.Length == 0) return new AlertInfo[0]; List list = new List(); foreach (AcknowledgedAlertItem item in ackalerts) { AlertInfo ai = ConvertAlertObj2(item); list.Add(ai); } if (list == null) return new AlertInfo[0]; if (alertparam.AssetID > 0) list = list.Where(m => m.MachineID == alertparam.AssetID).ToList(); return list.ToArray(); } else return new AlertInfo[0]; } catch (Exception ex) { AddLog("ERROR", "AlertsBasePage.GetAcknowledgedAlerts", ex.Message, ex.ToString()); return ex.Message; } } private object GetAlertsLisence() { try { AlertsLisenceItem result = new AlertsLisenceItem(); if (GetCurrentLoginSession() != null) { Foresight.Fleet.Services.Customer.LicenseInfo license = SystemParams.GetLicense(); if (license != null && license.Items.Count > 0) { var woitem = license.Items.FirstOrDefault(m => m.Key == "WorkOrder"); if (woitem != null && Helper.IsTrue(woitem.Value)) result.WorkOrder = true; } result.AcknowledgingAlerts = Helper.IsTrue(SystemParams.GetStringParam("AcknowledgingAlerts")); } return result; } catch (Exception ex) { AddLog("ERROR", "AlertsBasePage.GetAlertsLisence", ex.Message, ex.ToString()); return ex.Message; } } private string SaveAcknowledgeAlert() { try { LoginSession se = GetCurrentLoginSession(); if (se != null) { var clientdata = Request.Form["ClientData"].Split((char)170); var ids = HttpUtility.HtmlDecode(clientdata[0]); var acknowledgmentcomment = HttpUtility.HtmlDecode(clientdata[1]); long[] list = JsonConvert.DeserializeObject(ids); AlertManager am = new AlertManager(SystemParams.DataDbConnectionString); am.AcknowledgeAlert(se.User.UID, list, acknowledgmentcomment); return "OK"; } else return "Failed"; } catch (Exception ex) { return ex.Message; } } private string AssignedAlertsToWorkOrder() { try { if (GetCurrentLoginSession() != null) { var clientdata = Request.Form["ClientData"].Split((char)170); var id = HttpUtility.HtmlDecode(clientdata[0]); var ids = HttpUtility.HtmlDecode(clientdata[1]); long workorderid = Convert.ToInt64(id); long[] alertids = JsonConvert.DeserializeObject(ids); if (alertids == null) alertids = new long[0]; var wp = CreateClient(); var existsalerts = wp.GetWorkOrderAlerts(SystemParams.CompanyID, workorderid).Select(a => a.ID); var added = alertids.Except(existsalerts).ToArray(); var deleted = existsalerts.Except(alertids).ToArray(); if (added.Length > 0) wp.AddOrRemoveAlertsFromWorkOrder(SystemParams.CompanyID, workorderid, added, true); if (deleted.Length > 0) wp.AddOrRemoveAlertsFromWorkOrder(SystemParams.CompanyID, workorderid, deleted, false); return "OK"; } else return "Failed"; } catch (Exception ex) { return ex.Message; } } private object GetWorkOrderAlerts() { try { var session = GetCurrentLoginSession(); if (session != null) { var clientdata = Request.Form["ClientData"]; long workorderid = 0; long.TryParse(clientdata, out workorderid); AlertItems items = WorkOrderManager.GetWorkOrderAlerts(workorderid, session.SessionID); if (items == null) return new AlertItems(); return new { WorkOrderID = workorderid, Data = items }; } else return new { WorkOrderID = -1, Data = new AlertItems() }; } catch (Exception ex) { AddLog("ERROR", "AlertsBasePage.GetWorkOrderAlerts", ex.Message, ex.ToString()); return ex.Message; } } private object GetAssetAlerts() { try { if (GetCurrentLoginSession() != null) { var clientdata = Request.Form["ClientData"].Split((char)170); var mid = HttpUtility.HtmlDecode(clientdata[0]); var ids = HttpUtility.HtmlDecode(clientdata[1]); long machineid = 0; long.TryParse(mid, out machineid); long[] alertids = JsonConvert.DeserializeObject(ids); AssetAlertItem[] alerts = CreateClient().GetNoneAssignedAlerts(SystemParams.CompanyID, machineid); //AssetAlertGridViewItem[] alerts = CreateClient().GetAssetAlertGridViewItemsByAsset(SystemParams.CompanyID, machineid, Helper.DBMinDateTime, DateTime.MaxValue, null, null, -1, -1, "", false); AlertItems items = new AlertItems(); if (alerts != null) { var dtcalerts = new List(); var pmaalerts = new List(); var inspectalerts = new List(); var oilalerts = new List(); Dictionary> pmalertdic = new Dictionary>(); foreach (var alertitem in alerts.OrderByDescending(ai => ai.AlertTime)) { if (alertids != null && alertids.Length > 0 && !alertids.Contains(alertitem.ID)) continue; List tempList = null; var category = DetermineAlertCategory(alertitem.AlertType); if (category == AssetAlertCategory.PMAlert) tempList = pmaalerts; else if (category == AssetAlertCategory.InspectAlert) tempList = inspectalerts; else if (category == AssetAlertCategory.OilSampleAlert) tempList = oilalerts; else tempList = dtcalerts; var a = ConvertAlertObj1(alertitem); a.RepeatedAlerts = alertitem.RepeatedAlerts; a.AlertCount = alertitem.RepeatedAlerts.Count + 1; tempList.Add(a); if (category == AssetAlertCategory.PMAlert) { if (!pmalertdic.ContainsKey(a.ScheduleID)) pmalertdic[a.ScheduleID] = new List(); pmalertdic[a.ScheduleID].Add(a); } } items.DTCAlerts = dtcalerts.ToArray(); items.PMAlerts = pmaalerts.ToArray(); items.InspectAlerts = inspectalerts.ToArray(); items.OilAlerts = oilalerts.ToArray(); items.AllExpectedCost = 0; foreach (var dic in pmalertdic) { items.AllExpectedCost += dic.Value.Where(m => !m.Recurring).Sum(m => m.ExpectedCost); int minPriority = dic.Value.Select(m => m.Priority).Min(); var recalerts = dic.Value.Where(m => m.Priority == minPriority && m.Recurring && m.ExpectedCost > 0); if (recalerts != null && recalerts.Count() > 0) items.AllExpectedCost += recalerts.Sum(m => m.ExpectedCost); } } return new { MachineID = machineid, Data = items }; } else return new { MachineID = -1, Data = new AlertInfo[0] }; } catch (Exception ex) { AddLog("ERROR", "AlertsBasePage.GetAssetAlerts", ex.Message, ex.ToString()); return ex.Message; } } private string SaveAutoAcknowledgeAlertTypes() { try { LoginSession session = GetCurrentLoginSession(); if (session != null) { var clientdata = Request.Form["ClientData"]; string[] alerttypes = JsonConvert.DeserializeObject(clientdata); CreateClient().SaveAutoAcknowledgeAlertTypes(SystemParams.CompanyID, alerttypes, session.User.UID); return "OK"; } else return "Failed"; } catch (Exception ex) { return ex.Message; } } private object GetAutoAcknowledgeAlertTypes() { try { if (GetCurrentLoginSession() != null) { string[] alerttypes = CreateClient().GetAutoAcknowledgeAlertTypes(SystemParams.CompanyID, GetCurrentLoginSession().User.UID); return alerttypes; } else return new string[0]; } catch (Exception ex) { AddLog("ERROR", "AlertsBasePage.GetAutoAcknowledgeAlertTypes", ex.Message, ex.ToString()); return ex.Message; } } private object GetAutoAcknowledgeAlertTypesHistory() { try { if (GetCurrentLoginSession() != null) { AutoAcknowledgeItem[] items = CreateClient().GetAutoAcknowledgeAlertTypesHistory(SystemParams.CompanyID, GetCurrentLoginSession().User.UID); if (items == null || items.Length == 0) return new AutoAcknowledgeInfo[0]; List ls = new List(); foreach (AutoAcknowledgeItem item in items) { AutoAcknowledgeInfo ai = new AutoAcknowledgeInfo(); Helper.CloneProperty(ai, item); ai.LocalUpdatedOn = ai.UpdatedOnLocal; ls.Add(ai); } return ls.OrderBy(m => m.LocalUpdatedOn).ToArray(); } else return new AutoAcknowledgeInfo[0]; } catch (Exception ex) { AddLog("ERROR", "AlertsBasePage.GetAutoAcknowledgeAlertTypesHistory", ex.Message, ex.ToString()); return ex.Message; } } private static readonly string[] PMALERTS = new string[] { "Preventative Maintenance" }; private static readonly string[] INSPECT = new string[] { "Red-Inspect", "Yellow-Inspect", "Green-Inspect", "Info-Inspect" }; private static readonly string[] OILSAMPLE = new string[] { "Oil Sample Result" }; private static AssetAlertCategory DetermineAlertCategory(string alerttype) { if (PMALERTS.Contains(alerttype, StringComparer.OrdinalIgnoreCase)) { return AssetAlertCategory.PMAlert; } if (INSPECT.Contains(alerttype, StringComparer.OrdinalIgnoreCase)) { return AssetAlertCategory.InspectAlert; } if (OILSAMPLE.Contains(alerttype, StringComparer.OrdinalIgnoreCase)) { return AssetAlertCategory.OilSampleAlert; } return AssetAlertCategory.DTCAlert; } private object GetAssetGroups() { try { var session = GetCurrentLoginSession(); if (session != null) { var groups = MachineManagement.GetMachineGroupsByUser(session.User.UID, null); List list = new List(); foreach (var gp in groups) { StringKeyValue kv = new StringKeyValue(); kv.Key = gp.GroupID; kv.Value = gp.GroupName; list.Add(kv); } return list.OrderBy((m) => m.Value).ToArray(); } else return new StringKeyValue[0]; } catch (Exception ex) { AddLog("ERROR", "AlertsBasePage.GetAssetGroups", ex.Message, ex.ToString()); return ex.Message; } } private object GetAssignTos() { try { var session = GetCurrentLoginSession(); if (session != null) { var users = Users.UserManagement.GetActiveUsers(session.SessionID, SystemParams.CompanyID); List list = new List(); foreach (var u in users) { StringKeyValue kv = new StringKeyValue(); kv.Key = u.IID; kv.Value = u.DisplayName; list.Add(kv); } list = list.OrderBy((m) => m.Value).ToList(); list.Insert(0, new StringKeyValue() { Key = "1", Value = "Alert Creator" }); list.Insert(1, new StringKeyValue() { Key = "2", Value = "First Assigned Contact in Managed Assets" }); return list.ToArray(); } else return new StringKeyValue[0]; } catch (Exception ex) { AddLog("ERROR", "AlertsBasePage.GetAssignTos", ex.Message, ex.ToString()); return ex.Message; } } private object GetJobsites() { try { var session = GetCurrentLoginSession(); if (session != null) { JobSiteItem[] jss = CreateClient().GetJobSiteItems(SystemParams.CompanyID, string.Empty, false); List list = new List(); foreach (JobSiteItem js in jss) { StringKeyValue kv = new StringKeyValue(); kv.Key = js.ID.ToString(); kv.Value = js.Name; list.Add(kv); } return list.OrderBy((m) => m.Value).ToArray(); } else return new StringKeyValue[0]; } catch (Exception ex) { AddLog("ERROR", "AlertsBasePage.GetAssetGroups", ex.Message, ex.ToString()); return ex.Message; } } private object GetAlertTypes() { try { if (GetCurrentLoginSession() != null) { AlertManager am = new AlertManager(SystemParams.DataDbConnectionString); return am.GetAlertTypes(); ; } else return new StringKeyValue[0]; } catch (Exception ex) { AddLog("ERROR", "AlertsBasePage.GetAlertTypes", ex.Message, ex.ToString()); return ex.Message; } } #region Work Order Generators private object GetWorkOrderGenerators() { try { if (GetCurrentLoginSession() != null) { WorkOrderGeneratorInfo[] generators = CreateClient().GetWorkOrderGenerators(SystemParams.CompanyID); if (generators == null) return new WorkOrderGeneratorInfo[0]; return generators; } else return new WorkOrderGeneratorInfo[0]; } catch (Exception ex) { AddLog("ERROR", "AlertsBasePage.GetWorkOrderGenerators", ex.Message, ex.ToString()); return ex.Message; } } private object SaveWorkOrderGenerator() { try { var session = GetCurrentLoginSession(); if (session != null) { var clientdata = Request.Form["ClientData"]; WorkOrderGeneratorInfo generator = JsonConvert.DeserializeObject(clientdata); if (generator.Id > 0) { CreateClient().UpdateWorkOrderGenerator(SystemParams.CompanyID, generator); } else { generator.Id = CreateClient().AddNewWorkOrderGenerator(SystemParams.CompanyID, generator); } return new string[] { generator.Id.ToString(), "" }; } else return "Failed"; } catch (Exception ex) { return ex.Message; } } private object DeleteWorkOrderGenerator() { try { var session = GetCurrentLoginSession(); if (session != null) { string id = HttpUtility.HtmlDecode(Request.Form["ClientData"]); CreateClient().DeleteWorkOrderGenerator(SystemParams.CompanyID, Convert.ToInt32(id)); return new string[0]; } return "Failed"; } catch (Exception ex) { return ex.Message; } } #endregion } public class AlertsLisenceItem { public bool WorkOrder = false; public bool AcknowledgingAlerts = false; } }