public void AddUnit() { using (var dbContext = new BusinessCmpDbEntities()) { var unit = new Unit(); Console.WriteLine("Enter Unit Name: "); unit.UnitName = Console.ReadLine(); var check = dbContext.Units.SingleOrDefault(t => t.UnitName == unit.UnitName); if (check == null) { try { dbContext.Units.Add(unit); dbContext.SaveChanges(); Console.WriteLine("Unit added to the list"); } catch (Exception e) { Console.WriteLine(e); } } else { Console.WriteLine("Unit is already in the list"); } } }
public void AssignProjectManager() { using (var dbContext = new BusinessCmpDbEntities()) { Console.WriteLine("Select Id : "); var list = dbContext.EmplpoyeeDetails; foreach (var i in list) { Console.WriteLine("Id :" + i.EmployeeDetailId + "\tEmployee Id: " + i.EmployeeId + "\tProject Id: " + i.ProjectId); } var pm = new ProjectManager(); pm.EmployeeDetailId = Convert.ToInt32(Console.ReadLine()); var check = dbContext.ProjectManagers.SingleOrDefault(t => t.EmployeeDetailId == pm.EmployeeDetailId); if (check == null) { try { dbContext.ProjectManagers.Add(pm); dbContext.SaveChanges(); Console.WriteLine("Project manager is assigned to a project !!"); } catch (Exception e) { Console.WriteLine(e); } } else { Console.WriteLine("Manager is already assigned to project"); } } }
public void AssignProject() { var dbContext = new BusinessCmpDbEntities(); var emp = new EmplpoyeeDetail(); Console.WriteLine("Select Project Id : "); ProjectList(); emp.ProjectId = Convert.ToInt32(Console.ReadLine()); Console.WriteLine("Select Employee Id : "); EmployeeList(); emp.EmployeeId = Convert.ToInt32(Console.ReadLine()); var check = dbContext.EmplpoyeeDetails.SingleOrDefault(t => t.EmployeeId == emp.EmployeeId); var c = dbContext.EmplpoyeeDetails.SingleOrDefault(t => t.ProjectId == emp.ProjectId); if (check == null && c == null) { try { dbContext.EmplpoyeeDetails.Add(emp); dbContext.SaveChanges(); Console.WriteLine("Assigned a project to employee !!"); } catch (Exception e) { Console.WriteLine(e); } } else { Console.WriteLine("Project is already assigned to employee"); } }
public void AddEmployee() { using (var dbContext = new BusinessCmpDbEntities()) { var employee = new Employee(); Console.WriteLine("Enter Empployee Name: "); employee.Name = Console.ReadLine(); Console.WriteLine("Enter Empployee Address: "); employee.Address = Console.ReadLine(); Console.WriteLine("Enter Empployee Gender: "); employee.Gender = Console.ReadLine(); Console.WriteLine("Enter Empployee Contact no: "); employee.ContactNo = Convert.ToInt32(Console.ReadLine()); Console.WriteLine("Enter Unit Id in which Employee belongs : "); UnitList(); employee.UnitId = Convert.ToInt32(Console.ReadLine()); var check = dbContext.Employees.SingleOrDefault(t => t.Name == employee.Name); if (check == null) { try { dbContext.Employees.Add(employee); dbContext.SaveChanges(); Console.WriteLine("Employee added !!"); } catch (Exception e) { Console.WriteLine(e); } } else { Console.WriteLine("Employee is already in the list"); } } }