Example #1
0
        public async Task <IActionResult> CreateContractual([Bind("DailySalary,Id,EmployeeId,Name,BirthDate,TIN,EmployeeType")] ContractualEmployee contractualEmployee)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            contractualEmployee.Id         = Guid.NewGuid();
            contractualEmployee.EmployeeId = generateEmployeeNumber();
            dbContext.Add(contractualEmployee);
            await dbContext.SaveChangesAsync();

            return(Ok(contractualEmployee.EmployeeId));
        }
        /// <summary>
        /// Helps to keep centraalized object creation. This is object creation with If statement. If same copy of other function we have removed
        /// If condition by introducing dictionary.
        /// </summary>
        /// <param name="EmpType"></param>
        /// <returns></returns>
        public IEmployeeManager GetEmployeeTypeObject_WithoutUsing_RIP_Pattern(int EmpType)
        {
            IEmployeeManager Emp = null;

            if (EmpType == 1)
            {
                Emp = new PermanantEmployee();
            }
            else if (EmpType == 2)
            {
                Emp = new TemporaryEmployee();
            }
            else if (EmpType == 3)
            {
                Emp = new ContractualEmployee();
            }

            return(Emp);
        }