public ActionResult SaveEmployee(Employee3 e, string BtnSubmit) { switch (BtnSubmit) { case "Save Employee": this.Validate(e); if (ModelState.IsValid) { // return RedirectToAction("Index"); using (var dc = new NDBContext()) { dc.Save(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 e here } //return Content(e.FirstName + "|" + e.LastName + "|" + e.Salary); return RedirectToAction("Index"); case "Cancel": return RedirectToAction("Index"); } return new HttpStatusCodeResult(HttpStatusCode.NotFound); return new EmptyResult(); }
public ActionResult Index() { // List<Employee> employess = new List<Employee>(); //Employee emp = new Employee(); //emp.FirstName = "Sukesh"; //emp.LastName = "Marla"; //emp.Salary = 20000; //employess.Add(emp); //emp = new Employee(); //emp.FirstName = "Gary"; //emp.LastName = "Harpaz"; //emp.Salary = 12000; //employess.Add(emp); //emp = new Employee(); //emp.FirstName = "Suzy"; //emp.LastName = "Bracha"; //emp.Salary = 10000; //employess.Add(emp); List<Employee3> employess = new List<Employee3>(); using (var dc = new NDBContext()) { employess = dc.Employees.ToList(); } var employessvm = new EmployeesViewModel(); employessvm.Employees = employess.Select(e => new EmployeeViewModel(e)).ToList(); employessvm.UserName = "******"; return View("Index", employessvm); }