public AddEquipment(ObservableCollection <Equipment> list,
                            ObservableCollection <Attribute> listA,
                            Entities en,
                            ObservableCollection <Fabricator> ListFabricators,
                            ObservableCollection <Сategories> ListСategories,
                            ObservableCollection <string> ListCodes,
                            Equipment editEquipment)
        {
            InitializeComponent();

            fabricatorEquipmentComboBox.ItemsSource = ListFabricators;
            categoriesEquipmentComboBox.ItemsSource = ListСategories;
            attributesEquipmentComboBox.ItemsSource = listA;
            this.entities       = en;
            this.ListEquipment  = list;
            this.ListAttributes = listA;

            if (editEquipment != null)
            {
                create = false;
                EquipmentTitle.Content  = "Изменение оборудования";
                createEquipment.Content = "изменить";
                this.equipment          = editEquipment;
                id   = editEquipment.id_equipment;
                name = equipment.name_equipment;
                codeEquipmentTextBox.Text = equipment.code_equipment;
                nameEquipmentTextBox.Text = equipment.name_equipment;
                new TextRange(descriptionEquipmentTextBox.Document.ContentStart, descriptionEquipmentTextBox.Document.ContentEnd).Text = equipment.description_equipment;
                fabricatorEquipmentComboBox.SelectedValue = equipment.fabricator_equipment;
                categoriesEquipmentComboBox.SelectedValue = (int)equipment.category_equipment;
                priceEquipmentTextBox.Text = equipment.price_equipment.ToString();

                for (int i = 0; i < equipment.Attributes_Values.Count; i++)
                {
                    Attributes_Values av  = equipment.Attributes_Values.ElementAt(i);
                    Attribute         att = av.Attribute;
                    ListAttWas.Add(att);
                    WrapPanel wp = new WrapPanel
                    {
                        Margin = new System.Windows.Thickness(10),
                    };
                    attributesPanel.Children.Add(wp);
                    Label label = new Label
                    {
                        Content = att.name_attribute + ": ",
                    };
                    TextBox txB = new TextBox
                    {
                        Name  = att.name_attribute,
                        Width = 100,
                        Text  = av.value_aValues,
                        HorizontalAlignment = System.Windows.HorizontalAlignment.Right,
                    };
                    wp.Children.Add(label);
                    wp.Children.Add(txB);
                }
            }
            this.ListCodes = ListCodes;
        }
        public void Do()
        {
            try
            {
                equipment = new Equipment();
                equipment.code_equipment        = codeEquipmentTextBox.Text;
                equipment.name_equipment        = nameEquipmentTextBox.Text;
                equipment.description_equipment = new TextRange(descriptionEquipmentTextBox.Document.ContentStart, descriptionEquipmentTextBox.Document.ContentEnd).Text;
                Fabricator fabricator = fabricatorEquipmentComboBox.SelectedItem as Fabricator;
                equipment.fabricator_equipment = fabricator.id_fabricator;
                Сategories category = categoriesEquipmentComboBox.SelectedItem as Сategories;
                equipment.category_equipment = category.id_category;
                equipment.price_equipment    = Convert.ToDecimal(priceEquipmentTextBox.Text);

                WrapPanel[]      w     = attributesPanel.Children.OfType <WrapPanel>().ToArray();
                TextBox[]        t     = new TextBox[w.Count()];
                AttributeArray[] array = new AttributeArray[w.Count()];
                for (int i = 0; i < w.Count(); i++)
                {
                    t        = w[i].Children.OfType <TextBox>().ToArray();
                    array[i] = new AttributeArray(t[0].Name, t[0].Text);
                }

                foreach (Attribute item in ListAttributes)
                {
                    for (int i = 0; i < array.Count(); i++)
                    {
                        if (item.name_attribute == array[i].name)
                        {
                            Attributes_Values av = new Attributes_Values();
                            av.value_aValues     = array[i].value;
                            av.attribute_aValues = item.id_attribute;
                            if (id != 0)
                            {
                                av.equipment_aValues = id;
                            }
                            else
                            {
                                av.equipment_aValues = equipment.id_equipment;
                            }
                            equipment.Attributes_Values.Add(av);
                            item.Attributes_Values.Add(av);
                        }
                    }
                }

                if (create)
                {
                    equipment.col_equipment = 0;
                    entities.Equipments.Add(equipment);
                }
                else
                {
                    foreach (Equipment eq in ListEquipment)
                    {
                        if (eq.name_equipment == name)
                        {
                            eq.name_equipment        = equipment.name_equipment;
                            eq.code_equipment        = equipment.code_equipment;
                            eq.description_equipment = equipment.description_equipment;
                            eq.fabricator_equipment  = equipment.fabricator_equipment;
                            eq.category_equipment    = equipment.category_equipment;
                            eq.price_equipment       = equipment.price_equipment;
                            eq.Attributes_Values     = equipment.Attributes_Values;
                        }
                    }
                }
                entities.SaveChanges();
                this.DialogResult = true;
            }
            catch (Exception ex)
            {
                this.ShowMessageAsync("Ошибка", ex.ToString());
            }
        }