Example #1
0
        public static string CreateAllElectronicComponents(string name, string type, int pcbId, PCB pcb,
                                                           int namePowerSupplyId, PowerSupply namePowerSupply, string positionNumber, string datasheetLink)

        {
            var res = "уже существует";

            using (ApplicationContext db = new ApplicationContext())
            {
                //сущесствует ли электронный компонент
                var checkIsExist = db.ElectronicComponents.Any(ec => ec.Name == name);
                if (!checkIsExist)
                {
                    ElectronicComponent newEC = new ElectronicComponent
                    {
                        Name = name,
                        Type = type,

                        PCBId = pcb.Id,
                        //PCB = pcb,

                        NamePowerSupplyId = namePowerSupply.Id,
                        //NamePowerSupply = namePowerSupply,

                        PositionNumber = positionNumber,
                        DatasheetLink  = datasheetLink
                    };
                    db.ElectronicComponents.Add(newEC);
                    db.SaveChanges();
                    res = $"Элементат {newEC.Name} добавлен";
                }
                return(res);
            }
        }
Example #2
0
        //удалить эл компонент
        public static string DeleteElectronicComponent(ElectronicComponent electronicComponent)
        {
            var res = "такого элемента не сущетвует";

            using (ApplicationContext db = new ApplicationContext())
            {
                db.ElectronicComponents.Remove(electronicComponent);
                db.SaveChanges();
                res = $"Элемент {electronicComponent.Name} удален";
            }
            return(res);
        }
Example #3
0
        //реадктировать эл компонент
        public static string EditElectronicComponent(ElectronicComponent oldElectronicComponent,
                                                     string newName, string newType, string newPositionNumber, string newDatasheetLink)
        {
            var res = "такого элемента не сущетвует";

            using (ApplicationContext db = new ApplicationContext())
            {
                ElectronicComponent electronicComponent = db.ElectronicComponents.
                                                          FirstOrDefault(ec => ec.Id == oldElectronicComponent.Id);
                if (electronicComponent != null)
                {
                    electronicComponent.Name           = newName;
                    electronicComponent.Type           = newType;
                    electronicComponent.PositionNumber = newPositionNumber;
                    electronicComponent.DatasheetLink  = newDatasheetLink;

                    db.SaveChanges();
                    res = $"Элемент {oldElectronicComponent.Name} изменен";
                }
            }
            return(res);
        }