/// <summary>
        /// Method to REMOVE Department
        /// </summary>
        /// <param name="department">Department to Remove</param>
        public void RemoveDepartment(Department department)
        {
            Department parent = DepartmentsDb.Find(x => x.DepartmentName == department.ParentDepartment);

            if (parent != null)
            {
                parent.innerDepartments.Remove(department);
            }
            else
            {
                company.Clear();
            }

            if (department.DepartmentName != DepartmentsDb.Find(x => x is Company).DepartmentName)
            {
                RemoveChildren(department);
                DepartmentsDb.Remove(department);
            }
            else
            {
                DepartmentsDb.Clear();
            }

            EmployeesDB = EmployeesDB.Where(x => x.Department != department.DepartmentName).ToList();
        }
Exemplo n.º 2
0
        static async Task Main(string[] args)
        {
            const string connection_str = @"Data Source=(localdb)\MSSQLLocalDB;Initial Catalog=Employees.DB;Integrated Security=True";

            //var service_collection = new ServiceCollection();
            //service_collection.AddDbContext<EmployeesDB>(o => o.UseSqlServer(connection_str));
            //var service = service_collection.BuildServiceProvider();

            using (var db = new EmployeesDB(new DbContextOptionsBuilder <EmployeesDB>().UseSqlServer(connection_str).Options))
            {
                await db.Database.EnsureCreatedAsync();

                var k = 0;
                if (await db.Employees.CountAsync() == 0)
                {
                    EmployeesFromFile.MyThread thread = new EmployeesFromFile.MyThread();
                    thread.Thrd.Join();
                    for (var i = 0; i < EmployeesFromFile.GetEmployees.Count; i++)
                    {
                        await db.Employees.AddAsync(EmployeesFromFile.GetEmployees[i]);
                    }
                    await db.SaveChangesAsync();
                }
            }
            Console.WriteLine("Основной поток закончил работу");
            Console.ReadLine();
        }
Exemplo n.º 3
0
        protected override void Seed(EmployeesDB context)
        {
            //  This method will be called after migrating to the latest version.

            //  You can use the DbSet<T>.AddOrUpdate() helper extension method
            //  to avoid creating duplicate seed data.
        }
        /// <summary>
        /// SET Employee Values for Properties
        /// </summary>
        /// <param name="node">XML node to get Values</param>
        /// <param name="dept">Department to add Values</param>
        void DefineEmployeeClass(XmlNode node, Employee emply)
        {
            emply.EmployeeName = Convert.ToString(node.Attributes.GetNamedItem("employeeName").Value);
            emply.LastName     = Convert.ToString(node.Attributes.GetNamedItem("lastName").Value);
            emply.Age          = Convert.ToInt32(node.Attributes.GetNamedItem("age").Value);
            emply.Department   = Convert.ToString(node.Attributes.GetNamedItem("department").Value);
            emply.DaysWorked   = Convert.ToInt32(node.Attributes.GetNamedItem("daysWorked").Value);
            emply.Repository   = this;

            EmployeesDB.Add(emply);
        }
        public DepartmentsManager()
        {
            using (var db = new EmployeesDB())
            {
                DepartmentsArray = db.Departments.ToArray();
            }

            using (var db = new EmployeesDB())
            {
                for (var department_n = 1; department_n <= DepartmentsArray.Length; department_n++)
                {
                    DepartmentsArray[department_n - 1].Employees = db.Employees
                                                                   .Where(employee => employee.Department.Id == department_n).ToList <EmployeeEntity>();
                }
            }
        }
Exemplo n.º 6
0
 public ActionResult Account(EmployeeData ED, HttpPostedFileBase ProfileImage)
 {
     try
     {
         if (ModelState.IsValid)
         {
             int NameID = 1;
             //created the Database Object
             sdirecttestdbEntities dbEntities = new sdirecttestdbEntities();
             //created the table object
             EmployeesDB edb = new EmployeesDB();
             edb.FullName    = ED.FullName;
             edb.Email       = ED.Email;
             edb.DateOfBirth = ED.DateOfBirth;
             edb.Address     = ED.Address;
             if (ProfileImage != null && ProfileImage.ContentLength > 0)
             {
                 //get the path where we want to store our image
                 string path = Path.Combine(Server.MapPath("~/uploads"), Path.GetFileName(ProfileImage.FileName));
                 //move the image to upload folder
                 ProfileImage.SaveAs(path);
                 ViewBag.message = "file uploaded";
             }
             edb.ImageActualName = Path.GetFileName(ProfileImage.FileName);
             string ptr = Convert.ToString(NameID + "1_");
             edb.ImageName = string.Concat(ptr, ED.ImageName);
             edb.CountryId = ED.CountryId;
             edb.StateId   = ED.StateId;
             //store the data into table
             dbEntities.EmployeesDBs.Add(edb);
             //update the table with new data
             dbEntities.SaveChanges();
             int ID = edb.UserId;
             NameID = NameID + 1;
         }
         ViewBag.CountryList = new SelectList(GetCountryList(), "ID", "CountryName");
         ModelState.Clear();
         return(View());
     }
     catch (Exception)
     {
         throw new Exception("Filed is not valid");
     }
 }
        /// <summary>
        /// Method to ADD new Employee
        /// </summary>
        /// <param name="Name">New Employee Name</param>
        /// <param name="LastName">New Employee Last Name</param>
        /// <param name="Age">New Employee Age</param>
        /// <param name="Department">New Employee Department</param>
        public void AddEmployee(string Name, string LastName, int Age, string Department, int employeeClass)
        {
            Employee employee;

            switch (employeeClass)
            {
            case 0: employee = new Intern(Name, LastName, Age, Department, 0); break;

            case 1: employee = new Worker(Name, LastName, Age, Department, 0); break;

            case 2: employee = new HeadOfDepartment(Name, LastName, Age, Department, 0); break;

            case 3: employee = new HeadOfOrganization(Name, LastName, Age, Department, 0); break;

            default: employee = new Employee(Name, LastName, Age, Department, 0); break;
            }

            EmployeesDB.Add(employee);
        }
        public MainWindow()
        {
            InitializeComponent();
            using (var db = new EmployeesDB())
            {
                var employees_count = db.Employees.Count();
                Title = $"Сотрудников в базе {employees_count}";
            }

            using (var db = new EmployeesDB())
                if (!db.Departments.Any())
                {
                    int epmloyee_n = 1;
                    for (int department_n = 1; department_n <= 5; department_n++)
                    {
                        var department = new DepartmentEntity
                        {
                            Name = $"Department {department_n}"
                        };

                        for (int i = 0; i < 5; i++)
                        {
                            var employee = new EmployeeEntity
                            {
                                Name    = $"Сотрудник {epmloyee_n}",
                                Surname = $"Сотрудник {epmloyee_n}"
                            };

                            department.Employees.Add(employee);
                            epmloyee_n++;
                        }

                        db.Departments.Add(department);
                    }

                    db.SaveChanges();
                }
        }
Exemplo n.º 9
0
 public EmployeesStoreInDB(EmployeesDB empl)
 {
     _empl = empl;
 }
 /// <summary>
 /// Method to REMOVE Employee
 /// </summary>
 /// <param name="employee">Employee to Remove</param>
 public void RemoveEmployee(Employee employee)
 {
     EmployeesDB.Remove(employee);
     mainWindow.LoadEmployeesToListView();
 }