예제 #1
0
        static void Main(string[] args)
        {
            var db = new SoftuniContext();

            //_______________from db to class
            var config = new MapperConfiguration(cfg =>
            {
                cfg.AddProfile(new EmployeesToViewModelProfile());
            });
            IMapper mapper = config.CreateMapper();


            var employees = db.Employees.ProjectTo <EmployeeDepartment>(config).Take(10).ToList();

            // var employeeDep = mapper.Map<EmployeeDepartment>(employee);

            foreach (var e in employees)
            {
                Console.WriteLine($"{e.FirstName} in deparment {e.DepartmentName}");
            }


            //________________from class to db
            var inputModel = new EmployeeDepartment {
                DepartmentName = "New", FirstName = "Pesho"
            };
            var employee = mapper.Map <Employee>(inputModel);

            Console.WriteLine($"FirstName: {employee.FirstName}\nLastName: {employee.LastName}\nHireDate: {employee.HireDate}");
        }
예제 #2
0
        private void BtnLogin_Click(object sender, EventArgs e)
        {
            if (String.IsNullOrEmpty(tbxUsername.Text) || String.IsNullOrEmpty(tbxPassword.Text))
            {
                MessageBox.Show("Please, fill out all the required fields!");
            }
            else
            {
                string username = tbxUsername.Text;
                string password = tbxPassword.Text;
                bool   invalid  = true;

                foreach (Employee empl in employees)
                {
                    if (empl.personalInfo.Email == username && empl.personalInfo.Password == password)
                    {
                        EmployeeDepartment ed = empl.employmentInfo.EmployeeDepartment;

                        invalid = false;

                        this.Hide();
                        MediaBazaarForm form1 = new MediaBazaarForm(ed, empl);
                        form1.ShowDialog();
                        this.Close();
                    }
                }

                if (invalid)
                {
                    MessageBox.Show("Invalid data!");
                }
            }
        }
        public IActionResult EditEmployee(int id)
        {
            Employee           emp         = _context.Employees.Find(id);
            List <Department>  departments = _context.Departments.ToList();
            EmployeeDepartment ed;

            ed                 = new EmployeeDepartment();
            ed.EmployeeID      = emp.EmployeeID;
            ed.EmplName        = emp.Name;
            ed.EmplSurname     = emp.Surname;
            ed.EmailAddress    = emp.EmailAddress;
            ed.PhoneNumber     = emp.PhoneNumber;
            ed.DayOfBirthday   = emp.DayOfBirthday;
            ed.DepartmentID    = emp.DeptID;
            ed.departmentsEDVM = new List <Department>();
            if (emp.Department == null)
            {
                ed.DeptName = "";
            }
            else
            {
                ed.DeptName = emp.Department.Name;
                ed.departmentsEDVM.Add(emp.Department);
            }

            foreach (var item in departments)
            {
                if (item.DepartmentID != emp.DeptID)
                {
                    ed.departmentsEDVM.Add(item);
                }
            }

            return(View(ed));
        }
예제 #4
0
        //Constructor

        public EmployeeEmploymentInformation(EmployeeDepartment employeeDepartment, EmployeeContract contract)
        {
            this.EmployeeDepartment = employeeDepartment;
            contracts = new List <EmployeeContract>();
            this.contracts.Add(contract);
            AssignContractNum(contract);
        }
예제 #5
0
        public void TestCRUDEmployee()
        {
            string userNameExpected = "AnLe";
            string nameExpected     = "AnLe";
            string passWord         = "******";

            Employee           employee           = employeeBLL.CreateEmployee(nameExpected, userNameExpected, passWord);
            EmployeeDepartment employeeDepartment = new EmployeeDepartment();
            List <Department>  departments        = departmentBLL.ListDepartment();

            employeeDepartment.DepartmentID = departments[0].ID;
            employeeDepartment.EmployeeID   = employee.ID;
            emloyeeDepartmentBLL.CreateEmployeeDepartment(employeeDepartment);

            bool            isCreated = false;
            List <Employee> employees = employeeBLL.ListEmployeeByDepartment(departments[0]);

            for (int i = 0; i < employees.Count; i++)
            {
                if (employees[i].Name == nameExpected && employees[i].Username == userNameExpected)
                {
                    isCreated = true;
                }
            }
            Assert.AreEqual(true, isCreated);
            TestUpdateInformationEmployee(employee, employeeDepartment);
        }
예제 #6
0
        public void TestInputEmptyEmployee()
        {
            try
            {
                string userNameExpected = "";
                string nameExpected     = "";
                string passWord         = "";

                Employee           employee           = employeeBLL.CreateEmployee(nameExpected, userNameExpected, passWord);
                EmployeeDepartment employeeDepartment = new EmployeeDepartment();
                List <Department>  departments        = departmentBLL.ListDepartment();

                bool            isCreated = false;
                List <Employee> employees = employeeBLL.ListEmployeeByDepartment(departments[0]);
                for (int i = 0; i < employees.Count; i++)
                {
                    if (employees[i].Name == nameExpected && employees[i].Username == userNameExpected)
                    {
                        isCreated = true;
                    }
                }
                Assert.AreEqual(false, isCreated);
            }
            catch (Exception e)
            {
                Assert.AreNotEqual("", e.ToString());
            }
        }
        public IActionResult AddEmployee(EmployeeDepartment employeeDep)
        {
            List <Department> departments = _context.Departments.ToList();

            employeeDep.departmentsEDVM = new List <Department>();
            foreach (var item in departments)
            {
                employeeDep.departmentsEDVM.Add(item);
            }

            if (ModelState.IsValid)
            {
                Employee employee = new Employee();
                employee.DeptID        = employeeDep.DepartmentID;
                employee.EmployeeID    = employeeDep.EmployeeID;
                employee.Name          = employeeDep.EmplName;
                employee.Surname       = employeeDep.EmplSurname;
                employee.DayOfBirthday = employeeDep.DayOfBirthday;
                employee.EmailAddress  = employeeDep.EmailAddress;
                employee.PhoneNumber   = employeeDep.PhoneNumber;
                _context.Add(employee);
                _context.SaveChanges();
                return(RedirectToAction("Main"));
            }
            return(View(employeeDep));
        }
        public IActionResult Main()
        {
            var employees = _context.Employees.Include(e => e.Department);
            List <EmployeeDepartment> employeeDepartmentsLists = new List <EmployeeDepartment>();
            EmployeeDepartment        ed;

            foreach (var item in employees)
            {
                ed              = new EmployeeDepartment();
                ed.EmployeeID   = item.EmployeeID;
                ed.EmplName     = item.Name;
                ed.EmplSurname  = item.Surname;
                ed.EmailAddress = item.EmailAddress;
                ed.PhoneNumber  = item.PhoneNumber;
                if (item.Department == null)
                {
                    ed.DeptName = "";
                }
                else
                {
                    ed.DeptName = item.Department.Name;
                }


                employeeDepartmentsLists.Add(ed);
            }

            return(View(employeeDepartmentsLists));
        }
        public async Task <IActionResult> Edit(int id, [Bind("Id")] EmployeeDepartment employeeDepartment)
        {
            if (id != employeeDepartment.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(employeeDepartment);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!EmployeeDepartmentExists(employeeDepartment.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(employeeDepartment));
        }
예제 #10
0
 public Shift(EmployeeDepartment employeeDepartment, DateTime datetime, ShiftType shiftType, int shiftnum) // this is for reading shifts from the DB
 {
     EmployeeDepartment = employeeDepartment;
     this.DateTime      = datetime;
     ShiftType          = shiftType;
     ShiftNumber        = shiftnum;
 }
예제 #11
0
        // GET: employeeController
        //public ActionResult Index()
        //{
        public ActionResult GetEmployeeDepartment()
        {
            EmployeeDepartment ed = new EmployeeDepartment();

            ed.employee   = GetEmployee();
            ed.department = GetDepartment();
            return(View(ed));
        }
예제 #12
0
        public ActionResult DeleteConfirmed(int id)
        {
            EmployeeDepartment employeeDepartment = db.EmployeeDepartments.Find(id);

            db.EmployeeDepartments.Remove(employeeDepartment);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
예제 #13
0
        //Constructor


        public Shift(EmployeeDepartment employeeDepartment, Employee employee, DateTime datetime, ShiftType shiftType) // this is for getting day as an input string (one week)
        {
            EmployeeDepartment = employeeDepartment;
            this.DateTime      = datetime;
            ShiftType          = shiftType;
            employees          = new List <Employee>();
            employees.Add(employee);
        }
        public void DeleteEmployeeDepartment(EmployeeDepartment employeeDepartment)
        {
            if (employeeDepartment == null)
            {
                throw new ArgumentNullException(nameof(employeeDepartment));
            }

            _context.EmployeeDepartments.Remove(employeeDepartment);
        }
        public async Task AddEmployeeDepartment(EmployeeDepartment employeeDepartment)
        {
            if (employeeDepartment == null)
            {
                throw new ArgumentNullException(nameof(employeeDepartment));
            }

            await _context.EmployeeDepartments.AddAsync(employeeDepartment);
        }
        // GET: Employee

        public ActionResult GetData()
        {
            //Employee Model Information

            List <EmployeeModel> db = new List <EmployeeModel>();

            EmployeeModel obj = new EmployeeModel();

            obj.EmpId     = 1;
            obj.EmpName   = "Chaterjee";
            obj.EmpSalary = 25000;

            EmployeeModel obj1 = new EmployeeModel();

            obj1.EmpId     = 2;
            obj1.EmpName   = "Sneha";
            obj1.EmpSalary = 35000;


            EmployeeModel obj2 = new EmployeeModel();

            obj2.EmpId     = 3;
            obj2.EmpName   = "Firoz";
            obj2.EmpSalary = 45000;

            db.Add(obj);
            db.Add(obj1);
            db.Add(obj2);

            //Department Information


            List <DepartmentModel> deptdb = new List <DepartmentModel>();

            DepartmentModel deptobj = new DepartmentModel();

            deptobj.DeptId   = 1;
            deptobj.DeptName = "IT";

            DepartmentModel deptobj1 = new DepartmentModel();

            deptobj1.DeptId   = 2;
            deptobj1.DeptName = "NetWork";

            deptdb.Add(deptobj);
            deptdb.Add(deptobj1);



            EmployeeDepartment empdept = new EmployeeDepartment();

            empdept.EmployeeModels   = db;     //Employees
            empdept.DepartmentModels = deptdb; //Departments

            return(View(empdept));
        }
        public async Task <IActionResult> Create([Bind("Id")] EmployeeDepartment employeeDepartment)
        {
            if (ModelState.IsValid)
            {
                _context.Add(employeeDepartment);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(employeeDepartment));
        }
예제 #18
0
        private void CbxSchedDepartment_SelectedIndexChanged_1(object sender, EventArgs e)
        {
            EmployeeDepartment ed        = (EmployeeDepartment)Enum.Parse(typeof(EmployeeDepartment), cbxSchedDepartment.SelectedValue.ToString());
            List <Employee>    employees = sm.GetEmployeesFromDep(ed);

            cbxSchedEmployee.Items.Clear();
            foreach (Employee em in employees)
            {
                cbxSchedEmployee.Items.Add(em);
            }
        }
예제 #19
0
 public ActionResult Edit([Bind(Include = "EmployeeDepartmentID,DepartmentID,EmployeeID")] EmployeeDepartment employeeDepartment)
 {
     if (ModelState.IsValid)
     {
         db.Entry(employeeDepartment).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.DepartmentID = new SelectList(db.Departments, "DepartmentID", "DepartmentName", employeeDepartment.DepartmentID);
     ViewBag.EmployeeID   = new SelectList(db.Employees, "EmployeeID", "EmployeeName", employeeDepartment.EmployeeID);
     return(View(employeeDepartment));
 }
예제 #20
0
        public Employee[] SearchEmployeeByDepartment(EmployeeDepartment dep)
        {
            List <Employee> found = new List <Employee>();

            foreach (Employee e in employees)
            {
                if (e.employmentInfo.EmployeeDepartment == dep)
                {
                    found.Add(e);
                }
            }
            return(found.ToArray());
        }
 public void Save(EmployeeDepartment employeeDepartment)
 {
     try
     {
         using (var em = EntityManagerFactory.CreateInstance(ds))
         {
             Save(em, null, employeeDepartment);
         }
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
예제 #22
0
        // GET: EmployeeDepartments/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            EmployeeDepartment employeeDepartment = db.EmployeeDepartments.Find(id);

            if (employeeDepartment == null)
            {
                return(HttpNotFound());
            }
            return(View(employeeDepartment));
        }
        public ViewResult AddEmployee()
        {
            List <Department> departments = _context.Departments.ToList();

            EmployeeDepartment ed = new EmployeeDepartment();

            ed.departmentsEDVM = new List <Department>();
            foreach (var item in departments)
            {
                ed.departmentsEDVM.Add(item);
            }
            ed.DayOfBirthday = DateTime.Now;
            return(View(ed));
        }
예제 #24
0
        //show emplpoyee Departments:
        public static void showEmployeeDepartments()
        {
            EmployeeDepartment empDep = new EmployeeDepartment();

            empDep.numofClasses  = 150;
            empDep.numOfTeachers = 15;
            empDep.deptName      = "Science";

            empDep.printDeptInfo();
            //create an instant result:
            EmployeeDepartment scienceDept   = new EmployeeDepartment(empDep.deptName, empDep.numofClasses, empDep.numOfTeachers);
            EmployeeDepartment mathDept      = new EmployeeDepartment("Math", 15, 3);
            EmployeeDepartment chemistryDept = new EmployeeDepartment("Chemistry", 105, 32);
            EmployeeDepartment CsciDept      = new EmployeeDepartment(864, 48, "Computer Science");
        }
예제 #25
0
        // GET: EmployeeDepartments/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            EmployeeDepartment employeeDepartment = db.EmployeeDepartments.Find(id);

            if (employeeDepartment == null)
            {
                return(HttpNotFound());
            }
            ViewBag.DepartmentID = new SelectList(db.Departments, "DepartmentID", "DepartmentName", employeeDepartment.DepartmentID);
            ViewBag.EmployeeID   = new SelectList(db.Employees, "EmployeeID", "EmployeeName", employeeDepartment.EmployeeID);
            return(View(employeeDepartment));
        }
예제 #26
0
        public void TestDeleteEmployee(Employee employee, EmployeeDepartment employeeDepartment)
        {
            employeeBLL.Delete(employee);
            bool isDeleted = true;
            List <Department> departments = departmentBLL.ListDepartment();
            List <Employee>   employees   = employeeBLL.ListEmployeeByDepartment(departments[0]);

            for (int i = 0; i < employees.Count; i++)
            {
                if (employees[i].Name == employee.Name && employees[i].Username == employee.Username)
                {
                    isDeleted = false;
                }
            }
            Assert.AreEqual(true, isDeleted);
        }
        public IActionResult EditEmployee(int id, EmployeeDepartment employeeDep)
        {
            List <Department> departments = _context.Departments.ToList();

            Employee employee = new Employee();

            employee.EmployeeID         = employeeDep.EmployeeID;
            employee.Name               = employeeDep.EmplName;
            employee.Surname            = employeeDep.EmplSurname;
            employee.DayOfBirthday      = employeeDep.DayOfBirthday;
            employee.EmailAddress       = employeeDep.EmailAddress;
            employee.PhoneNumber        = employeeDep.PhoneNumber;
            employee.DeptID             = employeeDep.DepartmentID;
            employeeDep.departmentsEDVM = new List <Department>();

            foreach (var item in departments)
            {
                employeeDep.departmentsEDVM.Add(item);
            }

            if (id != employeeDep.EmployeeID)
            {
                return(Content("ID jest nie prawidłowe."));
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Employees.Update(employee);
                    _context.SaveChanges();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!EmployeeExist(id))
                    {
                        return(Content("Pracownik nie istnieje"));
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Main)));
            }
            return(View(employeeDep));
        }
        public EmployeeDepartment GetCurrentDepartment(Guid employeeId)
        {
            EmployeeDepartment employeeDepartment = null;

            using (var em = EntityManagerFactory.CreateInstance(ds))
            {
                string sql = "SELECT  TOP 1 ed.*,b.BranchName,d.DepartmentName FROM (EmployeeDepartment ed "
                             + "INNER JOIN Branch b ON ed.BranchId = b.ID) INNER JOIN Department d "
                             + "ON ed.DepartmentId = d.ID "
                             + "WHERE ed.EmployeeId='{" + employeeId + "}' "
                             + "ORDER BY ed.EffectiveDate DESC";

                employeeDepartment = em.ExecuteObject <EmployeeDepartment>(sql, new EmployeeDepartmentMapper());
            }

            return(employeeDepartment);
        }
        public EmployeeDepartment GetPreviousDepartment(Guid employeeId, int month, int year)
        {
            EmployeeDepartment employeeDepartment = new EmployeeDepartment();

            using (var em = EntityManagerFactory.CreateInstance(ds))
            {
                string sql = "SELECT  TOP 1 ed.*,b.BranchName,d.DepartmentName FROM (EmployeeDepartment ed "
                             + "INNER JOIN Branch b ON ed.BranchId = b.ID) INNER JOIN Department d "
                             + "ON ed.DepartmentId = d.ID "
                             + "WHERE ed.EmployeeId='{" + employeeId + "}' "
                             + "AND month(ed.EffectiveDate) <=" + month + " "
                             + "AND year(ed.EffectiveDate) <=" + year;

                employeeDepartment = em.ExecuteObject <EmployeeDepartment>(sql, new EmployeeDepartmentMapper());
            }

            return(employeeDepartment);
        }
        public void Save(IEntityManager em, Transaction tx, EmployeeDepartment employeeDepartment)
        {
            string[] columns = { "ID", "EmployeeId", "EffectiveDate", "BranchId", "DepartmentId" };

            object[] values = { Guid.NewGuid(),              employeeDepartment.EmployeeId, employeeDepartment.EffectiveDate.ToShortDateString(),
                                employeeDepartment.BranchId, employeeDepartment.DepartmentId };

            var q = new Query().Select(columns).From(tableName).Insert(values);

            if (tx == null)
            {
                em.ExecuteNonQuery(q.ToSql());
            }
            else
            {
                em.ExecuteNonQuery(q.ToSql(), tx);
            }
        }