using Foresight.Fleet.Services.User; using Foresight.ServiceModel; using IronIntel.Services; using Newtonsoft.Json; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace IronIntel.Contractor.Site.Maintenance { public class MaintenanceBasePage : ContractorBasePage { protected void ProcessRequest(string methodName) { object result = null; if (methodName != null) { switch (methodName.ToUpper()) { case "GETNAVS": result = GetNavigations(); break; } } string json = JsonConvert.SerializeObject(result); Response.Write(json); Response.End(); } private MaintenanceNavigateItem[] GetNavigations() { List list = GetNavigateItems(); LicenseInfo license = SystemParams.GetLicense(); if (license != null && license.Items.Count > 0) { var alitem = license.Items.FirstOrDefault(m => m.Key == "AlertsManagement"); if (alitem == null || !Helper.IsTrue(alitem.Value)) { MaintenanceNavigateItem item = list.FirstOrDefault(m => m.ID == "nav_alertsmanagement"); list.Remove(item); } var woitem = license.Items.FirstOrDefault(m => m.Key == "WorkOrder"); if (woitem == null || !Helper.IsTrue(woitem.Value)) { MaintenanceNavigateItem item = list.FirstOrDefault(m => m.ID == "nav_workorder"); list.Remove(item); } var fuelitem = license.Items.FirstOrDefault(m => m.Key == "FuelRecords"); if (fuelitem == null || !Helper.IsTrue(fuelitem.Value)) { MaintenanceNavigateItem item = list.FirstOrDefault(m => m.ID == "nav_fuelrecord"); list.Remove(item); } } var user = GetCurrentUser(); if (user.UserType == Users.UserTypes.Common) { var client = FleetServiceClientHelper.CreateClient(); Tuple[] pmss = client.GetUserPermissions(SystemParams.CompanyID, user.IID); if (pmss.Length > 0) { Tuple alertpm = pmss.FirstOrDefault(m => m.Item1.Id == Feature.ALERTS_MANAGEMENT); if (alertpm == null) { MaintenanceNavigateItem item = list.FirstOrDefault(m => m.ID == "nav_alertsmanagement"); list.Remove(item); } Tuple wopm = pmss.FirstOrDefault(m => m.Item1.Id == Feature.WORK_ORDER); if (wopm == null) { MaintenanceNavigateItem item = list.FirstOrDefault(m => m.ID == "nav_workorder"); list.Remove(item); } Tuple pmpm = pmss.FirstOrDefault(m => m.Item1.Id == Feature.PREVENTATIVE_MAINTENANCE); if (pmpm == null) { MaintenanceNavigateItem item1 = list.FirstOrDefault(m => m.ID == "nav_preventative"); list.Remove(item1); MaintenanceNavigateItem item2 = list.FirstOrDefault(m => m.ID == "nav_timebased"); list.Remove(item2); MaintenanceNavigateItem item3 = list.FirstOrDefault(m => m.ID == "nav_hours"); list.Remove(item3); MaintenanceNavigateItem item4 = list.FirstOrDefault(m => m.ID == "nav_absolutedistance"); list.Remove(item4); MaintenanceNavigateItem item5 = list.FirstOrDefault(m => m.ID == "nav_relativedistance"); list.Remove(item5); MaintenanceNavigateItem item6 = list.FirstOrDefault(m => m.ID == "nav_record"); list.Remove(item6); } Tuple fuelpm = pmss.FirstOrDefault(m => m.Item1.Id == Feature.FUEL_RECORDS); if (fuelpm == null) { MaintenanceNavigateItem item = list.FirstOrDefault(m => m.ID == "nav_fuelrecord"); list.Remove(item); } } } return list.ToArray(); } private static List GetNavigateItems() { List list = new List(); MaintenanceNavigateItem item1 = new MaintenanceNavigateItem(); item1.ID = "nav_alertsmanagement"; item1.Title = "Alerts Management **New**"; item1.Url = "AlertsManagement.aspx"; item1.IconPath = "img/alert.png"; list.Add(item1); MaintenanceNavigateItem item6 = new MaintenanceNavigateItem(); item6.ID = "nav_workorder"; item6.Title = "Work Order **New**"; item6.Url = "WorkOrderMaintenance.aspx"; item6.IconPath = "img/workorder.png"; list.Add(item6); MaintenanceNavigateItem item3 = new MaintenanceNavigateItem(); item3.ID = "nav_preventative"; item3.Title = "Absolute Hours Maintenance"; item3.Url = "PreventativeMaintenance.aspx"; item3.IconPath = "img/preventative.png"; list.Add(item3); MaintenanceNavigateItem item4 = new MaintenanceNavigateItem(); item4.ID = "nav_timebased"; item4.Title = "Relative Time Maintenance"; item4.Url = "TimeBasedMaintenance.aspx"; item4.IconPath = "img/timebased.png"; list.Add(item4); MaintenanceNavigateItem item7 = new MaintenanceNavigateItem(); item7.ID = "nav_hours"; item7.Title = "Relative Hours Maintenance"; item7.Url = "HoursMaintenance.aspx"; item7.IconPath = "img/hours.png"; list.Add(item7); MaintenanceNavigateItem item5 = new MaintenanceNavigateItem(); item5.ID = "nav_absolutedistance"; item5.Title = "Absolute Distance Maintenance"; item5.Url = "AbsoluteDistanceMaintenance.aspx"; item5.IconPath = "img/preventative.png"; list.Add(item5); MaintenanceNavigateItem item8 = new MaintenanceNavigateItem(); item8.ID = "nav_relativedistance"; item8.Title = "Relative Distance Maintenance"; item8.Url = "RelativeDistanceMaintenance.aspx"; item8.IconPath = "img/hours.png"; list.Add(item8); MaintenanceNavigateItem item2 = new MaintenanceNavigateItem(); item2.ID = "nav_record"; item2.Title = "Maintenance Record **Legacy**"; item2.Url = "MaintanceRecordsManagement.aspx"; item2.IconPath = "img/record.png"; list.Add(item2); MaintenanceNavigateItem item9 = new MaintenanceNavigateItem(); item9.ID = "nav_fuelrecord"; item9.Title = "Fuel Records"; item9.Url = "FuelRecordManagement.aspx"; item9.IconPath = "img/fuelrecord.png"; list.Add(item9); return list; } public class MaintenanceNavigateItem { public string ID { get; set; } public string Title { get; set; } public string Url { get; set; } public string IconPath { get; set; } } } }