Esempio n. 1
0
        public async Task<ActionResult> Upload(FileUploadViewModel model)
        {
            int t1 = Thread.CurrentThread.ManagedThreadId;
            List<Employee> employees = await Task.Factory.StartNew(() => GetEmployees(model));
            int t2 = Thread.CurrentThread.ManagedThreadId;

            EmployeeBusinessLayer ebl = new EmployeeBusinessLayer();
            ebl.UploadEmployees(employees);
            return RedirectToAction("Index", "Employee");
        }
Esempio n. 2
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 = "yellow";
     }
     else
     {
         empViewModel.SalaryColor = "green";
     }
     return Json(empViewModel);
 }
Esempio n. 3
0
 public ActionResult EmployeeList()
 {
     EmployeeListViewModel employeeListViewModel = new EmployeeListViewModel();
     EmployeeBusinessLayer ebl = new EmployeeBusinessLayer();
     var employees = ebl.GetEmployees();
     List<EmployeeViewModel> empViewModels = new List<EmployeeViewModel>();
     foreach (var item in employees)
     {
         EmployeeViewModel evm = new EmployeeViewModel();
         evm.EmployeeName = item.FirstName + "|" + item.LastName;
         evm.Salary = item.Salary.ToString("c");
         evm.SalaryColor = item.Salary > 15000 ? "yellow" : "green";
         empViewModels.Add(evm);
     }
     employeeListViewModel.Employees = empViewModels;
     return View("EmployeeList", employeeListViewModel);
 }
Esempio n. 4
0
 public async Task<ActionResult> Upload(FileUploadViewModel model)
 {
     int t1 = Thread.CurrentThread.ManagedThreadId;
     List<Employee> employees = await Task.Factory.StartNew<List<Employee>>(() => GetEmployees(model));
     EmployeeBusinessLayer ebl = new EmployeeBusinessLayer();
     ebl.UploadEmployees(employees);
     EmployeeListViewModel vm = new EmployeeListViewModel();
     vm.Employees = new List<EmployeeViewModel>();
     foreach (var item in employees)
     {
         EmployeeViewModel evm = new EmployeeViewModel();
         evm.EmployeeName = item.FirstName + " " + item.LastName;
         evm.Salary = item.Salary.ToString("c");
         evm.SalaryColor = item.Salary > 15000 ? "yellow" : "green";
         vm.Employees.Add(evm);
     }
     return Json(vm);
 }
Esempio n. 5
0
        public ActionResult DoLogin(UserDetails u)
        {
            if (ModelState.IsValid)
            {
                EmployeeBusinessLayer bal = new EmployeeBusinessLayer();

                var us = bal.GetUserValidity(u);

                bool IsAdmin = false;
                if(us == UserStatus.AuthenticatedAdmin)
                {
                    IsAdmin = true;
                }
                else if(us == 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");

                //if (bal.IsValidUser(u))
                //{
                //    FormsAuthentication.SetAuthCookie(u.UserName, false);
                //    return RedirectToAction("Index", "Employee");
                //}
                //else
                //{
                //    ModelState.AddModelError("CredentialError", "Invalid Username or Password");
                //    return View("Login");
                //}
            }
            else
            {
                return View("Login");
            }
        }
Esempio n. 6
0
        public ActionResult Index()
        {
            //Employee em = new Employee()
            //{
            //    FirstName = "FN",
            //    LastName = "LN",
            //    Salary = 20000
            //};

            //EmployeeViewModel vmEmp = new EmployeeViewModel();
            //vmEmp.EmployeeName = em.FirstName + " " + em.LastName;
            //vmEmp.Salary = em.Salary.ToString("c");
            //vmEmp.SalaryColor = em.Salary > 15000 ? "yellow" : "green";

            EmployeeListViewModel employeeListViewModel = new EmployeeListViewModel() { Employees = new List<EmployeeViewModel>() };
            EmployeeBusinessLayer empBal = new EmployeeBusinessLayer();
            var employees = empBal.GetEmployees();
            foreach (var emp in employees)
            {
                EmployeeViewModel empViewModel = new EmployeeViewModel()
                {
                     EmployeeName = emp.FirstName + " " + emp.LastName,
                     Salary = emp.Salary.ToString(),
                     SalaryColor = emp.Salary>15000?"yellow":"green",
                };
                employeeListViewModel.Employees.Add(empViewModel);
            }

            //employeeListViewModel.UserName = User.Identity.Name;

            //employeeListViewModel.FooterData = new FooterViewModel()
            //{
            //     CompanyName = "CompanyName",
            //     Year = DateTime.Now.Year.ToString()
            //};

            return View(employeeListViewModel);
        }
Esempio n. 7
0
        public ActionResult SaveEmployee(Employee e)
        {
            if (ModelState.IsValid)
            {
                EmployeeBusinessLayer empBal = new EmployeeBusinessLayer();
                empBal.SaveEmployee(e);

                return RedirectToAction("Index");
            }
            else
            {
                CreateEmployeeViewModel vm = new CreateEmployeeViewModel();
                vm.FirstName = e.FirstName;
                vm.LastName = e.LastName;

                vm.Salary = e.Salary.ToString();

                //vm.FooterData = new FooterViewModel()
                //{
                //    CompanyName = "CompanyName",
                //     Year = DateTime.Now.Year.ToString()
                //};

                //vm.UserName = User.Identity.Name;

                return View("CreateEmployee",vm);
            }
            //return new EmptyResult();
        }