public Employee SaveEmployee(Employee e) { SalesERPDAL salesDal = new SalesERPDAL(); salesDal.Employees.Add(e); salesDal.SaveChanges(); return e; }
private List<Employee> GetEmployees(FileUploadViewModel model) { List<Employee> employees = new List<Employee>(); StreamReader csvreader = new StreamReader(model.fileUpload.InputStream); csvreader.ReadLine();// Assuming first line is header while (!csvreader.EndOfStream) { var line = csvreader.ReadLine(); var values = line.Split(',');//Values are comma separated Employee e = new Employee(); e.FirstName = values[0]; e.LastName = values[1]; e.Salary = int.Parse(values[2]); employees.Add(e); } return employees; }
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.Value.ToString("C"); if (emp.Salary > 15000) { empViewModel.SalaryColor = "yellow"; } else { empViewModel.SalaryColor = "green"; } return Json(empViewModel); }
//----------3.1---------- //public ActionResult SaveEmployee() //{ // Employee e = new Employee(); // e.FirstName = Request.Form["FName"]; // e.LastName = Request.Form["LName"]; // e.Salary = int.Parse(Request.Form["Salary"]); // return Content(e.FirstName + "|" + e.LastName + "|" + e.Salary); //} //----------3.2---------- //public ActionResult SaveEmployee(string FName, string LName, int Salary) //{ // Employee e = new Employee(); // e.FirstName = FName; // e.LastName = LName; // e.Salary = Salary; // return Content(e.FirstName + "|" + e.LastName + "|" + e.Salary); //} //----------3.3---------- //public ActionResult SaveEmployee([ModelBinder(typeof(MyEmployeeModelBinder))]Employee e, string BtnSubmit) //{ // switch (BtnSubmit) // { // case "Save Employee": // return Content(e.FirstName + "|" + e.LastName + "|" + e.Salary); // case "Cancel": // return RedirectToAction("Index", "Employee"); // } // return new EmptyResult(); //} //public ActionResult SaveEmployee() //{ // Employee e = new Employee(); // UpdateModel<Employee>(e); //} public ActionResult CancelSave(Employee e) { return RedirectToAction("Index", "Employee"); }
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; } return View("CreateEmployee", vm); } case "Cancel": return RedirectToAction("Index", "Employee"); } return new EmptyResult(); }