Ejemplo n.º 1
0
        /// <summary>
        /// Get a List of Custom Employees
        /// </summary>
        /// <returns></returns>
        // GET: api/Employees
        public List <EmployeeCustom> GetEmployee()
        {
            List <Employee> employees = repository.GetAll();

            // New Employee custom list
            List <EmployeeCustom> empCustomList = new List <EmployeeCustom>();
            decimal currentSalary;

            foreach (Employee emp in employees)
            {
                if (emp.fk_ContractType == 1) // Hourly Salary
                {
                    currentSalary = _employeeService.CalculateAnnualHourlySalary(emp.hourlySalary ?? 0);
                }
                else // Monthly Salary
                {
                    currentSalary = _employeeService.CalculateAnnualMonthlySalary(emp.monthlySalary ?? 0);
                }

                EmployeeCustom empCustom = new EmployeeCustom {
                    idEmployee         = emp.idEmployee,
                    employeeName       = emp.employeeName,
                    employeePhone      = emp.employeePhone,
                    employeePosition   = emp.employeePosition,
                    contractType       = db.ContractType.Where(ct => ct.idContractType == emp.fk_ContractType).FirstOrDefault().contractTypeName,
                    hourlySalary       = emp.hourlySalary,
                    monthlySalary      = emp.monthlySalary,
                    annualHourlySalary = currentSalary,
                    //annualMonthlySalary = _employeeService.CalculateAnnualMonthlySalary(emp.monthlySalary ?? 0)
                };

                empCustomList.Add(empCustom);
            }
            return(empCustomList);
        }
Ejemplo n.º 2
0
        public void GetEmployeeWhereLambda()
        {
            using (var cn = LocalDb.GetConnection("DapperCX"))
            {
                string lastName = "Yarga";

                var emp = new EmployeeCustom()
                {
                    FirstName = lastName,
                    LastName  = GetLastName(),
                    IsExempt  = true,
                    HireDate  = DateTime.Today,
                    Value     = OtherEnum.Other
                };

                var provider = GetProvider();
                int id       = provider.SaveAsync(cn, emp).Result;

                emp = provider.GetWhereAsync <EmployeeCustom>(cn,
                                                              e => e.FirstName == lastName,
                                                              e => e.LastName == GetLastName()).Result;

                Assert.IsTrue(emp.Id == id);
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Upload Employee
        /// </summary>
        /// <param name="data"></param>
        /// <returns></returns>
        public string UploadEmployee(EmployeeCustom data)
        {
            string result = "";

            try
            {
                SqlConnection con = new SqlConnection(@"Data Source = (localdb)\MSSQLLocalDB; Initial Catalog = Test; Integrated Security = True");
                SqlCommand    cmd = new SqlCommand("UpdateEmployee", con);
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.AddWithValue("@employeeName", data.employeeName);
                cmd.Parameters.AddWithValue("@employeeNo", data.employeeNo);
                cmd.Parameters.AddWithValue("@departmentId", data.departmentId);
                cmd.Parameters.AddWithValue("@salary", data.salary);
                cmd.Parameters.AddWithValue("@joiningDate", data.joiningDate);
                cmd.Parameters.AddWithValue("@id", data.id);
                cmd.Parameters.AddWithValue("@modifiedOn", DateTime.Now);
                con.Open();
                object res = cmd.ExecuteScalar();
                con.Close();
                return(result = "Updated Successfully");
            }
            catch (Exception ex)
            {
                return(result = "Not Updated");
            }
        }
Ejemplo n.º 4
0
        public ActionResult UpdateEmployee(EmployeeCustom data)
        {
            EmployeeDAL employeeDAL = new EmployeeDAL();
            string      result      = employeeDAL.UploadEmployee(data);

            ViewData["result"] = result;
            ModelState.Clear();
            return(View());
        }
Ejemplo n.º 5
0
        public ActionResult InsertEmployee(EmployeeCustom data)
        {
            EmployeeDAL employeeDAL = new EmployeeDAL();
            string      result      = employeeDAL.InsertEmployee(data);

            ViewData["result"] = result;
            ModelState.Clear();
            var check = db.Departments.Where(m => m.isDeleted == 0).Select(m => new { m.departmentName, m.Id }).ToList();

            ViewBag.departmentList = check;
            return(View());
        }
Ejemplo n.º 6
0
        public void GetEmployeeWithRelated()
        {
            using (var cn = LocalDb.GetConnection("DapperCX"))
            {
                var emp = new EmployeeCustom()
                {
                    FirstName = "Whoever",
                    LastName  = "Nobody",
                    IsExempt  = true,
                    HireDate  = DateTime.Today,
                    Value     = OtherEnum.Other
                };

                var provider = GetProvider();
                int id       = provider.SaveAsync(cn, emp).Result;

                emp = provider.GetAsync <EmployeeCustom>(cn, id).Result;
                Assert.IsTrue(emp.Something.SequenceEqual(new string[] { "this", "that", "other" }));
                Assert.IsTrue(emp.SomethingElse.SequenceEqual(new DateTime[] { DateTime.Today }));
            }
        }
Ejemplo n.º 7
0
        public IHttpActionResult PostEmployee(EmployeeCustom employee)
        {
            //if (!ModelState.IsValid)
            //{
            //    return BadRequest(ModelState);
            //}

            // Mapping Employee
            Employee _employee = new Employee {
                employeeName     = employee.employeeName,
                employeePhone    = employee.employeePhone,
                employeePosition = employee.employeePosition,
                hourlySalary     = employee.hourlySalary,
                monthlySalary    = employee.monthlySalary,
                fk_ContractType  = db.ContractType.Where(ct => ct.contractTypeName == employee.contractType).FirstOrDefault().idContractType
            };

            db.Employee.Add(_employee);
            db.SaveChanges();

            return(CreatedAtRoute("DefaultApi", new { id = employee.idEmployee }, employee));
        }
Ejemplo n.º 8
0
        public List <EmployeeCustom> GetEmployee(int id)
        {
            // GetEmployee Employee by ID
            Employee emp = repository.GetById(id);

            if (emp == null)
            {
                return(null);
            }

            decimal currentSalary;

            if (emp.fk_ContractType == 1) // Hourly Salary
            {
                currentSalary = _employeeService.CalculateAnnualHourlySalary(emp.hourlySalary ?? 0);
            }
            else // Monthly Salary
            {
                currentSalary = _employeeService.CalculateAnnualMonthlySalary(emp.monthlySalary ?? 0);
            }

            EmployeeCustom empCustom = new EmployeeCustom
            {
                idEmployee         = emp.idEmployee,
                employeeName       = emp.employeeName,
                employeePhone      = emp.employeePhone,
                employeePosition   = emp.employeePosition,
                contractType       = db.ContractType.Where(ct => ct.idContractType == emp.fk_ContractType).FirstOrDefault().contractTypeName,
                hourlySalary       = emp.hourlySalary,
                monthlySalary      = emp.monthlySalary,
                annualHourlySalary = currentSalary,
                //annualMonthlySalary = _employeeService.CalculateAnnualMonthlySalary(emp.monthlySalary ?? 0)
            };
            List <EmployeeCustom> empList = new List <EmployeeCustom>();

            empList.Add(empCustom);
            return(empList);
        }