public ActionResult Create([Bind(Include = "Id,Name,JobDescription,Number,Department,HourlyPay,Bonus,EmployeeTypeID")] Employee.Web.Models.Employee employee)
        {
            if (ModelState.IsValid)
            {
                //calcaulate bonus
                // businees logic inside controller -- bad practice
                //if (employee.EmployeeTypeID ==1) // permanent
                //{
                //    employee.HourlyPay = 8;
                //    employee.Bonus = 10;
                //}
                //else if (employee.EmployeeTypeID == 2)
                //{
                //    employee.HourlyPay = 12;
                //    employee.Bonus = 5;
                //}
                BaseEmployeeFactory empFactory = new EmployeeManagerFactory().CreateFactory(employee);
                //IEmployeeManager empManager = empFactory.GetEmployeeManager(employee.EmployeeTypeID);
                //employee.Bonus = empManager.GetBonus();
                //employee.HourlyPay = empManager.GetHourlyPay();

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

            ViewBag.EmployeeTypeID = new SelectList(db.EmployeeTypes, "Id", "EmployeeType1", employee.EmployeeTypeID);
            return(View(employee));
        }
        public ActionResult Create([Bind(Include = "Id,Name,JobDesc,Number,Department,HourlyPay,Bonus,EmployeeTypeId")] Employee employee)
        {
            if (ModelState.IsValid)
            {
                //EmployeeManagerFactory empFactory = new EmployeeManagerFactory();
                //IEmployeeManager empManager = empFactory.GetEmployeeManager(employee.EmployeeTypeId);
                //if (empManager != null)
                //{
                //    employee.Bonus = empManager.GetBonus();
                //    employee.HourlyPay = empManager.GetHourlyPay();
                //}

                BaseEmployeeFactory employeeFactory = new EmployeeManagerFactory().CreateFactory(employee);
                employeeFactory.ApplySalary();

                IComputerFactory      computerFactory = new EmployeeSystemFactory().Create(employee);
                EmployeeSystemManager manager         = new EmployeeSystemManager(computerFactory);
                employee.ComputerDetails = manager.GetSystemDetails();

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

            ViewBag.EmployeeTypeId = new SelectList(db.EmployeeTypes, "Id", "Types", employee.EmployeeTypeId);
            return(View(employee));
        }
Esempio n. 3
0
        static void Main(string[] args)
        {
            Employee employee = GetData();

            BaseEmployeeFactory employeeFactory = new EmployeeManagerFactory().CreateFactory(employee);

            employeeFactory.ApplySalary();


            //EmployeeManagerFactory employeeManagerFactory = new EmployeeManagerFactory();
            //IEmployeeManager employeeManager = employeeManagerFactory.GetEmployeeManager(employee.Type);
            //employee.Bounus = employeeManager.GetBonus();
            //employee.Pay = employeeManager.GetPay();

            //if(employee.Type == 1)
            //{
            //    employee.Pay = 500;
            //    employee.Bounus = 250;
            //}
            //else if (employee.Type == 2)
            //{
            //    employee.Pay = 300;
            //    employee.Bounus = 100;
            //}

            PrintEmployee(employee);
        }
        public ActionResult Create([Bind(Include = "Id,Name,JobDescription,Number,Department,HourlyPay,Bonus,EmployeeTypeId")] Employee employee)
        {
            if (ModelState.IsValid)
            {
                #region SimpleFactory
                //EmployeeManagerFactory empFactory = new EmployeeManagerFactory();
                //IEmployeeManager empManager = empFactory.GetEmployeeManager(employee.EmployeeTypeId);
                //employee.HourlyPay = empManager.GetPay();
                //employee.Bonus = empManager.GetBonus();
                #endregion
                BaseEmployeeFactory empFactory = new EmployeeManagerFactory().CreateFactory(employee);
                empFactory.ApplySalary();

                //abstract factory
                IComputerFactory      factory = new EmployeeSystemFactory().Create(employee);
                EmployeeSystemManager manager = new EmployeeSystemManager(factory);
                employee.ComputerDetails = manager.GetSystemDetails();

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

            ViewBag.EmployeeTypeId = new SelectList(db.Employee_Type, "Id", "EmployeeType", employee.EmployeeTypeId);
            return(View(employee));
        }
Esempio n. 5
0
        // GET api/values
        public async System.Threading.Tasks.Task <IEnumerable <EmployeeModel> > GetAsync()
        {
            // Method has to be refactored, implement dependency injection and move out the following logic to differnt class, so that this can be unit testable

            try
            {
                EmployeeRepository employee = new EmployeeRepository();


                var empData = await employee.GetEmployeeAsync(1);


                BaseEmpFactory empFactory;
                foreach (var emp in empData)
                {
                    empFactory = new EmployeeManagerFactory().CreateFactory(emp);
                    empFactory.ApplySalary();
                }

                return(empData);
            }
            catch (Exception ex)
            {
                Console.Write(ex);
                return(new List <EmployeeModel> {
                });
            }
        }
Esempio n. 6
0
        // GET api/values/5
        public async System.Threading.Tasks.Task <IEnumerable <EmployeeModel> > GetAsync(int id)
        {
            try
            {
                // Method has to be refactored, implement dependency injection and move out the following logic to differnt class, so that this can be unit testable

                EmployeeRepository employee = new EmployeeRepository();


                var empData = await employee.GetEmployeeAsync(1);

                var selectedEmployee = empData.FirstOrDefault((p) => p.id == id);

                BaseEmpFactory empFactory;

                empFactory = new EmployeeManagerFactory().CreateFactory(selectedEmployee);
                empFactory.ApplySalary();
                List <EmployeeModel> lstEmpModel = new List <EmployeeModel>();
                lstEmpModel.Add(selectedEmployee);

                return(lstEmpModel);
            }
            catch (Exception ex)
            {
                Console.Write(ex);
                return(new List <EmployeeModel> {
                });
            }
        }
Esempio n. 7
0
        static void Main(string[] args)
        {
            Employees employees = new Employees();

            //=== Get user inputs=====
            Console.WriteLine("Enter the Employee Name:- ");
            string employeeName = string.Empty;

            employeeName = Console.ReadLine();

            Console.WriteLine("Employee Type number (1=Permanent, 2= Contractor):- ");
            int employeeTypeID = Convert.ToInt32(Console.ReadLine());

            employees.Name           = employeeName;
            employees.EmployeeTypeID = employeeTypeID;

            // ====Pass data to factory====
            BaseEmployeeFactory employeeManagerFactory = new EmployeeManagerFactory().CreateFectory(employees);

            employeeManagerFactory.ApplySalary();

            //======= Print Employee Details ======
            Console.WriteLine("Employee Name:- " + employees.Name);
            Console.WriteLine("Employee Bonus:- " + employees.HourlyPay);
            Console.WriteLine("Employee Bonus:- " + employees.Bonus);
            Console.WriteLine("Employee MedicalAllowance:- " + employees.MedicalAllowance);
            Console.WriteLine("Employee HourseAllowance:- " + employees.HourseAllowance);
        }
Esempio n. 8
0
        public ActionResult Create([Bind(Include = "Id,Name,JobDescription,Number,Department,HourlyPay,Bonus,EmployeeType,HouseAllowance,MedicalAllowance")] Employee employee)
        {
            if (ModelState.IsValid)
            {
                BaseEmployeeFactory employeeFactory = new EmployeeManagerFactory().CreateFactory(employee);
                employeeFactory.ApplySalary();
                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> Create([Bind("Id,Name,JobDescription,Number,Department,HourlyPay,Bonus,EmployeeTypeId,HouseAllowances,MedicalAllowances")] Employee employee)
        {
            if (ModelState.IsValid)
            {
                BaseEmployeeFactory baseEmployeeFactory = new EmployeeManagerFactory().CreateFactory(employee);
                baseEmployeeFactory.ApplySalary();
                _context.Add(employee);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["EmployeeTypeId"] = new SelectList(_context.EmployeeType, "Id", "EmployeeType1", employee.EmployeeTypeId);
            return(View(employee));
        }
Esempio n. 10
0
        public async Task <IActionResult> New(Employee employee)
        {
            if (ModelState.IsValid)
            {
                BaseEmployeeFactory empFactory = new EmployeeManagerFactory().CreateFactory(employee);
                empFactory.ApplySalary();
                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));
        }
Esempio n. 11
0
        public ActionResult Edit([Bind(Include = "Id,Name,JobDescription,Number,Department,HourlyPay,Bonus,EmployeeTypeID,HouseAllowance,MedicalAllowance")] Employee employee)
        {
            if (ModelState.IsValid)
            {
                BaseEmployeeFactory empFactory = new EmployeeManagerFactory().CreateFactory(employee);
                empFactory.ApplySalary();
                IComputerFactory      factory = new EmployeeSystemFactory().Create(employee);
                EmployeeSystemManager manager = new EmployeeSystemManager(factory);
                employee.ComputerDetails = manager.GetSystemDetails();

                db.Entry(employee).State = EntityState.Modified;
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }
            return(View(employee));
        }
Esempio n. 12
0
        public ActionResult Create([Bind(Include = "Id,Name,JobDescription,Number,Department,HourlyPay,Bonus,EmployeeTypeID")] Employee employee)
        {
            if (ModelState.IsValid)
            {
                BaseEmployeeFactory employeeManagerFactory = new EmployeeManagerFactory().CreateFactory(employee);
                employeeManagerFactory.ApplySalary();
                IComputerFactory      factory = new EmployeeSystemFactory().Create(employee);
                EmployeeSystemManager manager = new EmployeeSystemManager(factory);
                employee.ComputerDetails = manager.GetSystemDetails();
                db.Employee.Add(employee);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.EmployeeTypeID = new SelectList(db.Employee_Type, "Id", "EmployeeType", employee.EmployeeTypeID);
            return(View(employee));
        }
Esempio n. 13
0
        private static void Main()
        {
            var employee = new Employee
            {
                EmployeeType = EmployeeType.Permanent
            };

            var factory = new EmployeeManagerFactory().GetEmployeeManager(employee);

            factory.ApplySalary();

            //
            employee = new Employee
            {
                EmployeeType = EmployeeType.Contract
            };
            factory = new EmployeeManagerFactory().GetEmployeeManager(employee);
            factory.ApplySalary();
        }
Esempio n. 14
0
        public void TestMethodForCalculateAnnualSalary()
        {
            //Create test employee object

            EmployeeModel selectedEmployee = new EmployeeModel();

            selectedEmployee.id               = 1;
            selectedEmployee.hourlySalary     = 80;
            selectedEmployee.contractTypeName = "HourlySalaryEmployee";

            BaseEmpFactory baseEmpFactory; //Instantiate factory class

            baseEmpFactory = new EmployeeManagerFactory().CreateFactory(selectedEmployee);
            baseEmpFactory.ApplySalary();

            decimal localAnualLogic = 120 * selectedEmployee.hourlySalary * 12;

            // Assert
            Assert.IsNotNull(selectedEmployee);
            Assert.AreEqual(localAnualLogic, actual: selectedEmployee.annualSalary);
        }
Esempio n. 15
0
        static void Main(string[] args)
        {
            while (true)
            {
                //Simple Factory implementation testing

                //Console.WriteLine("");
                //Console.WriteLine("Enter employee type ID");

                //var empTypeId = Int16.Parse(Console.ReadLine());

                //EmployeeManagerFactory empFactory = new EmployeeManagerFactory();
                //IEmployeeManager employeeManager = empFactory.GetEmployeeManager(empTypeId);

                //var employeePay = employeeManager.GetPay();
                //var employeeBonus = employeeManager.GetBonus();

                //Console.WriteLine($"Employee Pay = {employeePay} --- Employee Bonus = {employeeBonus}");


                //Factory Method implementation testing

                Console.WriteLine("");
                Console.WriteLine("Enter employee type ID");

                var empTypeId = Int16.Parse(Console.ReadLine());

                Employee employee = new Employee()
                {
                    Id = empTypeId
                };

                BaseEmployeeFactory employeeFactory = new EmployeeManagerFactory().CreateFactory(employee);
                employeeFactory.ApplySalary();


                Console.WriteLine($"Employee Pay = {employee.HourlyPay} --- Employee Bonus = {employee.Bonus}/n");
                Console.WriteLine($"Employee House Allowance = {employee.HouseAllowance} --- Employee Medical Allowance = {employee.MedicalAllowance}");
            }
        }