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); } }
//создат отдел == PowerSupply //public static List<PowerSupply> GetAllPowerSupply() //{ // return null; //} //создать позицию == Deadlines //ElectronicComponents //public static List<ElectronicComponent> GetAllElectronicComponent() //{ // return null; //} //созщдать сутрудника == PCB //public static List<PCB> GetAllPCB() //{ // return null; //} //удаление отдела == удаление TypeDevice //удаление позиции == Deadlines //сроки выполннения //удаление сотурдинка == PowerSupply #endregion #region CreateEntitys public static string CreateAllPowerSupply(string name, int power, int voltage, List <ElectronicComponent> electronicComponents, List <PCB> pCBs, string pathToSchema) { var res = "уже суещствет"; using (ApplicationContext db = new ApplicationContext()) { //сужествует ли блок питания var checkIsExit = db.PowerSupplies.Any(ps => ps.Name == name); if (!checkIsExit) { PowerSupply newPowerSupply = new PowerSupply { Name = name, Power = power, Voltage = voltage, //ElectronicComponents = electronicComponents, //PCBs = pCBs, PathToSchema = pathToSchema }; db.PowerSupplies.Add(newPowerSupply); db.SaveChanges(); res = $"БП {newPowerSupply.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); } }
//удалить блок питания public static string DeletePowerSupply(PowerSupply powerSupply) { var res = "такого БП не существует"; using (ApplicationContext db = new ApplicationContext()) { db.PowerSupplies.Remove(powerSupply); db.SaveChanges(); res = $"БП {powerSupply.Name} удален"; }; return(res); }
//редактровать блок питания public static string EditPowerSupply(PowerSupply oldPowerSupply, string newName, int NewVoltage, int newPower, string newPathToSchema) { var res = "такого БП не существует"; using (ApplicationContext db = new ApplicationContext()) { PowerSupply powerSupply = db.PowerSupplies.FirstOrDefault(ps => ps.Id == oldPowerSupply.Id); if (powerSupply != null) { powerSupply.Name = newName; powerSupply.Voltage = NewVoltage; powerSupply.Power = newPower; powerSupply.PathToSchema = newPathToSchema; db.SaveChanges(); res = $"БП {oldPowerSupply.Name} изменен"; } }; return(res); }