public ActionResult Create(FormCollection formCollection) { Employee employee = new Employee(); employee.FirstName = formCollection["FirstName"]; employee.LastName = formCollection["LastName"]; employee.Age = Convert.ToByte(formCollection["Age"]); EmployeeBAL emp = new EmployeeBAL(); int NewId = emp.Add(employee); return(RedirectToAction("Details", "Employee", new { id = NewId })); }
public ActionResult Create(EmployeeVM viewModel) { try { // TODO: Add insert logic here if (ModelState.IsValid) { Entities.Employee entity = new Entities.Employee(); entity.EmployeeId = viewModel.EmployeeId; entity.EmployeeCode = viewModel.EmployeeCode.Trim(); entity.Password = viewModel.Password.Trim(); entity.FirstName = viewModel.FirstName.Trim(); entity.MiddleName = viewModel.MiddleName.Trim(); entity.LastName = viewModel.LastName.Trim(); entity.Category = viewModel.Category.Trim(); entity.Address = viewModel.Address.Trim(); entity.ContactNo = viewModel.ContactNo.Trim(); entity.DOB = viewModel.DOB; entity.JoiningDate = viewModel.JoiningDate; EmployeeBAL balObject = new EmployeeBAL(); balObject.Add(entity, SessionHelper.SchoolId); TempData["Message"] = "Employee added successfully !!!"; } else { TempData["Error"] = "Some problem while adding Employee !!!"; } } catch { TempData["Error"] = "Some problem while adding Employee !!!"; } return(View(viewModel)); }