public void SetCustomerLocalizationModel(int customerId, CustomerLocalizationModel customerLocalizationModel)
        {
            var customerProfile = RbacEntities.CustomerProfiles.FirstOrDefault(m => m.CustomerId == customerId);

            // Language
            var     settingFactory = new SettingsFactory();
            Setting setting        = settingFactory.GetListValue("Locale", customerLocalizationModel.LanguageId);

            if (setting != null)
            {
                settingFactory.Set(customerId, "CustomerLocale", setting.Value);

                // Write the local to customer.DefaultLocale also
                customerProfile.DefaultLocale = setting.Value;
            }


            // 12/ 24 hour format
            customerProfile.Is24HrFormat = customerLocalizationModel.Is24Hr;

            // TimeZone
            customerProfile.TimeZoneID = customerLocalizationModel.TimeZoneId;
            // Save changes.
            RbacEntities.SaveChanges();
        }
        public CustomerLocalizationModel GetCustomerLocalizationModel(int customerId)
        {
            var customerLocalizationModel = new CustomerLocalizationModel();

            // TimeZone
            // Get presently assign zone id.
            var customerProfile = RbacEntities.CustomerProfiles.FirstOrDefault(m => m.CustomerId == customerId);

            customerLocalizationModel.TimeZoneId = customerProfile == null ? -1 : customerProfile.TimeZoneID ?? -1;

            // Get list of possible zones.

            customerLocalizationModel.TimeZone.Add(new SelectListItem()
            {
                Text     = "[Select Time Zone]",
                Value    = "-1",
                Selected = customerLocalizationModel.TimeZoneId == -1
            });

            if (customerLocalizationModel.TimeZoneId == -1)
            {
                customerLocalizationModel.TimeZoneDisplay = "";
            }

            foreach (var timeZone in RbacEntities.CustomerTimeZones)
            {
                customerLocalizationModel.TimeZone.Add(new SelectListItem()
                {
                    Text     = timeZone.TimeZoneName,
                    Value    = timeZone.TimeZoneID.ToString(),
                    Selected = customerLocalizationModel.TimeZoneId == timeZone.TimeZoneID
                });
                if (customerLocalizationModel.TimeZoneId == timeZone.TimeZoneID)
                {
                    customerLocalizationModel.TimeZoneDisplay = timeZone.TimeZoneName;
                }
            }
            // Language
            customerLocalizationModel.LanguageDisplay = "";
            var    settingFactory = new SettingsFactory();
            string locale         = settingFactory.GetValue("CustomerLocale", customerId);

            customerLocalizationModel.Language = new List <SelectListItem>();
            List <Setting> settingList = settingFactory.GetList("Locale");

            foreach (Setting setting in settingList)
            {
                SelectListItem selectListItem = new SelectListItem()
                {
                    Text  = setting.Value,
                    Value = setting.Id.ToString()
                };
                if (locale != null && locale.Equals(setting.Value))
                {
                    selectListItem.Selected = true;
                    customerLocalizationModel.LanguageId      = setting.Id;
                    customerLocalizationModel.LanguageDisplay = locale;
                }
                else
                {
                    selectListItem.Selected = setting.Default;
                    if (selectListItem.Selected)
                    {
                        customerLocalizationModel.LanguageId = setting.Id;
                    }
                }

                customerLocalizationModel.Language.Add(selectListItem);
            }
            // Is there a selected or default item?  If not add a "select X" item.
            if (customerLocalizationModel.LanguageId == 0)
            {
                customerLocalizationModel.Language.Insert(0,
                                                          new SelectListItem()
                {
                    Text     = "[Select Language]",
                    Value    = "0",
                    Selected = true
                });
            }

            // 12/24 Hour Clock
            customerLocalizationModel.Is24Hr = false;
            var customer = RbacEntities.CustomerProfiles.FirstOrDefault(m => m.CustomerId == customerId);

            if (customer != null)
            {
                customerLocalizationModel.Is24Hr = customer.Is24HrFormat ?? false;
            }


            return(customerLocalizationModel);
        }
Example #3
0
 public MaintenanceGroupIdentificationModel()
 {
     Status       = new CustomerStatusModel();
     Contact      = new CustomerContactModel();
     Localization = new CustomerLocalizationModel();
 }