예제 #1
0
        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");
                }
            }
        }
예제 #2
0
        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");
                }
            }
        }
예제 #3
0
        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");
            }
        }
예제 #4
0
        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");
                }
            }
        }