private void AddSetting(SystemSetting setting)
 {
     if (!_settings.Contains(setting))
     {
         _context.AddToSystemSettings(setting);
         _settings.Add(setting);
     }
 }
Ejemplo n.º 2
0
 private void InsertSystemSetting(string subType, string settingName, string settingValue, string description)
 {
     using (EnterpriseTestContext context = new EnterpriseTestContext())
     {
         if (!context.SystemSettings.Any(s => s.Name.Equals(settingName, StringComparison.InvariantCultureIgnoreCase)))
         {
             SystemSetting newSetting = new SystemSetting()
             {
                 Type        = SettingType.SystemSetting.ToString(),
                 SubType     = subType,
                 Name        = settingName,
                 Value       = settingValue,
                 Description = description
             };
             context.AddToSystemSettings(newSetting);
             context.SaveChanges();
         }
     }
 }
        private bool ValidateEntities()
        {
            foreach (DataGridViewRow row in settings_DataGridView.Rows)
            {
                SystemSetting setting = row.DataBoundItem as SystemSetting;

                if (setting != null && setting.EntityState == EntityState.Added)
                {
                    if (string.IsNullOrEmpty(setting.Type))
                    {
                        MessageBox.Show
                        (
                            "The Type must have a value",
                            "Setting Type Missing Value",
                            MessageBoxButtons.OK,
                            MessageBoxIcon.Error
                        );
                        return(false);
                    }

                    if (string.IsNullOrEmpty(setting.Name))
                    {
                        MessageBox.Show
                        (
                            "The Name must not be blank",
                            "Setting Name Missing Value",
                            MessageBoxButtons.OK,
                            MessageBoxIcon.Error
                        );
                        return(false);
                    }

                    if (string.IsNullOrEmpty(setting.Value))
                    {
                        MessageBox.Show
                        (
                            "The Value must not be blank",
                            "Setting Value Missing Value",
                            MessageBoxButtons.OK,
                            MessageBoxIcon.Error
                        );
                        return(false);
                    }

                    var exists =
                        (
                            from s in _context.SystemSettings
                            where s.Name.Equals(setting.Name, StringComparison.OrdinalIgnoreCase)
                            select s
                        ).Any();

                    if (exists)
                    {
                        MessageBox.Show
                        (
                            "A setting entry with Name = '{0}' already exists.".FormatWith(setting.Name),
                            "Duplicate Setting Value",
                            MessageBoxButtons.OK,
                            MessageBoxIcon.Error
                        );
                        return(false);
                    }

                    _context.AddToSystemSettings(setting);
                }
            }

            return(true);
        }