public ActionResult Upload(FileUploadViewModel model)
 {
     var employees = GetEmployees(model);
     var bal = new EmployeeBusinessLayer();
     bal.UploadEmployees(employees);
     return RedirectToAction("Index", "Employee");
 }
 public ActionResult Delete(int id)
 {
     EmployeeBusinessLayer employeeBusinessLayer =
         new EmployeeBusinessLayer();
     employeeBusinessLayer.DeleteEmployee(id);
     return RedirectToAction("Index");
 }
Esempio n. 3
0
 public async Task<ActionResult> Upload(FileUploadViewModel model)
 {
     int t1 = Thread.CurrentThread.ManagedThreadId;
     List<Employee> employees = await Task.Factory.StartNew<List<Employee>>(() => GetEmployees(model));
     int t2 = Thread.CurrentThread.ManagedThreadId;
     EmployeeBusinessLayer bal = new EmployeeBusinessLayer();
     bal.UploadEmployees(employees);
     EmployeeListViewModel vm = new EmployeeListViewModel();
     vm.Employees = new List<EmployeeViewModel>();
     foreach (Employee item in employees)
     {
         EmployeeViewModel evm = new EmployeeViewModel();
         evm.EmployeeName = item.FirstName + "&" + item.LastName;
         evm.Salary = item.Salary.ToString("C");
         if (item.Salary>15000)
         {
             evm.SalaryColor = "red";
         }
         else
         {
             evm.SalaryColor = "blue";
         }
         vm.Employees.Add(evm);
     }
     return Json(vm);
 }
        public ActionResult Index()
        {
            EmployeeBusinessLayer employeeBusinessLayer = new EmployeeBusinessLayer();
            List<Employee> employees = employeeBusinessLayer.Employees.ToList();

            return View(employees);
        }
Esempio n. 5
0
 public async Task<ActionResult> Upload(FileUploadViewModel model)
 {
     int t1 = Thread.CurrentThread.ManagedThreadId;
     List<Employee> employees = await Task.Factory.StartNew<List<Employee>>(() => GetEmployees(model));
     //List<Employee> employees = GetEmployees(model);
     int t2 = Thread.CurrentThread.ManagedThreadId;
     EmployeeBusinessLayer bal = new EmployeeBusinessLayer();
     bal.UploadEmployees(employees);
     return RedirectToAction("Index", "Employee");
 }
        public ActionResult Edit(Employee employee)
        {
            if(ModelState.IsValid)
            {
                EmployeeBusinessLayer employeeBusinessLayer = new EmployeeBusinessLayer();
                employeeBusinessLayer.SaveEmployee(employee);

                return RedirectToAction("Index");
            }

            return View(employee);
        }
        public ActionResult Create_Post()
        {
            if (ModelState.IsValid)
            {
                Employee employee = new Employee();
                UpdateModel<Employee>(employee);
                EmployeeBusinessLayer employeeBusinessLayer = new EmployeeBusinessLayer();
                employeeBusinessLayer.AddEmployee(employee);

                return RedirectToAction("Index");
            }
            return View();
        }
Esempio n. 8
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 Create(FormCollection fc)
        {
            Employee employee = new Employee();

            employee.Name = fc["Name"];
            employee.Gender = fc["Gender"];
            employee.City = fc["City"];
            employee.DateOfBirth = Convert.ToDateTime(fc["DateOfBirth"]);

            EmployeeBusinessLayer employeeBusinessLayer = new EmployeeBusinessLayer();

            employeeBusinessLayer.AddEmployee(employee);
            return RedirectToAction("Index");
        }
        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);
        }
Esempio n. 11
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);
 }
        public ActionResult DoLogin(UserDetails u)
        {
            if (!ModelState.IsValid)
                return View("Login");

            var bal = new EmployeeBusinessLayer();
            //New Code Start
            var status = bal.GetUserValidity(u);
            if (status == UserStatus.AuthenticatedAdmin || status == UserStatus.AuthentucatedUser)
            {
                var isAdmin = status == UserStatus.AuthenticatedAdmin;
                FormsAuthentication.SetAuthCookie(u.UserName, false);
                Session["IsAdmin"] = isAdmin;
                return RedirectToAction("Index", "Employee");
            }

            ModelState.AddModelError("CredentialError", "Invalid Username or Password");
            return View("Login");
        }
Esempio n. 13
0
        public ActionResult DoLogin(UserDetails u)
        {
            if (ModelState.IsValid)
            {
                EmployeeBusinessLayer bal = new EmployeeBusinessLayer();
                #region
                //if (bal.IsValidUser(u))
                //{
                //    FormsAuthentication.SetAuthCookie(u.UserName, false);
                //    return RedirectToAction("Index", "Employee");
                //}
                //else
                //{
                //    ModelState.AddModelError("CredentialError", "InValid Username or Password");
                //    return View("Login");
                //}
                #endregion
                UserStatus status = bal.GetUserValidity(u);
                bool IsAdmin = false;
                if (status==UserStatus.AuthenticatedAdmin)
                {
                    IsAdmin = true;
                }
                else if (status==UserStatus.AuthenticatedUser)
                {
                    IsAdmin = false;
                }
                else
                {
                    ModelState.AddModelError("CredentialError", "Invalid Username or Password");
                    return View("Login");
                }
                FormsAuthentication.SetAuthCookie(u.UserName, false);
                Session["IsAdmin"] = IsAdmin;
                return RedirectToAction("Index", "Employee");

            }
            else
            {
                return View("Login");
            }
        }
        public ActionResult Index(int id)
        {
            var employeeListViewModel = new EmployeeListViewModel();
            var empBal = new EmployeeBusinessLayer();
            var employees = empBal.GetEmployees();
            var empViewModels = new List<EmployeeViewModel>();

            foreach (Employee emp in employees)
            {
                var empViewModel = new EmployeeViewModel();
                empViewModel.EmployeeName = emp.FirstName + " " + emp.LastName;
                empViewModel.Salary = emp.Salary != null ? emp.Salary.Value.ToString("C") : "";
                if (emp.Salary > 15000)
                    empViewModel.SalaryColor = "yellow";
                else
                    empViewModel.SalaryColor = "green";
                empViewModels.Add(empViewModel);
            }
            employeeListViewModel.Employees = empViewModels;
            //employeeListViewModel.UserName = "******";
            return View("Index", employeeListViewModel);
        }
Esempio n. 15
0
 public ActionResult EmployeeList()
 {
     EmployeeListViewModel employeeListViewModel = new EmployeeListViewModel();
     EmployeeBusinessLayer empBal = new EmployeeBusinessLayer();
     List<Employee> employees = empBal.GetEmployees();
     List<EmployeeViewModel> empViewModels = new List<EmployeeViewModel>();
     foreach (Employee item in employees)
     {
         EmployeeViewModel empViewModel = new EmployeeViewModel();
         empViewModel.EmployeeName = item.FirstName + "|" + item.LastName;
         empViewModel.Salary = item.Salary.ToString("C");
         if (item.Salary>15000)
         {
             empViewModel.SalaryColor = "blue";
         }
         else
         {
             empViewModel.SalaryColor = "red";
         }
         empViewModels.Add(empViewModel);
     }
     employeeListViewModel.Employees = empViewModels;
     return PartialView("EmployeeList", employeeListViewModel);
 }
Esempio n. 16
0
 public ActionResult Edit(int id)
 {
     EmployeeBusinessLayer employeeBusinessLayer = new EmployeeBusinessLayer();
     Employee employee = employeeBusinessLayer.Employees.Single(emp => emp.ID == id);
     return View(employee);
 }
 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();
 }
Esempio n. 18
0
        public ActionResult Index()
        {
            //Employee emp = new Employee();
            //emp.FirstName = "gyk";
            //emp.LastName = "alex";
            //emp.Salary = 2000;
            //ViewBag.Employee = emp;    //ViewBag和ViewData可以相互调用,底层数据结构是同一个
            ////ViewData["Employee"] = emp;//  但这种类型并不好用,有安全和效率低的问题

            //EmployeeViewModel vmEmployee = new EmployeeViewModel();
            //vmEmployee.EmployeeName = emp.FirstName + " " + emp.LastName;
            //vmEmployee.Salary = emp.Salary.ToString("C");

            //if (emp.Salary > 15000)
            //{
            //    vmEmployee.SalaryColor = "yellow";
            //}
            //else
            //{
            //    vmEmployee.SalaryColor = "green";
            //}

            EmployeeListViewModel employeeListViewModel = new EmployeeListViewModel();
            //employeeListViewModel.UserName = User.Identity.Name;
            EmployeeBusinessLayer empBal = new EmployeeBusinessLayer();
            List<Employee> employees = empBal.GetEmployees();
            List<EmployeeViewModel> empViewModels = new List<EmployeeViewModel>();
            foreach (Employee item in employees)
            {
                EmployeeViewModel empViewModel = new EmployeeViewModel();
                empViewModel.EmployeeName = item.FirstName + "*" + item.LastName;
                empViewModel.Salary = item.Salary.ToString();
                if (item.Salary > 15000)
                {
                    empViewModel.SalaryColor = "yellow";
                }
                else
                {
                    empViewModel.SalaryColor = "green";
                }
                empViewModels.Add(empViewModel);
            }
            employeeListViewModel.Employees = empViewModels;
            //employeeListViewModel.FooterData = new FooterViewModel();
            //employeeListViewModel.FooterData.CompanyName = "StepByStepSchools";
            //employeeListViewModel.FooterData.Year = DateTime.Now.ToString();

            return View("Index", employeeListViewModel);
        }
Esempio n. 19
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();
        }