public ActionResult Edit(Employee employee)
        {
            if(ModelState.IsValid)
            {
                EmployeeBusinessLayer employeeBusinessLayer = new EmployeeBusinessLayer();
                employeeBusinessLayer.SaveEmployee(employee);

                return RedirectToAction("Index");
            }

            return View(employee);
        }
Ejemplo n.º 2
0
        public ActionResult Edit_Post(int id)
        {
            EmployeeBusinessLayer employeeBusinessLayer = new EmployeeBusinessLayer();
            Employee employee = employeeBusinessLayer.Employees.Single(x => x.ID == id);
            UpdateModel<IEmployee>(employee);

            if (ModelState.IsValid)
            {
                employeeBusinessLayer.SaveEmployee(employee);
                return RedirectToAction("Index");
            }
            return View(employee);
        }
        public ActionResult Edit_Post(int id)
        {
            EmployeeBusinessLayer employeeBusinessLayer = new EmployeeBusinessLayer();
            Employee employee = employeeBusinessLayer.Employees.Single(emp => emp.ID == id);
            UpdateModel(employee, new string[] { "ID", "Gender", "City", "DateOfBirth" });
            //UpdateModel(employee, null, null, new string[] { "Name" });
            if(ModelState.IsValid)
            {
                employeeBusinessLayer.SaveEmployee(employee);

                return RedirectToAction("Index");
            }

            return View(employee);
        }
Ejemplo n.º 4
0
 public ActionResult SaveEmployee(Employee emp)
 {
     EmployeeBusinessLayer empBal = new EmployeeBusinessLayer();
     empBal.SaveEmployee(emp);
     EmployeeViewModel empViewModel = new EmployeeViewModel();
     empViewModel.EmployeeName = emp.FirstName + "|" + emp.LastName;
     empViewModel.Salary = emp.Salary.ToString("C");
     if (emp.Salary>15000)
     {
         empViewModel.SalaryColor = "red";
     }
     else
     {
         empViewModel.SalaryColor = "blue";
     }
     return Json(empViewModel);
 }
Ejemplo n.º 5
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
                        {
                            CreateEmployeeViewModel vm = new CreateEmployeeViewModel();
                            //vm.FooterData = new FooterViewModel();
                           // vm.FooterData.CompanyName = "StepByStepSchools";
                           // vm.FooterData.Year = DateTime.Now.Year.ToString();
                            //vm.UserName = User.Identity.Name;
                            #region
                            //vm.FirstName = e.FirstName;
                            //vm.LastName = e.LastName;
                            //if (e.Salary!=0)
                            //{
                            //    vm.Salary = e.Salary.ToString();
                            //}
                            //else
                            //{
                            //    vm.Salary = ModelState["Salary"].Value.AttemptedValue;
                            //}

                            #endregion
                            return View("CreateEmployee",vm);
                        }
                    }
                case "Cancel":
                    {
                        return RedirectToAction("Index");
                    }
                default:
                    break;
            }
            return new EmptyResult();
        }
 public ActionResult SaveEmployee(Employee e, string BtnSubmit)
 {
     switch (BtnSubmit)
     {
         case "Save Employee":
             if (ModelState.IsValid)
             {
                 var empBal = new EmployeeBusinessLayer();
                 empBal.SaveEmployee(e);
                 return RedirectToAction("Index");
             }
             else
             {
                 var vm = new CreateEmployeeViewModel
                 {
                     FirstName = e.FirstName,
                     LastName = e.LastName,
                 };
                 if (e.Salary.HasValue)
                     vm.Salary = e.Salary.ToString();
                 else
                     vm.Salary = ModelState["Salary"].Value.AttemptedValue;
                 return View("CreateEmployee", vm); // Day 4 Change - Passing e here
             }
         case "Cancel":
             return RedirectToAction("Index");
     }
     return new EmptyResult();
 }