public void Read(int companyId) { using (DataBase.Communication db = new DataBase.Communication(connectionString)) { foreach (DataBase.Employee employee in db.employees.Include(p => p.passport).ToList()) { if (employee.companyId == companyId) { Console.WriteLine($"{employee.id} - {employee.passport.type}"); } } } }
private int MadeId(DataBase.Communication db) { int id = 1; foreach (DataBase.Employee employee in db.employees.OrderBy(p => p.id).ToList()) { if (id == employee.id) { id++; } else { return(id); } } return(id); }
public int Add(String name, String surname, String phone, int companyId, String type, String number) { using (DataBase.Communication db = new DataBase.Communication(connectionString)) { int id = MadeId(db); db.employees.Add(new DataBase.Employee() { id = id, name = name, surname = surname, phone = phone, companyId = companyId, passport = new DataBase.Passport() { type = type, number = number } }); db.SaveChanges(); return(id); } }