public ActionResult Table()
        {
            try
            {
                // Get serilized settings
                var CashBidsSettings = new Models.CashBidsSettings();
                CashBidsSettings = JsonConvert.DeserializeObject <Models.CashBidsSettings>(ModuleContext.Configuration.ModuleSettings.GetValueOrDefault("CashBidsTableSettings", ""));
                CashBidsSettings.defaultLocation = new Models.Location();

                // Get portal settings
                var portalController = new PortalController();
                var portalID         = PortalController.Instance.GetCurrentPortalSettings().PortalId;
                var PortalSettings   = PortalController.Instance.GetPortalSettings(portalID);

                CashBidsSettings.WebCashBidsAPIKey = PortalSettings.ContainsKey("WebCashBidsAPIKey") ? PortalSettings["WebCashBidsAPIKey"] : "";
                CashBidsSettings.ServerCashBidsAPI = PortalSettings.ContainsKey("ServerCashBidsAPI") ? PortalSettings["ServerCashBidsAPI"] : "";
                CashBidsSettings.siteId            = PortalSettings.ContainsKey("SiteID") ? PortalSettings["SiteID"] : "";
                // Show table

                CashBidsSettings.visibleFields = CashBidsSettings.visibleFields.OrderBy(x => x.Order).ToList();

                return(View(CashBidsSettings));
            } catch (Exception ex) {
                var objEventLog = new EventLogController();
                objEventLog.AddLog("Cash Bids Table Exception", ex.ToString(), EventLogController.EventLogType.ADMIN_ALERT);

                var CashBidsSettings = new Models.CashBidsSettings();
                CashBidsSettings.defaultLocation = new Models.Location();
                return(View(CashBidsSettings));
            }
        }
        public ActionResult CashBidsTable(Models.CashBidsSettings settings)
        {
            // Get portal settings
            var portalID = PortalController.Instance.GetCurrentPortalSettings().PortalId;

            settings.hideCommodities = GetHiddenCommodityStrings(settings.hiddenCommodityCheckboxes);
            settings.hideLocations   = GetHiddenLocationStrings(settings.hiddenLocationCheckboxes);

            PortalController.Instance.UpdatePortalSetting(portalID, "WebCashBidsAPIKey", settings.WebCashBidsAPIKey, true, "en-US", false);
            PortalController.Instance.UpdatePortalSetting(portalID, "ServerCashBidsAPI", settings.ServerCashBidsAPI, true, "en-US", false);
            PortalController.Instance.UpdatePortalSetting(portalID, "SiteID", settings.siteId, true, "en-US", false);

            settings.WebCashBidsAPIKey = "";
            settings.siteId            = "";
            settings.ServerCashBidsAPI = "";

            ModuleContext.Configuration.ModuleSettings["CashBidsTableSettings"] = JsonConvert.SerializeObject(settings);
            return(RedirectToDefaultRoute());
        }
        public ActionResult CashBidsTable()
        {
            try
            {
                var settings = new Models.CashBidsSettings();

                var nonDeserializedSettings = ModuleContext.Configuration.ModuleSettings.GetValueOrDefault("CashBidsTableSettings", "");
                if (nonDeserializedSettings != "")
                {
                    settings = JsonConvert.DeserializeObject <CashBidsSettings>(nonDeserializedSettings);
                }

                if (settings.visibleFields.Count == 0)
                {
                    settings.visibleFields = new List <VisibleField>()
                    {
                        new VisibleField {
                            FieldName = "BASIS_PRICE", IsChecked = true, Order = 0
                        },
                        new VisibleField {
                            FieldName = "CASH_PRICE", IsChecked = true, Order = 1
                        },
                        new VisibleField {
                            FieldName = "DELIVERY_END", IsChecked = true, Order = 2
                        },
                        new VisibleField {
                            FieldName = "DELIVERY_START", IsChecked = true, Order = 3
                        },
                        new VisibleField {
                            FieldName = "FUTURES_CHANGE", IsChecked = true, Order = 4
                        },
                        new VisibleField {
                            FieldName = "FUTURES_QUOTE", IsChecked = true, Order = 5
                        },
                        new VisibleField {
                            FieldName = "SETTLE_PRICE", IsChecked = true, Order = 6
                        },
                        new VisibleField {
                            FieldName = "SYMBOL", IsChecked = true, Order = 7
                        },
                        new VisibleField {
                            FieldName = "UNIT_OF_MEASURE", IsChecked = true, Order = 8
                        }
                    };
                }

                settings.visibleFields = settings.visibleFields.OrderBy(x => x.Order).ToList();

                // Get portal settings
                var portalController = new PortalController();
                var portalID         = PortalController.Instance.GetCurrentPortalSettings().PortalId;
                var PortalSettings   = PortalController.Instance.GetPortalSettings(portalID);

                // Set portal settings after deserilization
                settings.WebCashBidsAPIKey = PortalSettings.ContainsKey("WebCashBidsAPIKey") ? PortalSettings["WebCashBidsAPIKey"] : "";
                settings.ServerCashBidsAPI = PortalSettings.ContainsKey("ServerCashBidsAPI") ? PortalSettings["ServerCashBidsAPI"] : "";
                settings.siteId            = PortalSettings.ContainsKey("SiteID") ? PortalSettings["SiteID"] : "";

                var objEventLog = new EventLogController();
                objEventLog.AddLog("Cash Bids Breadcrumbs", "Checking if api keys are set: " + settings.ToString(), EventLogController.EventLogType.ADMIN_ALERT);
                if (string.IsNullOrEmpty(settings.ServerCashBidsAPI) == false && string.IsNullOrEmpty(settings.siteId) == false)
                {
                    objEventLog.AddLog("Cash Bids Breadcrumbs", "Setting initializing cash bid API service", EventLogController.EventLogType.ADMIN_ALERT);
                    var DTNAPIService = new CashBidAPIService();
                    objEventLog.AddLog("Cash Bids Breadcrumbs", "Setting commodity checkboxes", EventLogController.EventLogType.ADMIN_ALERT);
                    var allowedCommodities = DTNAPIService.GetCommoditiesFromCashBids(settings.siteId).Result;
                    var allowedLocations   = DTNAPIService.GetSiteLocationsFromAPI(settings.siteId).Result;

                    objEventLog.AddLog("Cash Bids Breadcrumbs", "Setting commodity checkboxes", EventLogController.EventLogType.ADMIN_ALERT);
                    settings.hiddenCommodityCheckboxes = SetCommodityCheckboxes(allowedCommodities, settings);
                    settings.hiddenLocationCheckboxes  = SetLocationCheckboxes(allowedLocations, settings);
                }

                return(View(settings));
            }catch (Exception ex) {
                var objEventLog = new EventLogController();
                objEventLog.AddLog("Cash Bids Table Exception", ex.ToString(), EventLogController.EventLogType.ADMIN_ALERT);
                return(RedirectToDefaultRoute());
            }
        }