Ejemplo n.º 1
0
        public ActionResult Index()
        {
            EmployeeViewModelList employeeListViewModel = new EmployeeViewModelList();

            EmployeeBusinessLayer empBal = new EmployeeBusinessLayer();
            List<Employee> employees = empBal.GetEmployees();

            List < EmployeeViewModel > empViewModels = new List<EmployeeViewModel>();

            foreach (Employee emp in employees)
            {
                EmployeeViewModel empViewModel = new EmployeeViewModel();
                empViewModel.EmployeeName = emp.FirstName + " " + emp.LastName;
                empViewModel.Salary = emp.Salary.ToString("C");
                if (emp.Salary > 15000)
                {
                    empViewModel.SalaryColor = "yellow";
                }
                else
                {
                    empViewModel.SalaryColor = "green";
                }
                empViewModels.Add(empViewModel);
            }
            employeeListViewModel.Employees = empViewModels;
            return View("Index", employeeListViewModel);
        }
Ejemplo n.º 2
0
 public ActionResult SaveEmployee(Employee e, string BtnSubmit)
 {
     switch (BtnSubmit)
     {
         case "Save Employee":
             if (ModelState.IsValid)
             {
                 EmployeeBusinessLayer empBal = new EmployeeBusinessLayer();
                 empBal.SaveEmployee(e);
                 return RedirectToAction("Index");
             }
             else
             {
                 return View("AddEmployee");
             }
         case "Cancel":
             return RedirectToAction("Index");
     }
     return new EmptyResult();
 }