public int Save(GeneralSetting log)
        {
            GeneralSettingLocal setting = new GeneralSettingLocal
            {
                SettingKey = (int)log.SettingKey,
                SettingValue = log.SettingValue
            };

            GeneralSettingLocal exist = _GetByKey(setting.SettingKey);
            if (exist == null)
            {
                exist = new GeneralSettingLocal();
                _ctx.GeneralSettingLocal.Add(exist);
                exist.Id = setting.Id;
                exist.SettingKey = setting.SettingKey;
            }
            exist.SettingValue = setting.SettingValue;
            
            _ctx.SaveChanges();
            return exist.Id;
        }
        private void SaveReportUrl(Object obj)
        {
            ReportPassword = ((PasswordBox) obj).Password;
            if (!IsValidUri(ReportUrl.Trim()))
            {
                MessageBox.Show("Enter a Valid Reports Url", "Distributr Settings", MessageBoxButton.OK);
                return;
            }
            if (!ReportUrl.EndsWith("/"))
            {
                MessageBox.Show("Add '/' at the end of the url", "Distributr Settings", MessageBoxButton.OK);
                return;
            }
            else
            {
                try
                {
                    using (StructureMap.IContainer c = NestedContainer)
                    {
                        GeneralSetting setting = new GeneralSetting
                            {
                                SettingKey = GeneralSettingKey.ReportUrl,
                                SettingValue = ReportUrl.Trim()
                            };
                     Using<IGeneralSettingRepository>(c).Save(setting);
                     GeneralSetting username = new GeneralSetting
                     {
                         SettingKey = GeneralSettingKey.ReportUsername,
                         SettingValue = ReportUsername.Trim()
                     };
                     Using<IGeneralSettingRepository>(c).Save(username);
                     GeneralSetting password = new GeneralSetting
                     {
                         SettingKey = GeneralSettingKey.ReportPassword,
                         SettingValue =VCEncryption.EncryptString(ReportPassword),
                     };
                     Using<IGeneralSettingRepository>(c).Save(password);
                     GeneralSetting folder = new GeneralSetting
                     {
                         SettingKey = GeneralSettingKey.ReportFolder,
                         SettingValue = ReportFolder,
                     };
                     Using<IGeneralSettingRepository>(c).Save(folder);
                        if (report)
                            MessageBox.Show("Reports Url Saved", "Distributr Settings", MessageBoxButton.OK);
                    }
                }catch(Exception ex)
                {
                    MessageBox.Show("Error Occured", "Distributr Settings", MessageBoxButton.OK);
                }

            }
        }
        private void SaveSyncPageSize()
        {
             if (SyncPageSize < 100)
            {
                MessageBox.Show("Must be greater than 100 records", "Distributr: Sync Settings",
                                MessageBoxButton.OK);
                return;
            }

            var pagesizeSetting = new GeneralSetting()
            {
                SettingKey = GeneralSettingKey.SyncPageSize,
                SettingValue = SyncPageSize.ToString()
            };
            using (StructureMap.IContainer c = NestedContainer)
            {
                Using<IGeneralSettingRepository>(c).Save(pagesizeSetting);
            }
        }
        private void SaveRecordsPerPage()
        {
            using (StructureMap.IContainer c = NestedContainer)
            {
                if (RecordsPerPage < 5)
                {
                    MessageBox.Show("Must be at least 5 items per page", "Distributr: General Settings",
                                    MessageBoxButton.OK);
                    return;
                }

                var pgwsSetting = new GeneralSetting()
                                      {
                                          SettingKey = GeneralSettingKey.RecordsPerPage,
                                          SettingValue = RecordsPerPage.ToString()
                                      };
                Using<IGeneralSettingRepository>(c).Save(pgwsSetting);

                if (report)
                    MessageBox.Show("Records per page settings saved", "Distributr: General Settings",
                                    MessageBoxButton.OK);
            }
        }