public ActionResult Create([Bind(Include = "Id,Name,JobDescription,Number,Department,HourlyPay,Bonus,EmployeeTypeID")] Employee employee)
        {
            if (ModelState.IsValid)
            {
                /*
                 *  THIS IS AN EXAMPLE OF TIGHT COUPLING
                 *
                 *  if (employee.EmployeeTypeID == 1)
                 *  {
                 *      employee.HourlyPay = 8;
                 *      employee.Bonus = 10;
                 *  }
                 *  else if (employee.EmployeeTypeID == 2)
                 *  {
                 *      employee.HourlyPay = 12;
                 *      employee.Bonus = 5;
                 *  }
                 */

                EmployeeManagerFactory empFactory = new EmployeeManagerFactory();
                IEmployeeManager       empManager = empFactory.GetEmployeeManager(employee.EmployeeTypeID);
                employee.Bonus     = empManager.GetBonus();
                employee.HourlyPay = empManager.GetPay();

                db.Employees.Add(employee);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.EmployeeTypeID = new SelectList(db.Employee_Type, "Id", "EmployeeType", employee.EmployeeTypeID);
            return(View(employee));
        }
Example #2
0
        static void Main(string[] args)
        {
            DemoEntities context = new DemoEntities();
            Employee     e       = new Employee();

            Console.Write("Enter Employee Name : ");
            e.EmployeeName = Console.ReadLine();

            Console.Write("Enter Department : ");
            e.Department = Console.ReadLine();

            Console.Write("Employement Type\n1. Permanent\n2. Contract\nEnter Employment Type : ");
            e.EmployeeTypeId = Convert.ToInt32(Console.ReadLine());

            EmployeeManagerFactory factory = new EmployeeManagerFactory();
            IEmployeeManager       manager = factory.GetEmployeeManager(e.EmployeeTypeId.Value);

            e.HourlyPay = manager.GetHourlyPay();
            e.BonusRate = manager.GetBonusRate();

            context.Employees.Add(e);
            context.SaveChanges();

            foreach (var emp in context.Employees)
            {
                Console.WriteLine("{0}, {1}, {2}, {3}, {4}, {5}, {6}", emp.EmployeeId, emp.EmployeeName, emp.Department, emp.EmployeeTypeId, emp.EmployeeType.EmployeeType1, emp.HourlyPay, emp.BonusRate);
            }
        }
        public IActionResult Edit(int id, Employee employee)
        {
            var factory         = new EmployeeManagerFactory();
            var employeeManager = factory.GetEmployeeManager(employee.EmployeeType);

            employee.Bonus     = employeeManager.GetBonus();
            employee.HourlyPay = employeeManager.GetPay();

            _employee.UpdateEmployee(employee);

            return(RedirectToAction("Index"));
        }
        public IActionResult Create(Employee employee)
        {
            var factory         = new EmployeeManagerFactory();
            var employeeManager = factory.GetEmployeeManager(employee.EmployeeType);

            employee.Bonus     = employeeManager.GetBonus();
            employee.HourlyPay = employeeManager.GetPay();

            var savedEmployee = _employee.AddEmployee(employee);

            return(RedirectToAction("Index"));
        }
Example #5
0
        static void Main(string[] args)
        {
            Console.WriteLine("-----------Employee Management System!!!---------------");
            Console.Write("Please enter employee type to get 'Bonus' & 'Pay' info!-> ");
            int employeeType = Convert.ToInt32(Console.ReadLine());
            EmployeeManagerFactory empFactory      = new EmployeeManagerFactory();
            IEmployeeManager       employeeManager = empFactory.GetEmployeeManager(employeeType);
            var bonus = employeeManager.GetBonus();
            var pay   = employeeManager.GetPay();

            Console.WriteLine("Get Bonus : " + bonus);
            Console.WriteLine("Get Pay : " + pay);
            Console.Write("Press any key to exit!!!");
            Console.ReadLine();
        }
        public ActionResult Create([Bind(Include = "Id,Name,JobDescription,Number,Department,HourlyPay,Bonus,EmployeeType")] Employee employee)
        {
            if (ModelState.IsValid)
            {
                EmployeeManagerFactory empFactory = new EmployeeManagerFactory();
                IEmployeeManager       empManager = empFactory.GetEmployeeManager(employee.EmployeeType.Value);
                employee.Bonus     = empManager.GetBonus();
                employee.HourlyPay = empManager.GetPay();
                db.Employees.Add(employee);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.EmployeeType = new SelectList(db.Employee_Type, "Id", "EmployeeType", employee.EmployeeType);
            return(View(employee));
        }
        public async Task <IActionResult> New(Employee employee)
        {
            if (ModelState.IsValid)
            {
                EmployeeManagerFactory employeeManagerFactory = new EmployeeManagerFactory();
                IEmployeeManager       manager = employeeManagerFactory.GetEmployeeManager(employee.EmployeeTypeId);
                employee.Bonus     = manager.GetBonus();
                employee.HourlyPay = manager.GetPay();
                db.Add(employee);
                await db.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["DepartmentId"]   = new SelectList(db.Departments, "Id", "DepartmentName", employee.DepartmentId);
            ViewData["EmployeeTypeId"] = new SelectList(db.EmployeeTypes, "Id", "EmployeeTypeName", employee.EmployeeTypeId);
            return(View(employee));
        }
Example #8
0
        static void Main(string[] args)
        {
            #region Singleton For Single Thread

            /*
             * SingletonDP objSingletonDP1 = SingletonDP.GetInstance;
             * objSingletonDP1.SumTwoNumbers(1, 2);
             *
             *
             * SingletonDP objSingletonDP2 = SingletonDP.GetInstance;
             * objSingletonDP2.SumTwoNumbers(3, 4);
             *
             */
            #endregion

            #region Singleton For Multithread

            /*
             * Parallel.Invoke(
             *  () => FirstCalculation(),
             *  () => SecondCalculation()
             *  );
             */
            #endregion

            #region Factory Pattern


            #region Example_1

            /*
             * SalaryProcessingFactory2 factory = new SalaryProcessingFactory2();
             * ISalaryProcessing salaryProcessing = factory.RunSalaryProcessing(EmployeeType.FULLTIME);
             * decimal fullTimeSalary = salaryProcessing.GetSalary();
             *
             * salaryProcessing = factory.RunSalaryProcessing(EmployeeType.CONTRACT);
             * decimal contractSalary = salaryProcessing.GetSalary();
             *
             * salaryProcessing = factory.RunSalaryProcessing(EmployeeType.TEMPORARY);
             * decimal tempSalary = salaryProcessing.GetSalary();
             *
             * Console.WriteLine("Full Time Employee's Salary : " + fullTimeSalary.ToString());
             * Console.WriteLine("------------------------------------------------------------");
             * Console.WriteLine("Contract Employee's Salary : " + contractSalary.ToString());
             * Console.WriteLine("------------------------------------------------------------");
             * Console.WriteLine("Temporary Employee's Salary : " + tempSalary.ToString());
             */
            #endregion

            #region Example_2

            EmployeeManagerFactory factory    = new EmployeeManagerFactory();
            IEmployeeManager       empManager = factory.GetEmployeeManager(EmployeeType.CONTRACT);
            decimal _bonus        = empManager.GetBonus();
            decimal _pay          = empManager.GetPay();
            string  _employeeType = empManager.GetEmployeeType().ToString();

            Console.WriteLine(_employeeType + " EMPLOYEE PAY : " + _pay.ToString() + "\n");
            Console.WriteLine(_employeeType + " EMPLOYEE BONUS : " + _bonus.ToString() + "\n");

            #endregion
            #endregion

            Console.ReadLine();
        }