예제 #1
0
        public void PersonTest()
        {
            Person me = new Person();

            me.FirstName = "Carl";
            me.LastName  = "Goss";
            Console.WriteLine(me.Name);

            Employee dwight = new Employee(12345);

            dwight.FirstName = "Dwight";
            dwight.LastName  = "Shrute";
            Console.WriteLine(dwight.Name);
            Console.WriteLine(dwight.EmployeeNumber);

            SalaryEmployee jim = new SalaryEmployee(12333, 60000);

            jim.FirstName = "Jim";
            Console.WriteLine(jim.FirstName);
            Console.WriteLine(jim.EmployeeNumber);
            Console.WriteLine(jim.Salary);

            List <Employee> ListOfEmployees = new List <Employee>();

            ListOfEmployees.Add(jim);
            ListOfEmployees.Add(dwight);
        }
예제 #2
0
        public void SetName_ShouldSetCorrectly()
        {
            Person martha = new Person();

            martha.SetFirstame("Martha");   //sets first name through method
            martha.SetLastName("Vineyard"); //sets last name through method
            Console.WriteLine(martha.Name);

            Customer bob = new Customer();

            bob.SetFirstame("Bobert");
            bob.SetLastName("Boss");
            Console.WriteLine(bob.Name);

            //set properties via a block
            SalaryEmployee tedEmployee = new SalaryEmployee
            {
                PhoneNumber    = "1-800-fakenum",
                Salary         = 800000,
                HireDate       = new DateTime(1304, 01, 01),
                EmployeeNumber = 394
            }; //need semicolon

            Console.WriteLine(tedEmployee.YearsWithCompany);
        }
예제 #3
0
        public void EmployeeTests()
        {
            Employee       julian  = new Employee();
            HourlyEmployee bubbles = new HourlyEmployee();
            SalaryEmployee ricky   = new SalaryEmployee();

            List <Employee> allEmployees = new List <Employee>();

            allEmployees.Add(julian);
            allEmployees.Add(bubbles);
            allEmployees.Add(ricky);

            //var employee = allEmployees[1];

            foreach (Employee worker in allEmployees)
            {
                if (worker.GetType() == typeof(SalaryEmployee))
                {
                    SalaryEmployee sEmployee = (SalaryEmployee)worker;
                    Console.WriteLine($"This is a salary employee that makes {sEmployee.Salary}.");
                }
                else if (worker is HourlyEmployee hourlyWorker)
                {
                    HourlyEmployee hEmployee = (HourlyEmployee)worker;
                    Console.WriteLine(hourlyWorker.Hours);
                }

                /* Abstraction
                 * Polymorphism
                 * Inheritance - one class recieving the traits/properties of another class (hourlyEmployee and Employee)
                 * Encapsulation
                 */
            }
        }
예제 #4
0
        public void EmployeeTests()
        {
            Employee       jarvis = new Employee();       // newing up new instance of the employee class named jarvis
            HourlyEmployee tony   = new HourlyEmployee(); // new instance of the hourly employee class named tony
            SalaryEmployee pepper = new SalaryEmployee(); //new instance of salary employee class named pepper

            tony.HoursWorked = 55;
            tony.HourlyWage  = 9003;
            pepper.Salary    = 200000;

            List <Employee> allEmployees = new List <Employee>();

            allEmployees.Add(jarvis);
            allEmployees.Add(tony);
            allEmployees.Add(pepper);                           //adds all these employess to the list of employees
            //tony.Name = "Tony Stark"
            tony.SetFirstName("Tony");                          // sets the property of the first name and the field _firstName
            tony.SetLastName("Stark");                          // sets the property of the last name and the field _LastName

            foreach (Employee worker in allEmployees)           //iterates through the list loops through this list and reassigns the variable worker each time the loop reaches the start of the list the list so first time through it is assigned the variable of jarvis, second time through the list it is assigned the values of tony, last time through the list it is assigned the value of pepper. Once it has run through the all the employees in the allemployee list the program stops.
            {
                if (worker.GetType() == typeof(SalaryEmployee)) // if worker is a salaryEmployee //will run through jarvis, tony, and pepper because they are all within the list of allemployees
                {
                    SalaryEmployee sEmployee = (SalaryEmployee)worker;
                    Console.WriteLine($"this is a salary employee that makes {sEmployee.Salary}"); // ?
                }
                else if (worker is HourlyEmployee hourlyWorker)                                    // pattern matching it is taking worker turning into hourly worker then creating new variable within the if statement
                {
                    //HourlyEmployee hEmployee = (HourlyEmployee)hourlyWorker;
                    Console.WriteLine($"{worker.Name} has worked {hourlyWorker.HoursWorked} hours!");
                }
            }
        }
예제 #5
0
        public void Employee()
        {
            Employee       jarvis = new Employee();//objects to work with
            HourlyEmployee tony   = new HourlyEmployee();
            SalaryEmployee pepper = new SalaryEmployee();

            tony.HoursWorked = 55;
            tony.HourlyWage  = 9003;
            pepper.Salary    = 2000000;

            List <Employee> allEmployees = new List <Employee>();//rules of list that lists can hold ONE thing

            allEmployees.Add(jarvis);
            allEmployees.Add(tony);
            allEmployees.Add(pepper); //no error bc they are inherite from the base class
            //tony.SetFirstName = "Tony Stark"; this line does not work as it is read only
            //tony.SetFirstName("Tony"); this line works and is a preference choice on how to write this

            foreach (Employee worker in allEmployees)
            {
                if (worker.GetType() == typeof(SalaryEmployee))
                {
                    SalaryEmployee sEmployee = (SalaryEmployee)worker; //casting
                    Console.WriteLine($"This is a salary employee that makes {sEmployee.Salary}");
                }
                else if (worker is HourlyEmployee hourlyWorker) //pattern matching taking working turning it into hourley worker and making a new variable in the IF statement
                {
                    //HourlyEmployee hEmployee = (HourlyEmployee)hourlyWorker;
                    Console.WriteLine($"{worker.Name} has worked {hourlyWorker.HoursWorked} hours!");
                }
            }//polymorphism is the P in API ... classes related thru inheritance ...uses methods to preform tasks in different ways ...one method that can do serval functionality
        }
예제 #6
0
        public void EmployeeTests()
        {
            Employee       jarvis = new Employee();
            HourlyEmployee tony   = new HourlyEmployee();

            tony.HoursWorked = 12;
            tony.HourlyWage  = 15000;
            SalaryEmployee friday = new SalaryEmployee();

            friday.Salary = 1000000;

            List <Employee> allEmployees = new List <Employee>();

            allEmployees.Add(jarvis);
            allEmployees.Add(tony);
            allEmployees.Add(friday);

            //var employee = allEmployees[1];

            foreach (Employee worker in allEmployees)
            {
                if (worker.GetType() == typeof(SalaryEmployee))
                {
                    SalaryEmployee sEmployee = (SalaryEmployee)worker;
                    Console.WriteLine($"This is a salary employee that makes {sEmployee.Salary}.");
                }
                else if (worker is HourlyEmployee hourlyWorker) // Pattern Matching
                {
                    // Casting
                    HourlyEmployee hEmployee = (HourlyEmployee)worker;
                    Console.WriteLine(hourlyWorker.HoursWorked);
                }
            }
        }
예제 #7
0
        public void EmployeeTests()
        {
            Employee       jarvis = new Employee();
            HourlyEmployee tony   = new HourlyEmployee();
            SalaryEmployee pepper = new SalaryEmployee();

            tony.HoursWorked = 55;
            tony.HourlyWage  = 9003;
            pepper.Salary    = 200000;

            List <Employee> allEmployees = new List <Employee>();

            allEmployees.Add(jarvis); //we never added any info so in the foreach loop it will be blank
            allEmployees.Add(tony);   // we never set his name so in the foreach loop nothing will appear for worker.Name
            allEmployees.Add(pepper);
            //tony.Name = "Tony Stark";
            tony.SetFirstName("Tony");
            tony.SetLastName("Stark");

            foreach (Employee worker in allEmployees)
            {
                if (worker.GetType() == typeof(SalaryEmployee))
                {
                    SalaryEmployee sEmployee = (SalaryEmployee)worker; //casting because worker is of type List<Employee> and not SalaryEmployee
                    Console.WriteLine($"This is a salary employee that makes {sEmployee.Salary}");
                }
                else if (worker is HourlyEmployee hourlyWorker) //pattern matching-- so we don't have to cast like the below
                {
                    //HourlyEmployee hEmployee = (HourlyEmployee)hourlyWorker; -- casting
                    Console.WriteLine($"{worker.Name} has worked {hourlyWorker.HoursWorked} hours!");
                }
            }
        }
예제 #8
0
        public dynamic GetDefaultInfo()
        {
            SalaryEmployee model = new SalaryEmployee();

            try
            {
                model = _salaryEmployeeService.GetQueryable().FirstOrDefault();
            }
            catch (Exception ex)
            {
                LOG.Error("GetInfo", ex);
                Dictionary <string, string> Errors = new Dictionary <string, string>();
                Errors.Add("Generic", "Error " + ex);

                return(Json(new
                {
                    Errors
                }, JsonRequestBehavior.AllowGet));
            }

            return(Json(new
            {
                model.Id,
                model.EmployeeId,
                EmployeeNIK = model.Employee.NIK,
                EmployeeName = model.Employee.Name,
                model.EffectiveDate,
                model.Description,
                model.Errors
            }, JsonRequestBehavior.AllowGet));
        }
예제 #9
0
        public void EmployeeTests()
        {
            Employee       jarvis = new Employee();
            HourlyEmployee tony   = new HourlyEmployee();
            SalaryEmployee pepper = new SalaryEmployee();

            tony.HoursWorked = 55;
            tony.HourlyWage  = 9003;
            pepper.Salary    = 200000;

            List <Employee> allEmployees = new List <Employee>();

            allEmployees.Add(jarvis);
            allEmployees.Add(tony);
            allEmployees.Add(pepper);

            foreach (Employee worker in allEmployees)
            {
                if (worker.GetType() == typeof(SalaryEmployee))
                {
                    SalaryEmployee sEmployee = (SalaryEmployee)worker;
                    Console.WriteLine($"This is a salary employee that makes{sEmployee.Salary}");
                }
                else if (worker is HourlyEmployee hourlyWorker)
                {
                    HourlyEmployee hEmployee = (HourlyEmployee)hourlyWorker;
                    Console.WriteLine($"{ worker.Name} HashSet worked { hourlyWorker.HoursWorked} hours!");
                }
            }
        }
예제 #10
0
        public dynamic Insert(SalaryEmployee model)
        {
            try
            {
                if (!AuthenticationModel.IsAllowed("Create", Core.Constants.Constant.MenuName.EmployeeSalary, Core.Constants.Constant.MenuGroupName.Setting))
                {
                    Dictionary <string, string> Errors = new Dictionary <string, string>();
                    Errors.Add("Generic", "You are Not Allowed to Add record");

                    return(Json(new
                    {
                        Errors
                    }, JsonRequestBehavior.AllowGet));
                }

                model = _salaryEmployeeService.CreateObject(model, _employeeService, _salaryEmployeeDetailService, _salaryItemService, _salaryStandardDetailService);
            }
            catch (Exception ex)
            {
                LOG.Error("Insert Failed", ex);
                Dictionary <string, string> Errors = new Dictionary <string, string>();
                Errors.Add("Generic", "Error " + ex);

                return(Json(new
                {
                    Errors
                }, JsonRequestBehavior.AllowGet));
            }

            return(Json(new
            {
                model.Errors
            }));
        }
예제 #11
0
        public void EmployeeTests()
        {
            Employee       jenny   = new Employee();
            HourlyEmployee michael = new HourlyEmployee();
            SalaryEmployee pepper  = new SalaryEmployee();

            michael.HoursWorked = 55;
            michael.HourlyWage  = 20;
            pepper.Salary       = 84000;

            List <Employee> allEmployees = new List <Employee>();

            allEmployees.Add(jenny);
            allEmployees.Add(michael);
            allEmployees.Add(pepper);   // despite technically being different types, since they all inherit from Employee they can all go in the list

            foreach (Employee worker in allEmployees)
            {
                if (worker.GetType() == typeof(SalaryEmployee))
                {
                    SalaryEmployee sEmployee = (SalaryEmployee)worker;
                    Console.WriteLine($"This is a salaried employee who makes {sEmployee.Salary}");
                }
                else if (worker is HourlyEmployee hourlyWorker) // this is called pattern matching; turns worker to type HourlyEmployee (if it can; if it can't it returns false, fails the if, and moves on) and creates new variable hourlyWorker.
                // Basically, if worker is of type HourlyEmployee (in addition to its explicit type of Employee), then they become are assigned to variable hourlyWorker which is explicitly of type HourlyEmployee
                {
                    Console.WriteLine($"{worker.Name} has worked {hourlyWorker.HoursWorked} hours!");
                }
            }
        }
예제 #12
0
        public void SetName_ShouldSetCorrectly()
        {
            Person martha = new Person();

            martha.PhoneNumber = "8675309";

            Person stanley = new Person
            {
                PhoneNumber = "8675309",
                Email       = "*****@*****.**",
            };

            Customer bob = new Customer();

            bob.PhoneNumber = "800-555-1234";

            Employee ted = new SalaryEmployee
            {
                PhoneNumber = "fakeNumber",
                Salary      = 120000,
                HireDate    = new DateTime(1304, 01, 01),
            };

            Console.WriteLine(ted.YearsWithCompany);
        }
예제 #13
0
        private void HisobEmployee(int SalaryId)
        {
            decimal summ = 0;

            foreach (var item in GloblMain.dbo.Employees.ToList())
            {
                salaryEmployee.SalaryId   = SalaryId;
                salaryEmployee.EmployeeId = item.EmployeeId;
                salaryEmployee.INNPS      = item.Payment * 0.001;
                salaryEmployee.ENDF       = item.Payment * 0.12 - salaryEmployee.INNPS;
                salaryEmployee.ESP        = item.Payment * 0.12;
                summ += decimal.Parse(item.Payment.ToString());
                salaryEmployee.ApplyChanges();
                salaryEmployee = new SalaryEmployee();
            }
            dgSalary.DataSource = GloblMain.dbo.SalaryEmployees.ToList()
                                  .Where(x => x.SalaryId == SalaryId).ToList();
            if (GloblMain.GetSumOrg(summ))
            {
                MessageBox.Show("Оплачивается ежемесячно с основного счета ");
            }
            else
            {
                MessageBox.Show("На основном счете недостаточно денег ");
            }
        }
예제 #14
0
        public void EmployeeTests()
        {
            Employee       jarvis = new Employee();
            HourlyEmployee tony   = new HourlyEmployee();
            SalaryEmployee pepper = new SalaryEmployee();

            tony.HoursWorked = 55;
            tony.HourlyWage  = 9003;
            pepper.Salary    = 20000;

            List <Employee> allEmployees = new List <Employee>();

            allEmployees.Add(jarvis);
            allEmployees.Add(tony);
            allEmployees.Add(pepper);
            //tony.name = "tony stark";
            tony.SetFirstName("Tony");
            tony.SetLastName("Stark");


            foreach (Employee worker in allEmployees)
            {
                if (worker.GetType() == typeof(SalaryEmployee))
                {
                    SalaryEmployee sEmployee = (SalaryEmployee)worker;
                    Console.WriteLine($"This is a salary employee that makes {sEmployee.Salary}");
                }
                else if (worker is HourlyEmployee hourlyWorker) // Pattern Matching
                {
                    //HourlyEmployee hEmployee = (HourlyEmployee)hourlyWorker;
                    Console.WriteLine($"{worker.Name} has worked {hourlyWorker.HoursWorked} hours!");
                }
            }
        }
        public void GetYearlySalaryTest()
        {
            SalaryEmployee salaryEmployee = new SalaryEmployee("David", "Barnes", 250m);
            string         expected       = "$250.00";
            string         actual         = salaryEmployee.GetFormattedSalary();

            Assert.AreEqual(expected, actual);
        }
예제 #16
0
        public static Dictionary <int, List <Employee> > Parse(string xmlPath)
        {
            XmlDocument doc = new XmlDocument();

            doc.Load(xmlPath);
            var         root      = doc.SelectSingleNode("department");
            XmlNodeList monthList = root.SelectNodes("month");
            Dictionary <int, List <Employee> > res = new Dictionary <int, List <Employee> >();

            foreach (XmlNode monthNode in monthList)
            {
                XmlNodeList     employeeList = monthNode.SelectNodes("employee");
                List <Employee> employees    = new List <Employee>();
                foreach (XmlNode employeeNode in employeeList)
                {
                    Employee employee = null;
                    string   type     = employeeNode.Attributes["type"].Value;
                    string   name     = employeeNode.Attributes["name"].Value;
                    DateTime birthday = Convert.ToDateTime(employeeNode.Attributes["birthday"].Value);
                    switch (type)
                    {
                    case "salary":
                        employee = new SalaryEmployee()
                        {
                            Name     = name,
                            Birthday = birthday
                        };
                        break;

                    case "hour":
                        employee = new HourEmployee()
                        {
                            Name         = name,
                            Birthday     = birthday,
                            WorkingHours = Convert.ToDouble(employeeNode.Attributes["workingHours"].Value)
                        };
                        break;

                    case "sale":
                        employee = new SaleEmployee()
                        {
                            Name       = name,
                            Birthday   = birthday,
                            SaleAmount = Convert.ToDouble(employeeNode.Attributes["amount"].Value)
                        };
                        break;
                    }
                    if (employee != null)
                    {
                        employees.Add(employee);
                    }
                }

                res.Add(Convert.ToInt32(monthNode.Attributes["value"].Value), employees);
            }
            return(res);
        }
예제 #17
0
        public SalaryEmployee VHasEmployee(SalaryEmployee salaryEmployee, IEmployeeService _employeeService)
        {
            Employee employee = _employeeService.GetObjectById(salaryEmployee.EmployeeId);

            if (employee == null)
            {
                salaryEmployee.Errors.Add("Employee", "Tidak ada");
            }
            return(salaryEmployee);
        }
예제 #18
0
        public SalaryEmployeeDetail VHasSalaryEmployee(SalaryEmployeeDetail salaryEmployeeDetail, ISalaryEmployeeService _salaryEmployeeService)
        {
            SalaryEmployee salaryEmployee = _salaryEmployeeService.GetObjectById(salaryEmployeeDetail.SalaryEmployeeId);

            if (salaryEmployee == null)
            {
                salaryEmployeeDetail.Errors.Add("SalaryEmployee", "Tidak ada");
            }
            return(salaryEmployeeDetail);
        }
예제 #19
0
 public bool ValidCreateObject(SalaryEmployee salaryEmployee, IEmployeeService _employeeService, ISalaryEmployeeService _salaryEmployeeService)
 {
     VHasEmployee(salaryEmployee, _employeeService);
     if (!isValid(salaryEmployee))
     {
         return(false);
     }
     VHasEffectiveDate(salaryEmployee, _salaryEmployeeService);
     return(isValid(salaryEmployee));
 }
예제 #20
0
        public void FirstAndLastNameTest()
        {
            // Arrange
            SalaryEmployee testEmployee = MakeNewSalaryEmployee();
            string         expected     = "David Barnes";

            // Act
            string actual = testEmployee.FirstAndLastName();

            // Assert
            Assert.AreEqual(expected, actual);
        }
예제 #21
0
        public void FormattedSalaryTest()
        {
            // Arrange
            SalaryEmployee testEmployee = MakeNewSalaryEmployee();
            string         expected     = "$13,000.00";

            // Act
            string actual = testEmployee.FormattedSalary();

            // Assert
            Assert.AreEqual(expected, actual);
        }
예제 #22
0
        public string PrintError(SalaryEmployee obj)
        {
            string erroroutput = "";
            KeyValuePair <string, string> first = obj.Errors.ElementAt(0);

            erroroutput += first.Key + "," + first.Value;
            foreach (KeyValuePair <string, string> pair in obj.Errors.Skip(1))
            {
                erroroutput += Environment.NewLine;
                erroroutput += pair.Key + "," + pair.Value;
            }
            return(erroroutput);
        }
        public void LastNameFirstNameTest()
        {
            // Arrange
            SalaryEmployee salaryEmployee = new SalaryEmployee("David", "Barnes", 250m);

            string expected = "Barnes, David";

            // Act
            string actual = salaryEmployee.GetLastNameFirstName();

            // Assert
            Assert.AreEqual(expected, actual);
        }
예제 #24
0
        public void WhenSalaryNotSpecified_ThrowException()
        {
            // Arrange
            var   employeeId = new EmployeeId("foo");
            var   name       = new Name("f", "m", "l", "s", "t");
            var   address    = new FakeAddress();
            Money salary     = null;

            // Act
            Action action = () => SalaryEmployee.CreateNew(employeeId, name, address, salary);

            // Assert
            action.Should().Throw <EmployeeDomainException>().WithMessage("Employee salary must not be null.");
        }
예제 #25
0
        public void SetName_ShouldSetCorrectly()
        {
            Person martha = new Person();

            martha.PhoneNumber = "8675309";

            Customer bob = new Customer();

            bob.PhoneNumber = "2721234";

            SalaryEmployee ted = new SalaryEmployee();

            ted.PhoneNumber = "5057124";
        }
예제 #26
0
 public SalaryEmployee VHasEffectiveDate(SalaryEmployee salaryEmployee, ISalaryEmployeeService _salaryEmployeeService)
 {
     if (salaryEmployee.EffectiveDate == null || salaryEmployee.EffectiveDate.Equals(DateTime.FromBinary(0)))
     {
         salaryEmployee.Errors.Add("EffectiveDate", "Tidak valid");
     }
     else
     {
         SalaryEmployee active = _salaryEmployeeService.GetActiveObject();
         if (active != null && salaryEmployee.EffectiveDate < active.EffectiveDate)
         {
             salaryEmployee.Errors.Add("EffectiveDate", "Harus lebih besar atau sama dengan SalaryEmployee yang Aktif");
         }
     }
     return(salaryEmployee);
 }
예제 #27
0
        public void CreateNew_CreatesSalaryEmployee()
        {
            // Arrange
            var employeeId = new EmployeeId("foo");
            var name       = new Name("bar", null, "bee", null, null);
            var address    = new FakeAddress();
            var salary     = new Money(new FakeCurrency(), new MoneyValue(100000m));

            // Act
            var employee = SalaryEmployee.CreateNew(employeeId, name, address, salary);

            // Assert
            employee.EmployeeId.Should().Be(employeeId);
            employee.Name.Should().Be(name);
            employee.Address.Should().Be(address);
            employee.Salary.Should().Be(salary);
        }
예제 #28
0
 public SalaryEmployee SoftDeleteObject(SalaryEmployee salaryEmployee)
 {
     if (_validator.ValidDeleteObject(salaryEmployee))
     {
         _repository.SoftDeleteObject(salaryEmployee);
         // sesuaikan yg aktif
         if (salaryEmployee.IsActive)
         {
             SalaryEmployee shouldbe = GetObjectByClosestEffectiveDate(DateTime.Now);
             if (shouldbe != null)
             {
                 shouldbe.IsActive = true;
                 _repository.UpdateObject(shouldbe);
             }
         }
     }
     return(salaryEmployee);
 }
예제 #29
0
        public void SetName_ShouldSetCorrectly()
        {
            Person martha = new Person();

            martha.PhoneNumber = "9707722";
            Console.WriteLine(martha.PhoneNumber);

            Customer bob = new Customer();

            bob.PhoneNumber = "123-1234";

            SalaryEmployee ted = new SalaryEmployee
            {
                PhoneNumber = "fakeNumber",
                HireDate    = new DateTime(1304, 01, 01),
            };

            Console.WriteLine(ted.YearsWithCompany);
        }
예제 #30
0
        public void SetName_ShouldSetCorrectly()
        {
            Person martha = new Person();  //martha is a new person class

            martha.PhoneNumber = "8675309";

            Customer bob = new Customer(); //bob has access to person and customer class because of inhertiance

            bob.PhoneNumber = "123-1234";

            SalaryEmployee ted = new SalaryEmployee
            {
                PhoneNumber = "fakeNumber", //again inheritance at work here
                Salary      = 120000,
                HireDate    = new DateTime(1304, 01, 01),
            };

            Console.WriteLine(ted.YearsWithCompany); //cw must be within the method bruh
        }