private void dSelectedAttributesEventSetter_OnHandlerDelete(object sender, MouseButtonEventArgs e)
        {
            MessageBoxResult messageBoxResult = MessageBox.Show("Are you sure to delete Attribute for the selected Material", "Delete Confirmation", MessageBoxButton.YesNo);

            if (messageBoxResult == MessageBoxResult.Yes)
            {
                object source   = e.OriginalSource;
                string isDelete = ((DataGridCell)sender).Column.Header.ToString().ToUpperInvariant();
                if (source.GetType() == typeof(Image) && isDelete == "DELETE")
                {
                    DataGridRow           deletedSelectedRow = FindParent <DataGridRow>(sender as DependencyObject);
                    MaterialGridAttribute objSelectedMaterialGridAttribute = (MaterialGridAttribute)deletedSelectedRow.DataContext;
                    lSelectedModels.Remove(objSelectedMaterialGridAttribute);
                    int iMaterialId = Convert.ToInt32(dMaterials.SelectedValue);
                    objDataAccess.DeleteAttributeFromMaterial(iMaterialId, objSelectedMaterialGridAttribute.Attribute.AttributeId);
                    objSelectedMaterialGridAttribute.IsSelected = false;
                    lAttributeModels.Add(objSelectedMaterialGridAttribute);
                    dAllAttributes.ItemsSource      = null;
                    dSelectedAttributes.ItemsSource = null;
                    dAllAttributes.ItemsSource      = lAttributeModels;
                    dSelectedAttributes.ItemsSource = lSelectedModels;
                    MessageBox.Show("Attribute for the selected Material deleted successfully");
                    // Reload Grid
                }
            }
        }
        public void LoadAttributes()
        {
            List <AttributeModel>        lAttributes            = objDataAccess.GetAllAttributes();
            List <MaterialGridAttribute> lMaterialGridAttribute = new List <MaterialGridAttribute>();

            lAttributes.ForEach(p => {
                MaterialGridAttribute objMaterialGridAttribute = new MaterialGridAttribute()
                {
                    Attribute  = p,
                    IsSelected = false
                };
                lMaterialGridAttribute.Add(objMaterialGridAttribute);
            });
            dAllAttributes.ItemsSource = lMaterialGridAttribute;
        }
        private void bReOrderDownButton_Click(object sender, RoutedEventArgs e)
        {
            MaterialGridAttribute objSelectedAttribute = (MaterialGridAttribute)dSelectedAttributes.SelectedValue;
            int selectedIndex = dSelectedAttributes.SelectedIndex;

            if (selectedIndex >= dSelectedAttributes.Items.Count - 1)
            {
                return;
            }

            List <MaterialGridAttribute> selectedAttributes = (List <MaterialGridAttribute>)dSelectedAttributes.ItemsSource;

            selectedAttributes.RemoveAt(selectedIndex);
            selectedAttributes.Insert(selectedIndex + 1, objSelectedAttribute);
            dSelectedAttributes.ItemsSource   = null;
            dSelectedAttributes.ItemsSource   = selectedAttributes;
            dSelectedAttributes.SelectedValue = objSelectedAttribute;
        }
        private void dMaterials_Selected(object sender, RoutedEventArgs e)
        {
            int iMaterialId = Convert.ToInt32(dMaterials.SelectedValue);
            List <MaterialAttribute> lSelectedMaterialAttribute = new List <MaterialAttribute>();

            if (iMaterialId != 0)
            {
                Material objSelectedMaterial = (Material)dMaterials.SelectedItem;
                dMaterialType.SelectedValue = objSelectedMaterial.MaterialType.Id;
                cIsEnable.IsChecked         = objSelectedMaterial.IsActive;


                lSelectedMaterialAttribute = objDataAccess.GetMaterialAttributesByMaterialId(objSelectedMaterial.Id);
                if (lSelectedModels == null)
                {
                    lSelectedModels = new List <MaterialGridAttribute>();
                }


                lSelectedModels.Clear();
                lSelectedMaterialAttribute.ForEach(p =>
                {
                    lSelectedModels.Add(new MaterialGridAttribute()
                    {
                        Attribute = new AttributeModel()
                        {
                            AttributeId     = p.Attribute.Id,
                            AttributeName   = p.Attribute.Name,
                            AttributeTypeId = p.Attribute.TypeId,
                            ParentId        = p.Attribute.ParentId == null ? 0 : (int)p.Attribute.ParentId
                        },
                        IsSelected = true
                    });
                });
                dSelectedAttributes.ItemsSource = null;
                dSelectedAttributes.ItemsSource = lSelectedModels;
            }
            else
            {
                lSelectedModels = new List <MaterialGridAttribute>();
                dSelectedAttributes.ItemsSource = null;
            }
            List <AttributeModel> lAllAttributes = objDataAccess.GetAllAttributes();

            if (lAttributeModels == null)
            {
                lAttributeModels = new List <MaterialGridAttribute>();
            }
            lAttributeModels.Clear();
            int[] distinctSelectedAttributeId = lSelectedMaterialAttribute?.Select(p => p.AttributeId).ToArray();
            var   AllAttributes = lAllAttributes.Where(p => !distinctSelectedAttributeId.Contains(p.AttributeId));

            AllAttributes.ToList().ForEach(p => {
                MaterialGridAttribute objMaterialGridAttribute = new MaterialGridAttribute()
                {
                    Attribute  = p,
                    IsSelected = false
                };
                lAttributeModels.Add(objMaterialGridAttribute);
            });
            dAllAttributes.ItemsSource = null;
            dAllAttributes.ItemsSource = lAttributeModels;
        }