//Delete Factory public async Task <bool> DeleteFactoryAsync(int id) { bool Result = false; var factory = _context.Factory.Single(f => f.Id == id); if (factory != null) { PrimarySourceSerivce ps = new PrimarySourceSerivce(_context); await ps.DeleteAllPrimaryAsync(id); SecoundrySourceService ss = new SecoundrySourceService(_context); await ss.DeleteAllSecondaryAsync(id); _context.Factory.Remove(factory); await _context.SaveChangesAsync(); Result = true; return(Result); } return(Result); }
// not used any more //public List<PrimarySource> GetValidPrimarySource(string type, int factoryid) //type of distination //{ // List<PhasesConnection> li = _context.PhasesConnection.ToList(); // List<PhasesConnection> valid = new List<PhasesConnection>(); // foreach (PhasesConnection pc in li) // { // if (type == "1" && pc.SourceId % 2 != 0) // { // if (pc.dN1 == -1 || pc.dN2 == -1 || pc.dN3 == -1) valid.Add(pc); // } // else if (type == "3" && pc.SourceId % 2 != 0 && pc.SourceType == "3") // { // if (pc.dN1 == -1 && pc.dN2 == -1 && pc.dN3 == -1) valid.Add(pc); // } // } // List<PrimarySource> validd = new List<PrimarySource>(); // PrimarySourceSerivce ps = new PrimarySourceSerivce(_context); // foreach (var primary in valid) // { // var par = ps.GetPrimarySourceFromDB(primary.SourceId); // if (par.FactoryId == factoryid) // { // validd.Add(par); // } // } // return validd; //} public List <secondarySource> GetValidsecondrySource(string type, int factoryid) //type of distination { List <PhasesConnection> li = _context.PhasesConnection.ToList(); List <PhasesConnection> valid = new List <PhasesConnection>(); foreach (PhasesConnection pc in li) { if (type == "1" && pc.SourceId % 2 == 0) { if (pc.dN1 == -1 || pc.dN2 == -1 || pc.dN3 == -1) { valid.Add(pc); } } else if (type == "3" && pc.SourceId % 2 == 0 && pc.SourceType == "3") { if (pc.dN1 == -1 && pc.dN2 == -1 && pc.dN3 == -1) { valid.Add(pc); } } } List <secondarySource> validd = new List <secondarySource>(); SecoundrySourceService ps = new SecoundrySourceService(_context); foreach (var secondary in valid) { var par = ps.GetSecoundrySourceFromDBByCode(secondary.SourceId); if (par.Fac_Id == factoryid) { validd.Add(par); } } return(validd); }