public static string CreateAllPCB(string name, string type, PowerSupply namePowerSupply, List <ElectronicComponent> electronicComponents, string pathToSchema) { var res = "уже существует"; using (ApplicationContext db = new ApplicationContext()) { //сужествует ли плата var checkIsExist = db.PCBs.Any(pcb => pcb.Name == name); if (!checkIsExist) { PCB newPcb = new PCB { Name = name, Type = type, NamePowerSupplyId = namePowerSupply.Id, //NamePowerSupply = namePowerSupply, //ElectronicComponents = electronicComponents, PathToSchema = pathToSchema }; db.PCBs.Add(newPcb); db.SaveChanges(); res = $"Плата {newPcb.Name} добавлена"; } return(res); } }
//удалить плату public static string DeletePCB(PCB PCB) { var res = "такой платы не сущетвует"; using (ApplicationContext db = new ApplicationContext()) { db.PCBs.Remove(PCB); db.SaveChanges(); res = $"Плата {PCB.Name} удалена"; } return(res); }
//редакторивать плату public static string EditPCB(PCB oldPCB, string newName, string newType, string newPathToSchema) { var res = "такой платы не сущетвует"; using (ApplicationContext db = new ApplicationContext()) { PCB PCB = db.PCBs.FirstOrDefault(pcb => pcb.Id == oldPCB.Id); if (PCB != null) { PCB.Name = newName; PCB.Type = newType; PCB.PathToSchema = newPathToSchema; db.SaveChanges(); res = $"Плата {oldPCB.Name} изменена"; } } return(res); }
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); } }