public ActionResult Index() { EmployeeBusinessLayer employeeBusinessLayer = new EmployeeBusinessLayer(); List<Employee> employees = employeeBusinessLayer.GetEmployees(); List<EmployeeViewModel> employeeViewModels = new List<EmployeeViewModel>(); foreach (Employee employee in employees) { EmployeeViewModel empVM = new EmployeeViewModel(); empVM.EmployeeName = employee.FirstName + " " + employee.LastName; empVM.Salary = employee.Salary.ToString("C"); if (employee.Salary >= 15000) empVM.SalaryColor = "yellow"; else empVM.SalaryColor = "green"; employeeViewModels.Add(empVM); } EmployeeListViewModel empLVM = new EmployeeListViewModel() ; empLVM.EmployeeViewModels = employeeViewModels; empLVM.FooterData = new FooterViewModel(); empLVM.FooterData.CompanyName = "Mindtree"; empLVM.FooterData.Year = DateTime.Now.Year.ToString(); empLVM.UserName = User.Identity.Name; return View("Index", empLVM); }
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 gridView() { 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 = "******"; employeeListViewModel.footerViewModel = new FooterViewModel(); employeeListViewModel.footerViewModel.CompanyName = "tombola";//Can be set to dynamic value employeeListViewModel.footerViewModel.Year = DateTime.Now.Year.ToString(); return View("gridView", employeeListViewModel); }
public ActionResult DoLogin(UserDetails u) { EmployeeBusinessLayer bal = new EmployeeBusinessLayer(); if (bal.IsValidUser(u)) { FormsAuthentication.SetAuthCookie(u.UserName, false); return RedirectToAction("gridView", "Employee"); } else { ModelState.AddModelError("CredentialError", "Invalid Username or Password"); return View("Login"); } }
public ActionResult SaveEmployee(Employee e) { if (ModelState.IsValid) { EmployeeBusinessLayer ebl = new EmployeeBusinessLayer(); Employee emp = ebl.SaveEmployee(e); return RedirectToAction("Index"); } else { return View("AddEmployee"); } return new EmptyResult(); }
public ActionResult EmployeeList() { EmployeeListViewModel employeeListViewModel = new ViewModel.SPA.EmployeeListViewModel(); employeeListViewModel.Employees = new List <EmployeeViewModel>(); EmployeeBusinessLayer bal = new EmployeeBusinessLayer(); List <Employee> employees = bal.GetEmployees(); foreach (var item in employees) { EmployeeViewModel vm = new EmployeeViewModel(); vm.EmployeeName = string.Concat(item.FirstName, " ", item.LastName); vm.Salary = item.Salary.Value.ToString("C"); vm.SalaryColor = item.Salary > 15000 ? "yellow" : "green"; employeeListViewModel.Employees.Add(vm); } return(View("_EmployeeList", employeeListViewModel)); }
//public ActionResult SaveEmployee(Employee e,string BtnSubmit) //{ // if (BtnSubmit== "SaveEmployee") // { // return Content(e.FirstName + "|" + e.LastName + "|" + e.Salary); // } // if (BtnSubmit == "Cancel") // { // return RedirectToAction("Index"); // } // return new EmptyResult(); //} //@* 如果控件名称与类属性名称不匹配会发生什么情况? *@ // @* 三种解决方案*@ //1.内部action 方法,获取请求中的post数据。Form 语法和手动构建Model对象 //public ActionResult SaveEmployee() //{ // Employee e = new Employee(); // e.FirstName = Request["FName"]; // e.LastName = Request["LName"]; // e.Salary = Convert.ToInt32(Request["Salary"]); // return Content(e.FirstName + "|" + e.LastName + "|" + e.Salary); //} //2.使用参数名称和手动创建Model对象 //public ActionResult SaveEmployee(string FName,string LName, int Salary) //{ // Employee e = new Employee(); // e.FirstName = FName; // e.LastName = LName; // e.Salary = Convert.ToInt32(Salary); // return Content(e.FirstName + "|" + e.LastName + "|" + e.Salary); //} //3. 创建自定义Model Binder public ActionResult SaveEmployee(Employee e, string BtnSubmit) { if (BtnSubmit == "SaveEmployee") { if (ModelState.IsValid) { EmployeeBusinessLayer layer = new EmployeeBusinessLayer(); layer.SaveEmployee(e); return(RedirectToAction("Index")); } else { return(View("CreateEmployee"));//转到试图 } } if (BtnSubmit == "Cancel") { return(RedirectToAction("Index"));//重定向 } return(new EmptyResult()); }
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 { return(View("CreateEmployee")); } case "Cancel": return(RedirectToAction("Index")); } return(new EmptyResult()); }
public ActionResult Index() { var employeeListViewModel = new EmployeeListViewModel(); var empBal = new EmployeeBusinessLayer(); var employees = empBal.GetEmployees(); var empViewModels = new List <EmployeeViewModel>(); foreach (var emp in employees) { var empViewModel = new EmployeeViewModel { EmployeeName = emp.FirstName + " " + emp.LastName, Salary = emp.Salary.ToString("C"), SalaryColour = (emp.Salary > 15000) ? "yellow" : "green" }; empViewModels.Add(empViewModel); } employeeListViewModel.Employees = empViewModels; return(View(employeeListViewModel)); }
public ActionResult Create_Post() { // Retrieve form data using form collection Employee employee = new Employee(); employee.ID = 46; // employee.d = 2; // UpdateModel(employee); TryUpdateModel(employee); if (ModelState.IsValid) { EmployeeBusinessLayer employeeBusinessLayer = new EmployeeBusinessLayer(); employeeBusinessLayer.AddEmmployee(employee); return(RedirectToAction("Index")); } else { return(View()); } }
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)); }
public ActionResult DoLogin(UserDetails u) { if (ModelState.IsValid) { EmployeeBusinessLayer bal = new EmployeeBusinessLayer(); //if (bal.IsValidUser(u)) //{ // FormsAuthentication.SetAuthCookie(u.UserName, false); // return RedirectToAction("AddNew", "Employee"); //} //else //{ // ModelState.AddModelError("CredentialError", "Invalid Username or Password"); // return View("Login"); //} 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("IndexList", "Employee")); } else { return(View("Login")); } }
public ActionResult Index() { 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 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 = "******"; //employeeListViewModel.FooterData = new FooterViewModel(); //employeeListViewModel.FooterData.CompanyName = "StepByStepSchools"; //employeeListViewModel.FooterData.Year = DateTime.Now.Year.ToString(); return(View("Index", employeeListViewModel)); }
public ActionResult SaveEmployee(CreateEmployeeViewModel e, string Btnsubmit) { if (Btnsubmit == "添 加") { if (ModelState.IsValid) { if (e.Password != e.rePassword) { ModelState.AddModelError("AddErr", "两次输入密码不一致"); return(View("CreateEmployee", new CreateEmployeeViewModel())); } EmployeeBusinessLayer empBal = new EmployeeBusinessLayer(); Employee emp = new Employee(); emp.Authentication = 0; emp.Password = e.Password; emp.UserID = e.UserID; emp.Name = e.UserID; Employee tmp = new Employee(); if ((tmp = empBal.SaveEmployee(emp)).UserID != null) { return(RedirectToAction("Index")); } else { ModelState.AddModelError("AddErr", tmp.Name); return(View("CreateEmployee", new CreateEmployeeViewModel())); } } else { CreateEmployeeViewModel ceVm = new CreateEmployeeViewModel(); return(View("CreateEmployee", ceVm)); } } else if (Btnsubmit == "Cancel") { return(RedirectToAction("Index")); } return(new EmptyResult()); }
public ActionResult Save(EmployeeViewModel e, string BtnSubmit) { switch (BtnSubmit) { case "Save Employee": if (ModelState.IsValid) { decimal salary = 0; decimal.TryParse(e.Salary, out salary); Task.Run(async() => { var empBal = new EmployeeBusinessLayer(); await empBal.Add(new Employee { Name = e.Name, Salary = salary }); }); return(RedirectToAction("Index")); } else { var evm = new EmployeeViewModel { //FooterData = new FooterViewModel() //{ // CompanyName = "Ryan's New Company", // Year = DateTime.Now.Year.ToString() //}, UserName = "******" }; return(RedirectToAction("Add", evm)); } default: return(RedirectToAction("Index")); } }
public List <EmployeeViewModel> GetEmployeeViewModelList() { List <EmployeeViewModel> empViewModels = new List <EmployeeViewModel>(); EmployeeBusinessLayer empBL = new EmployeeBusinessLayer(); List <Employee> EmployeeList = empBL.GetEmployee(); foreach (Employee employee in EmployeeList) { EmployeeViewModel evm = new EmployeeViewModel(); evm.EmployeeId = employee.EmployeeId; evm.EmployeeName = employee.FirstName + " " + employee.LastName; evm.SIN = employee.SIN; evm.EmployeeType = employee.EmployeeType; evm.EmployeeWorkingPeriod = employee.EmployeeStartDate + " -- " + employee.EmployeeEndDate; evm.EmployeePhone = employee.EmployeePhone; evm.EmployeeMobile = employee.EmployeeMobile; evm.EmployeeAddress = employee.EmployeeStreetNum + " " + employee.EmployeeStreetName + " " + employee.EmployeeProvince + " " + employee.EmployeePostCode; evm.EmployeeSalary = employee.EmployeeSalary; empViewModels.Add(evm); } return(empViewModels); }
public ActionResult Index() { EmployeeListViewModel employeeListViewModel = new EmployeeListViewModel(); employeeListViewModel.UserName = User.Identity.Name; EmployeeBusinessLayer empBal = new EmployeeBusinessLayer(); List <Employee> employees = empBal.GetEmployees(); List <EmployeeViewModel> employeeViewModels = new List <EmployeeViewModel>(); foreach (var v in employees) { EmployeeViewModel vmEmp = new EmployeeViewModel(); vmEmp.UserID = v.UserID; vmEmp.Password = v.Password; vmEmp.Name = v.Name; vmEmp.Authentication = v.Authentication; employeeViewModels.Add(vmEmp); } employeeListViewModel.Employees = employeeViewModels; return(View("Index", employeeListViewModel)); }
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")); }
public ActionResult DoLogin(UserDetails u) { if (ModelState.IsValid) { EmployeeBusinessLayer bal = new EmployeeBusinessLayer(); if (bal.IsValidUser(u)) { //false决定了是否创建永久有用的Cookie。临时Cookie会在浏览器关闭时自动删除,永久Cookie不会被删除。可通过浏览器设置或是编写代码手动删除。 FormsAuthentication.SetAuthCookie(u.UserName, false); return(RedirectToAction("Index", "Employee")); } else { ModelState.AddModelError("CredentialError", "Invalid Username or Password"); return(View("Login")); } } else { return(View("Login")); } }
public ActionResult SaveEmployee(Employee e, string BtnSubmit) { switch (BtnSubmit) { case "Save Employee": if (ModelState.IsValid) { var ebl = new EmployeeBusinessLayer(); ebl.SaveEmployee(e); return(RedirectToAction("Index")); } else { CreateEmployeeViewModel vm = new CreateEmployeeViewModel(); vm.FirstName = e.FirstName; vm.LastName = e.LastName; //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 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(RedirectToAction("Index")); }
public ActionResult Create_Post() { Employee employee = new Employee(); // Retrieve form data using form collection /* employee.Name = name; * employee.Gender = gender; * employee.City = city; * employee.DateOfBirth = dateOfBirth;*/ TryUpdateModel(employee); if (ModelState.IsValid) { EmployeeBusinessLayer employeeBusinessLayer = new EmployeeBusinessLayer(); employeeBusinessLayer.AddEmployee(employee); return(RedirectToAction("Index")); } return(View()); }
public ActionResult Edit_Post(int id) //public ActionResult Edit_Post([Bind(Include = "ID, Gender, City, DateOfBirth")] Employee employee) { EmployeeBusinessLayer employeeBusinessLayer = new EmployeeBusinessLayer(); Employee employee = employeeBusinessLayer.Employees.Single(x => x.ID == id); UpdateModel <IEmployee>(employee); //ini contoh include parameter //UpdateModel(employee,new string[] {"ID","Gender","City","DateOfBirth"}); //ini contoh exclude parameter //UpdateModel(employee, null, null, new string[] { "Name" }); if (ModelState.IsValid) { employeeBusinessLayer.SaveEmployee(employee); return(RedirectToAction("Index")); } return(View(employee)); }
public ActionResult SaveEmployee(Employee e, string BtnSubmit) { //处理参数名称与类属性不匹配的情况,使用Request类获取参数的值再赋值给类实例 /* * e.FirstName = Request.Form["FirstName"]; * * e.LastName = Request.Form["LastName"]; * * e.Salary = Convert.ToInt32(Request.Form["Salary"]); */ //MVC 的Model Binder: //无论请求是否由带参的action方法生成,Model Binder都会自动执行。 //Model Binder会通过方法的元参数迭代,然后会和接收到参数名称做对比。如果匹配,则响应接收的数据,并分配给参数。 //在Model Binder迭代完成之后,将类参数的每个属性名称与接收的数据做对比,如果匹配,则响应接收的数据,并分配给参数。 //请求信息包含在request对象中,比如:可以通过Request.Form["FirstName"]获取参数FirstName的值 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; vm.Salary = e.Salary.HasValue ? e.Salary.ToString() : ModelState["Salary"].Value.AttemptedValue; return(View("CreateEmployee", vm)); } case "Cancel": return(RedirectToAction("Index")); } return(new EmptyResult()); }
public ActionResult DoLogin(UserDetails userDetails) { if (ModelState.IsValid) { EmployeeBusinessLayer employeeBusinessLayer = new EmployeeBusinessLayer(); //if (employeeBusinessLayer.IsValidUser(userDetails)) //{ // FormsAuthentication.SetAuthCookie(userDetails.UserName, false); // return RedirectToAction("Index", "Employee"); //} //else //{ // ModelState.AddModelError("CredentialError", "用户名或密码错误^o^"); // return View("Login"); //} var userStates = employeeBusinessLayer.GetUserValidity(userDetails); var isAdmin = false; if (userStates == UserStatus.AuthenticatedAdmin) { isAdmin = true; } else if (userStates == UserStatus.AuthenticatedUser) { isAdmin = false; } else { ModelState.AddModelError("CredentialError", "用户名或密码错误^o^"); return(View("Login")); } FormsAuthentication.SetAuthCookie(userDetails.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, db); 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"].AttemptedValue; } //vm.FooterData = new FooterViewModel(); //vm.FooterData.CompanyName = "TTÜ"; //vm.FooterData.Year = DateTime.Now.Year.ToString(); //vm.UserName = User.Identity.Name; return(View("CreateEmployee", vm)); } case "Cancel": return(RedirectToAction("Index")); } return(new EmptyResult()); }
public ActionResult SaveEmployee(Employee e, string BtnSubmit) { switch (BtnSubmit) { case "Save Employee": { if (ModelState.IsValid) { EmployeeBusinessLayer empBLA = new EmployeeBusinessLayer(); empBLA.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; } return(View("CreateEmployee", vm)); //Day 4 Change - Passing a here } } break; case "Cancel": return(RedirectToAction("Index")); } return(new EmptyResult()); }
////public ActionResult Create(FormCollection formCollection) //public ActionResult Create(string name, string gender, string city, DateTime dateOfBirth) public ActionResult Create(Employee employee) { ////Employee employee = new Employee(); ////employee.Name = formCollection["Name"]; ////employee.Gender = formCollection["Gender"]; ////employee.City = formCollection["City"]; ////employee.DateOfBirth=Convert.ToDateTime(formCollection["DateOfBirth"]); //Employee employee = new Employee(); //employee.Name = name; //employee.Gender = gender; //employee.City = city; //employee.DateOfBirth = dateOfBirth; if (ModelState.IsValid) { EmployeeBusinessLayer employeeBusinessLayer = new EmployeeBusinessLayer(); employeeBusinessLayer.AddEmployee(employee); return(RedirectToAction("Index")); } return(View()); }
public ActionResult Index() { EmployeeBusinessLayer empBal = new EmployeeBusinessLayer(); List <Employee> employees = empBal.GetEmployees(); EmployeeListViewModel employeeListViewModel = new EmployeeListViewModel(); List <EmployeeViewModel> empViewModels = new List <EmployeeViewModel>(); foreach (Employee emp in employees) { EmployeeViewModel empViewModel = new EmployeeViewModel(); empViewModel.EmployeeId = emp.EmployeeId; empViewModel.EmployeeName = emp.FirstName + " " + emp.LastName; empViewModel.Salary = emp.Salary.Value.ToString("C"); empViewModel.SalaryColor = emp.Salary > 15000 ? "yellow" : "green"; empViewModels.Add(empViewModel); } employeeListViewModel.Employees = empViewModels; return(View("Index", employeeListViewModel)); }
// GET: Department public ActionResult GetDepartments() { EmployeeBusinessLayer ebl = new EmployeeBusinessLayer(); List <Departments> dept = new List <Departments>(); List <DepartmentVM> Departments = new List <DepartmentVM>(); DepartmentListVM deps = new DepartmentListVM(); dept = ebl.GetDepartments(); foreach (Departments dep in dept) { DepartmentVM dVM = new DepartmentVM(); dVM.DepartmentId = dep.DepartmentId; dVM.DepartmentName = dep.DepartmentName; dVM.Location = dep.Location; Departments.Add(dVM); } deps.DepartmentsList = Departments; // deps.UserName = "******"; return(View("Departments", deps)); }
public ActionResult Updatep(Employee e, string BtnSubmit) { switch (BtnSubmit) { case "更新": { if (ModelState.IsValid) { EmployeeBusinessLayer empBal = new EmployeeBusinessLayer(); empBal.Update(e); return(RedirectToAction("Index")); } else { return(View("Updatep")); } } case "取消": return(RedirectToAction("Index")); } return(new EmptyResult()); }
public ActionResult SaveEmployee(Employee em, string BtnSubmit) { switch (BtnSubmit) { case "Cancel": return(RedirectToAction("Index")); case "SaveEmployee": //if (!ModelState.IsValid) return View("CreateEmployee"); if (ModelState.IsValid) { EmployeeBusinessLayer emBO = new EmployeeBusinessLayer(); emBO.SaveEmployee(em); return(RedirectToAction("Index")); } else { CreateEmployeeViewModel vm = new CreateEmployeeViewModel(); vm.FirstName = em.FirstName; vm.LastName = em.LastName; if (em.Salary.HasValue) { vm.Salary = em.Salary.ToString(); } else { vm.Salary = ModelState["Salary"].Value.AttemptedValue; } return(View("CreateEmployee", vm)); } } return(new EmptyResult()); }
public ActionResult SaveEmployee(Employee e, string BtnSubmit) { switch (BtnSubmit) { case "Save Employee": if (ModelState.IsValid) { EmployeeBusinessLayer empbl = new EmployeeBusinessLayer(); empbl.SaveEmployee(e); return(RedirectToAction("Index")); } else { CreateEmployeeVM createEmpVM = new CreateEmployeeVM(); createEmpVM.FirstName = e.FirstName; createEmpVM.LastName = e.LastName; if (e.Salary > 0 || e.Salary.ToString() != null) { createEmpVM.Salary = Convert.ToString(e.Salary); } else { createEmpVM.Salary = ModelState["Salary"].Value.AttemptedValue; } createEmpVM.FooterData = new FooterVM(); createEmpVM.FooterData.CompanyName = "Sathish Tutorial Labs"; createEmpVM.FooterData.Year = "2016"; createEmpVM.FooterData.Terms = "All Rights Reserved!"; createEmpVM.UserName = HttpContext.User.Identity.Name; return(View("CreateEmployee", createEmpVM)); } case "Cancel": return(RedirectToAction("Index")); } return(new EmptyResult()); }
public ActionResult SaveEmployee(Employee e, string BtnSubmit) { switch (BtnSubmit) { case "Save Employee": if (ModelState.IsValid) { EmployeeBusinessLayer ebl = new EmployeeBusinessLayer(); ebl.SaveEmployee(e); return(RedirectToAction("Index")); } else { CreateEmployeeViewModel cevm = new CreateEmployeeViewModel(); cevm.FirstName = e.FirstName; cevm.LastName = e.LastName; if (e.Salary != 0) { cevm.Salary = e.Salary.ToString(); } else { cevm.Salary = ModelState["Salary"].Value.AttemptedValue; } return(View("CreateEmployee", cevm)); } break; case "Cancel": return(RedirectToAction("Index")); break; } return(new EmptyResult()); }
public async Task <ActionResult> Upload(FileUploadViewModel file) { List <Employee> employees = await Task.Factory.StartNew <List <Employee> >(() => GetEmployeesFromFile(file)); EmployeeBusinessLayer bl = new EmployeeBusinessLayer(); bl.UploadEmployees(employees); EmployeeListViewModel vm = new EmployeeListViewModel(); vm.Employees = new List <EmployeeViewModel>(); foreach (var item in employees) { EmployeeViewModel v = new EmployeeViewModel(); v.EmployeeName = string.Concat(item.FirstName + " " + item.LastName); v.Salary = item.Salary.Value.ToString("C"); v.SalaryColor = item.Salary > 15000 ? "yellow" : "green"; vm.Employees.Add(v); } return(Json(vm)); }
public ActionResult SaveEmployee(Employee e, string BtnSubmit) { CreateEmployeeViewModel employeeListViewModel = new CreateEmployeeViewModel(); //employeeListViewModel.UserName = "******"; //employeeListViewModel.footerViewModel = new FooterViewModel(); //employeeListViewModel.footerViewModel.CompanyName = "tombola";//Can be set to dynamic value //employeeListViewModel.footerViewModel.Year = DateTime.Now.Year.ToString(); if (!ModelState.IsValid) { employeeListViewModel.firstName = e.firstName; employeeListViewModel.lastName = e.lastName; employeeListViewModel.salary = e.salary.ToString(); return View("CreateEmployee-Copy", employeeListViewModel); // Day 4 Change - Passing e here // return View("CreateEmployee-Copy", e); } EmployeeBusinessLayer empBal = new EmployeeBusinessLayer(); empBal.SaveEmployee(e); return RedirectToAction("gridView"); }