Example #1
0
        public Response CreateEmployeeWithAttribute(BaseEmployee employee)
        {
            Response response = new Response();

            try
            {
                PropertyInfo employeePropertyWithAttribute = employee.GetType().GetProperties().Where(e => e.CustomAttributes.Any(a => a.AttributeType == typeof(HourlySalary))).First();
                employee.GetType().GetProperty(employeePropertyWithAttribute.Name).SetValue(employee, 300);

                bool isSuccess = SaveEmploye(employee);

                if (isSuccess)
                {
                    response.IsSuccess     = true;
                    response.Message       = "Create employee with attribute seccessfuly";
                    response.AverageSalary = employee.AverageSalary;
                }
                else
                {
                    response.IsSuccess = false;
                    response.Message   = "Create employee with attribute error";
                }
            }
            catch (Exception ex)
            {
                response.IsSuccess = false;
                response.Message   = $"Create employee with attribute error: {ex.Message}";
            }
            return(response);
        }
            public void Visit(Element element)
            {
                BaseEmployee employee = element as BaseEmployee;

                employee.VacationDays += 3;
                Console.WriteLine("{0} {1}'s new vacation days: {2}", employee.GetType().Name, employee.Name, employee.VacationDays);
            }
            public void Visit(Element element)
            {
                BaseEmployee employee = element as BaseEmployee;

                employee.Income *= 1.10;
                Console.WriteLine("{0} {1}'s new income: {2:C}", employee.GetType().Name, employee.Name, employee.Income);
            }