Ejemplo n.º 1
0
 public ActionResult DoLogin(UserDetails u)
 {
     if (ModelState.IsValid)
     {
         EmployeeBusinessLayerr bal = new EmployeeBusinessLayerr();
         //New Code Start
         UserStatus status  = bal.GetUserValidity(u);
         bool       IsAdmin = false;
         if (status == UserStatus.AuthenticatedAdmin)
         {
             IsAdmin = true;
         }
         else if (status == UserStatus.AuthentucatedUser)
         {
             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"));
         //New Code End
     }
     else
     {
         return(View("Login"));
     }
 }
Ejemplo n.º 2
0
        public async Task <ActionResult> Upload(FileUploadViewModel model)
        {
            //List<Employee> employees = GetEmployees(model);
            //EmployeeBusinessLayerr bal = new EmployeeBusinessLayerr();
            //bal.UploadEmployees(employees);
            //return RedirectToAction("Index", "Employee");



            int             t1        = Thread.CurrentThread.ManagedThreadId;
            List <Employee> employees = await Task.Factory.StartNew <List <Employee> >
                                            (() => GetEmployees(model));

            int t2 = Thread.CurrentThread.ManagedThreadId;
            EmployeeBusinessLayerr bal = new EmployeeBusinessLayerr();

            bal.UploadEmployees(employees);
            return(RedirectToAction("Index", "Employee"));
        }
Ejemplo n.º 3
0
        public ActionResult SaveEmployee(Employee e, string BtnSubmit)
        {
            switch (BtnSubmit)
            {
            case "Save Employee":
                if (ModelState.IsValid)
                {
                    EmployeeBusinessLayerr empBal = new EmployeeBusinessLayerr();
                    empBal.SaveEmployee(e);
                    return(RedirectToAction("Index"));
                }
                else
                {
                    CreateEmployeeViewModel vm = new CreateEmployeeViewModel();
                    vm.FirstName = e.FirstName;
                    vm.LastName  = e.LastName;

                    if (e.Salary.HasValue)
                    {
                        vm.Salary = e.Salary.ToString();
                    }
                    else
                    {
                        vm.Salary = ModelState["Salary"].Value.AttemptedValue;
                    }


                    //vm.FooterData = new FooterViewModel();
                    //vm.FooterData.CompanyName = "StepByStepSchools";//Can be set to dynamic value
                    //vm.FooterData.Year = DateTime.Now.Year.ToString();
                    //vm.UserName = User.Identity.Name; //New Line



                    return(View("CreateEmployee", vm));
                }

            case "Cancel":
                return(RedirectToAction("Index"));   // java中重定向
            }
            return(new EmptyResult());
        }
Ejemplo n.º 4
0
        public ActionResult Index()
        {
            EmployeeListViewModel employeeListViewModel = new EmployeeListViewModel();

            EmployeeBusinessLayerr empBal    = new EmployeeBusinessLayerr();
            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();
                if (emp.Salary > 15000)
                {
                    empViewModel.SalaryColor = "yellow";
                }
                else
                {
                    empViewModel.SalaryColor = "green";
                }
                empViewModels.Add(empViewModel);
            }


            employeeListViewModel.Employees = empViewModels;


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


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


            return(View(employeeListViewModel));
        }