Beispiel #1
0
        /// <summary>
        /// Mapper to employee
        /// </summary>
        /// <typeparam name="TR">Type to cast</typeparam>
        /// <param name="origin">Origin data type</param>
        /// <param name="destination">Destination data type</param>
        /// <returns>A casted type</returns>
        public static TR EmployeeMapper <TR>(this IEmployeeDTO origin, TR destination)
            where TR : IEmployeeDTO, new()
        {
            if (origin == null)
            {
                destination = default(TR);
            }
            else
            {
                if (destination == null)
                {
                    destination = new TR();
                }

                destination.id                     = origin.id;
                destination.name                   = origin.name;
                destination.contractTypeName       = origin.contractTypeName;
                destination.roleId                 = origin.roleId;
                destination.roleName               = origin.roleName;
                destination.roleDescription        = origin.roleDescription;
                destination.hourlySalary           = origin.hourlySalary;
                destination.monthlySalary          = origin.monthlySalary;
                destination.calculatedAnnualSalary = origin.calculatedAnnualSalary;
            }

            return(destination);
        }
        public IList <IEmployeeDTO> GetAllEmployees()
        {
            IList <IEmployeeDTO> employeeDTOList = null;

            using (EmployeePortalEntities employeePortalEntities = new EmployeePortalEntities())
            {
                try
                {
                    var employeeEntityList = employeePortalEntities.Employees;
                    if (employeeEntityList != null)
                    {
                        employeeDTOList = new List <IEmployeeDTO>();

                        foreach (var employee in employeeEntityList)
                        {
                            IEmployeeDTO employeeDTO = (IEmployeeDTO)DTOFactory.Instance.Create(DTOType.Employee);
                            EntityConverter.FillDTOFromEntity(employee, employeeDTO);
                            employeeDTOList.Add(employeeDTO);
                        }
                    }
                }
                catch (Exception ex)
                {
                    ExceptionManager.HandleException(ex);
                    throw new DACException(ex.Message, ex);
                }
            }
            return(employeeDTOList);
        }
        public bool UpdateEmployee(IEmployeeDTO employeeDTO)
        {
            bool retVal = false;

            using (EmployeePortalEntities employeePortalEntities = new EmployeePortalEntities())
            {
                try
                {
                    var employeeEntity = employeePortalEntities.Employees.FirstOrDefault(employee => employee.EmployeeId == employeeDTO.EmployeeId);
                    if (employeeEntity != null)
                    {
                        employeeEntity.FirstName = employeeDTO.FirstName;
                        employeeEntity.LastName  = employeeDTO.LastName;
                        employeeEntity.Email     = employeeDTO.Email;
                        employeePortalEntities.SaveChanges();
                        retVal = true;
                    }
                }
                catch (Exception ex)
                {
                    ExceptionManager.HandleException(ex);
                    throw new DACException(ex.Message, ex);
                }
            }
            return(retVal);
        }
Beispiel #4
0
        /// <summary>
        /// Calculate the Annual Salary
        /// </summary>
        /// <param name="employeeDTO">Employee entity</param>
        /// <returns>The annual salary calculated</returns>
        public override decimal CalculatedAnnualSalary(IEmployeeDTO employeeDTO)
        {
            decimal annualSalary = 0;

            annualSalary = 120 * employeeDTO.hourlySalary * 12;

            return(annualSalary);
        }
Beispiel #5
0
        /// <summary>
        /// Get all employees
        /// </summary>
        /// <param name="employeeDTO">Employe entity</param>
        /// <returns>A list of employees</returns>
        public List <IEmployeeDTO> GetEmployees(IEmployeeDTO employeeDTO)
        {
            return(Wrapper.ExecuteWrapper <List <IEmployeeDTO>, EmployeeBL>(() =>
            {
                List <IEmployeeDTO> employees = employeeDAL.Value.GetEmployees(employeeDTO);

                employees.ForEach(p => p.calculatedAnnualSalary = SalaryFabric.CalculatedAnnualSalary(p));

                return employees;
            }));
        }
Beispiel #6
0
        public override void AddEmployee(IEmployeeDTO employee)
        {
            AddedEmployee = employee;
            ++TotalEmployees;

            using (var writer = File.AppendText($"{ FileName }.txt"))
            {
                writer.WriteLine($"Name: { employee.Name } , Salary: { employee.Salary } ");

                // if the delegate is not null, then we can pass the object and the args
                EmployeeAdded?.Invoke(this, new EventArgs());
            }
        }
Beispiel #7
0
        public override void AddEmployee(IEmployeeDTO employee)
        {
            AddedEmployee = employee;
            ++TotalEmployees;

            if (employee.Salary <= 1000 && employee.Salary >= 0)
            {
                employeeList.Add(new EmployeeDTO { Name = employee.Name, Salary = employee.Salary });

                // if the delegate is not null, then we can pass the object and the args
                EmployeeAdded?.Invoke(this, new EventArgs());                
            }
            else
            {
                throw new ArgumentException($"Invalid {nameof(employee)}");
            }
        }
Beispiel #8
0
        /// <summary>
        /// Calculate the Annual Salary
        /// </summary>
        /// <param name="employeeDTO">Employee entity</param>
        /// <returns>The annual salary calculated</returns>
        public static decimal CalculatedAnnualSalary(IEmployeeDTO employeeDTO)
        {
            SalaryBase salaryBase   = null;
            decimal    annualSalary = 0;

            TypesContracts typesContracts = BasicExtensions.ToEnum <TypesContracts>(employeeDTO.contractTypeName);

            switch (typesContracts)
            {
            case TypesContracts.HourlySalaryEmployee:
                salaryBase = new  HourlySalary();
                break;

            case TypesContracts.MonthlySalaryEmployee:
                salaryBase = new MonthlySalary();
                break;
            }

            annualSalary = salaryBase.CalculatedAnnualSalary(employeeDTO);

            return(annualSalary);
        }
        public int AddEmployee(IEmployeeDTO employeeDTO, ISecurityDTO securityDTO)
        {
            int retVal = default(int);

            using(EmployeePortalEntities employeePortalEntities = new EmployeePortalEntities())
            {
                try
                {
                    Employee employee = new Employee();
                    employee.EmployeeCode = employeeDTO.EmployeeCode;
                    employee.FirstName = employeeDTO.FirstName;
                    employee.LastName = employeeDTO.LastName;
                    employee.Email = employeeDTO.Email;
                    employee.DOB = employeeDTO.DOB;
                    employee.DateOfJoining = employeeDTO.DateOfJoining;
                    employee.DepartmentId = employeeDTO.DepartmentId;
                    Employee addedEmployee = employeePortalEntities.Employees.Add(employee);

                    Login login = new Login();
                    var departmentEntity = employeePortalEntities.Departments.FirstOrDefault(department => department.DepartmentId == employeeDTO.DepartmentId);
                    login.Role = (departmentEntity.DepartmentName.Equals("Administration")) ? "A" : "U";
                    login.LoginName = securityDTO.LoginName;
                    login.Password = securityDTO.Password;
                    login.EmployeeId = addedEmployee.EmployeeId;
                    employeePortalEntities.Logins.Add(login);

                    employeePortalEntities.SaveChanges();
                    retVal = addedEmployee.EmployeeId;
                }
                catch (Exception ex)
                {
                    ExceptionManager.HandleException(ex);
                    throw new DACException(ex.Message, ex);
                }
            }

            return retVal;
        }
        public int AddEmployee(IEmployeeDTO employeeDTO, ISecurityDTO securityDTO)
        {
            int retVal = default(int);

            using (EmployeePortalEntities employeePortalEntities = new EmployeePortalEntities())
            {
                try
                {
                    Employee employee = new Employee();
                    employee.EmployeeCode  = employeeDTO.EmployeeCode;
                    employee.FirstName     = employeeDTO.FirstName;
                    employee.LastName      = employeeDTO.LastName;
                    employee.Email         = employeeDTO.Email;
                    employee.DOB           = employeeDTO.DOB;
                    employee.DateOfJoining = employeeDTO.DateOfJoining;
                    employee.DepartmentId  = employeeDTO.DepartmentId;
                    Employee addedEmployee = employeePortalEntities.Employees.Add(employee);

                    Login login            = new Login();
                    var   departmentEntity = employeePortalEntities.Departments.FirstOrDefault(department => department.DepartmentId == employeeDTO.DepartmentId);
                    login.Role       = (departmentEntity.DepartmentName.Equals("Administration")) ? "A" : "U";
                    login.LoginName  = securityDTO.LoginName;
                    login.Password   = securityDTO.Password;
                    login.EmployeeId = addedEmployee.EmployeeId;
                    employeePortalEntities.Logins.Add(login);

                    employeePortalEntities.SaveChanges();
                    retVal = addedEmployee.EmployeeId;
                }
                catch (Exception ex)
                {
                    ExceptionManager.HandleException(ex);
                    throw new DACException(ex.Message, ex);
                }
            }

            return(retVal);
        }
Beispiel #11
0
        /// <summary>
        /// Get all employees
        /// </summary>
        /// <param name="employeeDTO">Employee Entity</param>
        /// <returns>A list of employees</returns>
        public List <IEmployeeDTO> GetEmployees(IEmployeeDTO employeeDTO)
        {
            return(Wrapper.ExecuteWrapper <List <IEmployeeDTO>, EmployeeDAL>(() =>
            {
                List <Employee> employees = new List <Employee>();
                string url = "http://masglobaltestapi.azurewebsites.net/api/Employees";

                WebClient client = new WebClient();
                string content = client.DownloadString(url);

                DataContractJsonSerializer serializer = new DataContractJsonSerializer(typeof(List <Employee>));

                using (MemoryStream ms = new MemoryStream(Encoding.Unicode.GetBytes(content)))
                {
                    employees = (List <Employee>)serializer.ReadObject(ms);
                }

                employees = employees.Concat(EmployeeMockData()).ToList();

                employees = employees.Where(p => employeeDTO.id == 0 ? true : p.id == employeeDTO.id).ToList();

                return employees.ToList <IEmployeeDTO>();
            }));
        }
Beispiel #12
0
        public IList <IEmployeeDTO> SearchEmployeeByRawQuery(ISearchEmployeeDTO searchEmployeeDTO, bool checkTerminationDate)
        {
            IList <IEmployeeDTO> retVal = null;

            string query = @"SELECT * 
                            FROM Employees
                            WHERE
                            (
	                            (@FirstName IS NOT NULL AND  FirstName LIKE '%' + @FirstName + '%') OR
	                            (@LastName IS NOT NULL AND  LastName LIKE '%' + @LastName + '%') OR
	                            (@Email IS NOT NULL AND  Email LIKE '%' + @Email + '%') OR
	                            (@BeginDate IS NOT NULL AND  DateOfJoining >= @BeginDate ) OR
	                            (@EndDate IS NOT NULL AND  DateOfJoining <= @EndDate) OR
	                            (@Department IS NOT NULL AND  DepartmentId = @Department) 
                            )" + (checkTerminationDate ? "AND TerminationDate IS NULL" : string.Empty);

            try
            {
                using (EmployeePortal2017Entities portal = new EmployeePortal2017Entities())
                {
                    var firstNameParameter = searchEmployeeDTO.Firstname != null ?
                                             new SqlParameter("FirstName", searchEmployeeDTO.Firstname) :
                                             new SqlParameter("FirstName", DBNull.Value);

                    var lastNameParameter = searchEmployeeDTO.LastName != null ?
                                            new SqlParameter("LastName", searchEmployeeDTO.LastName) :
                                            new SqlParameter("LastName", DBNull.Value);

                    var emailParameter = searchEmployeeDTO.Email != null ?
                                         new SqlParameter("Email", searchEmployeeDTO.Email) :
                                         new SqlParameter("Email", DBNull.Value);

                    var startDateParameter = searchEmployeeDTO.BeginDate.HasValue ?
                                             new SqlParameter("BeginDate", searchEmployeeDTO.BeginDate) :
                                             new SqlParameter("BeginDate", DBNull.Value);

                    var endDateParameter = searchEmployeeDTO.Enddate.HasValue ?
                                           new SqlParameter("EndDate", searchEmployeeDTO.Enddate) :
                                           new SqlParameter("EndDate", DBNull.Value);

                    var departmentIdParameter = searchEmployeeDTO.DepartmentId.HasValue ?
                                                new SqlParameter("Department", searchEmployeeDTO.DepartmentId) :
                                                new SqlParameter("Department", DBNull.Value);

                    IList <Employee> employeeList = new List <Employee>();
                    employeeList = portal.ObjectContext.ExecuteStoreQuery <Employee>(query, new object[] { firstNameParameter,
                                                                                                           lastNameParameter, emailParameter, startDateParameter,
                                                                                                           endDateParameter, departmentIdParameter })
                                   .ToList();
                    if (employeeList.Count > 0)
                    {
                        retVal = new List <IEmployeeDTO>();
                        foreach (var employee in employeeList)
                        {
                            IEmployeeDTO employeeDTO = (IEmployeeDTO)DTOFactory.Instance.Create(DTOType.EmployeeDTO);
                            EntityConverter.FillDTOFromEntity(employee, employeeDTO);
                            retVal.Add(employeeDTO);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                ExceptionManager.HandleException(ex);
                throw new DACException(ex.Message);
            }
            return(retVal);
        }
Beispiel #13
0
 /// <summary>
 /// Mapper to employee
 /// </summary>
 /// <typeparam name="TR">Type to cast</typeparam>
 /// <param name="origin">Origin data type</param>
 /// <returns>A casted type</returns>
 public static TR EmployeeMapper <TR>(this IEmployeeDTO origin)
     where TR : IEmployeeDTO, new()
 {
     return(origin.EmployeeMapper(new TR()));
 }
Beispiel #14
0
 /// <summary>
 /// Calculate the Annual Salary
 /// </summary>
 /// <param name="employeeDTO">Employee entity</param>
 /// <returns>The annual salary calculated</returns>
 public virtual decimal CalculatedAnnualSalary(IEmployeeDTO employeeDTO)
 {
     return(0);
 }
 public bool UpdateEmployee(IEmployeeDTO employeeDTO)
 {
     bool retVal = false;
     using (EmployeePortalEntities employeePortalEntities = new EmployeePortalEntities())
     {
         try
         {
             var employeeEntity = employeePortalEntities.Employees.FirstOrDefault(employee => employee.EmployeeId == employeeDTO.EmployeeId);
             if (employeeEntity != null)
             {
                 employeeEntity.FirstName = employeeDTO.FirstName;
                 employeeEntity.LastName = employeeDTO.LastName;
                 employeeEntity.Email = employeeDTO.Email;
                 employeePortalEntities.SaveChanges();
                 retVal = true;
             }
         }
         catch (Exception ex)
         {
             ExceptionManager.HandleException(ex);
             throw new DACException(ex.Message, ex);
         }
     }
     return retVal;
 }
 public IList<IEmployeeDTO> SearchEmployees(IEmployeeDTO emoloyeeDTO)
 {
     throw new NotImplementedException();
 }
 public IList <IEmployeeDTO> SearchEmployees(IEmployeeDTO emoloyeeDTO)
 {
     throw new NotImplementedException();
 }