// GET: Employee
        public ActionResult GetView()
        {
            Employee emp = new Employee();
            emp.firstName = "sohaib";
            emp.lastName = "maroof";
            emp.salary = 999999;
            //viewbag.employee = emp;
            //viewdata["employee"] = emp;
            //putting viewmodel logic inside model

            EmployeeViewModel vmEmp = new EmployeeViewModel();
            vmEmp.EmployeeName = emp.firstName + " " + emp.lastName;
            vmEmp.salary = emp.salary.ToString("C");
            if (emp.salary > 15000)
            {
                vmEmp.salaryColor = "yellow";
            }
            else
            {
                vmEmp.salaryColor = "green";
            }

              //  vmEmp.UserName = "******";

            return View("MyView", vmEmp);
        }
 public ActionResult Edit(Employee employee)
 {
     if (ModelState.IsValid)
     {
         _employeeRepository.InsertOrUpdate(employee);
         _employeeRepository.Save();
         RedirectToAction("Manage");
     }
     return View();
 }
 public void InsertOrUpdate(Employee employee)
 {
     if (employee.EmployeeID == default(int))
     {
         // New entity
         context.employees.Add(employee);
     }
     else
     {
         // Existing entity
         context.Entry(employee).State = System.Data.Entity.EntityState.Modified;
     }
 }
        public ActionResult SaveEmployee(Employee e, string BtnSubmit)
        {
            CreateEmployeeViewModel employeeListViewModel = new CreateEmployeeViewModel();
            //employeeListViewModel.UserName = "******";
            //employeeListViewModel.footerViewModel = new FooterViewModel();
            //employeeListViewModel.footerViewModel.CompanyName = "tombola";//Can be set to dynamic value
            //employeeListViewModel.footerViewModel.Year = DateTime.Now.Year.ToString();
            if (!ModelState.IsValid)
            {   employeeListViewModel.firstName = e.firstName;
                employeeListViewModel.lastName = e.lastName;
                employeeListViewModel.salary = e.salary.ToString();

                return View("CreateEmployee-Copy", employeeListViewModel); // Day 4 Change - Passing e here
               // return View("CreateEmployee-Copy", e);
            }
            EmployeeBusinessLayer empBal = new EmployeeBusinessLayer();
            empBal.SaveEmployee(e);
            return RedirectToAction("gridView");
        }
Example #5
0
 public void AddEmployee(Employee employee)
 {
     Employees.Add(employee);
 }