public ActionResult Index() { 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.GetValueOrDefault(0).ToString("C"); empViewModel.SalaryColor = emp.Salary > 35000 ? "yellow" : "green"; empViewModels.Add(empViewModel); } EmployeeListViewModel employeeListViewModel = new EmployeeListViewModel(); employeeListViewModel.Employees = empViewModels; //employeeListViewModel.UserName = "******"; //employeeListViewModel.FooterData = new FooterViewModel(); //employeeListViewModel.FooterData.CompanyName = "Acme Inc."; //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"); }
public ActionResult DoLogin(UserDetails u) { if (ModelState.IsValid) { EmployeeBusinessLayer empBL = new EmployeeBusinessLayer(); UserStatus status = empBL.GetUserValidity(u); bool IsAdmin = status == UserStatus.AuthenticatedAdmin; if (status == UserStatus.NonAuthenticatedUser) { 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 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 createEmployeeViewModel = new CreateEmployeeViewModel(); createEmployeeViewModel.FirstName = e.FirstName; createEmployeeViewModel.LastName = e.LastName; //createEmployeeViewModel.FooterData = new FooterViewModel(); //createEmployeeViewModel.FooterData.CompanyName = "Acme Inc."; //createEmployeeViewModel.FooterData.Year = DateTime.Now.Year.ToString(); //createEmployeeViewModel.UserName = User.Identity.Name; if (e.Salary.HasValue) { createEmployeeViewModel.Salary = e.Salary.ToString(); } else { createEmployeeViewModel.Salary = ModelState["Salary"].Value.AttemptedValue; } return View("CreateEmployee", createEmployeeViewModel); } case "Cancel": return RedirectToAction("Index"); } return new EmptyResult(); }