public ActionResult DoLogin(UserDetails u)
        {
            if (ModelState.IsValid)
            {
                EmployeeBusinessLayer bal = new EmployeeBusinessLayer();

                //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");
            }
        }
 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.Value.ToString("C");
         if (item.Salary > 15000)
         {
             evm.SalaryColor = "yellow";
         }
         else
         {
             evm.SalaryColor = "green";
         }
         vm.Employees.Add(evm);
     }
     return Json(vm);
 }
        public ActionResult GetView()
        {
            EmployeeListViewModel employeeListViewModel = new EmployeeListViewModel();

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

            return View("MyView",employeeListViewModel);
        }
 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.FirstName = e.FirstName;
                 vm.LastName = e.LastName;
                 if (e.Salary > 0)
                 {
                     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();
 }
        public ActionResult Index()
        {
            EmployeeListViewModel employeeListViewModel = new EmployeeListViewModel();
               // employeeListViewModel.UserName = User.Identity.Name; //New Line
            EmployeeBusinessLayer empBal = new EmployeeBusinessLayer();
            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.Value.ToString("C");
                if (emp.Salary > 15000)
                {
                    empViewModel.SalaryColor = "yellow";
                }
                else
                {
                    empViewModel.SalaryColor = "green";
                }
                empViewModels.Add(empViewModel);
            }
            employeeListViewModel.Employees = empViewModels;
            //employeeListViewModel.FooterData = new FooterViewModel();
            //employeeListViewModel.FooterData.CompanyName = "StepByStepSchools";//Can be set to dynamic value
            //employeeListViewModel.FooterData.Year = DateTime.Now.Year.ToString();
            return View("Index", employeeListViewModel);
        }
 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);
     return RedirectToAction("Index", "Employee");
 }
Exemple #7
0
        public ActionResult GetView()
        {
            //Employee emp = new Employee();
            //emp.FirstName = "Sukesh";
            //emp.LastName = "Marla";
            //emp.Salary = 20000;

            /*
            ViewData["Employee"] = emp;
            ViewBag.Employee = emp;
            return View("GetView");
            */

            //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("GetView",vmEmp);

            EmployeeListViewModel employeeListViewModel = new EmployeeListViewModel();
            EmployeeBusinessLayer empBal = new EmployeeBusinessLayer();
            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("C");
                if (emp.Salary > 15000)
                {
                    empViewModel.SalaryColor = "yellow";
                }
                else
                {
                    empViewModel.SalaryColor = "green";
                }
                empViewModels.Add(empViewModel);
            }
            employeeListViewModel.Employees = empViewModels;
            employeeListViewModel.UserName = "******";
            return View("GetView", employeeListViewModel);
        }
Exemple #8
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);
        }
 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.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); // Day 4 Change - Passing e here
             }
         case "Cancel":
             return RedirectToAction("Index");
     }
     return new EmptyResult();
 }