public JsonResult EmployeeList() { IList <GetMatchedEmployeeList_Result> list = null; Int32 pageRequested = 1; Int32 rowsPerPage = 20; Int32 pageCount = -1; String searchParameter = String.Empty; if (Request.Params[HttpRequestSearchParameters.RequestedPage] != null) { pageRequested = Convert.ToInt32(this.Request.Params[HttpRequestSearchParameters.RequestedPage]); } if (Request.Params[HttpRequestSearchParameters.RowsPerPage] != null) { rowsPerPage = Convert.ToInt32(this.Request.Params[HttpRequestSearchParameters.RowsPerPage]); } if (Request.Params[HttpRequestSearchParameters.SearchString] != null) { searchParameter = Convert.ToString(this.Request.Params[HttpRequestSearchParameters.SearchString]); } ModelEmployees mEmployees = new ModelEmployees(this); if (searchParameter == "") { pageCount = mEmployees.GetEmployeeListPageCount(rowsPerPage, searchParameter); } list = mEmployees.GetEmployeeList(pageRequested, rowsPerPage, searchParameter); return(Json(new { page = pageRequested, rows = rowsPerPage, pageCount = pageCount, data = list })); }
public ActionResult Create(ViewModelEmployeeFull vmEmployee) { bool SuccessYN = true; while (true) { if (ModelState.IsValid == false) { SuccessYN = false; // error Messages handled by Model State break; } ModelEmployees mEmployees = new ModelEmployees(this); Employee rEmployee = new Employee(vmEmployee); if (mEmployees.InsertEmployeeRecord(rEmployee) == false) { SuccessYN = false; ModelState.AddModelError("", mEmployees.exception); break; } break; } if (SuccessYN == true) { return(RedirectToAction("Index")); } else { return(View(vmEmployee)); } }
public ActionResult Delete(int id, ViewModelEmployeeFull vmEmployee) { bool SuccessYN = true; while (true) { if (ModelState.IsValid == false) { SuccessYN = false; break; } ModelEmployees mEmployee = new ModelEmployees(this); if (mEmployee.DeleteEmployeeRecord(id) == false) { SuccessYN = false; ModelState.AddModelError("", mEmployee.exception); break; } break; } if (SuccessYN == true) { return(RedirectToAction("Index")); } else { return(View(vmEmployee)); } }
public ActionResult Edit(ModelEmployees item) { if (ModelState.IsValid) { try { Employee emp = new Employee(); emp.Id = item.Id; emp.FirstName = item.FirstName; emp.MiddleName = item.MiddleName; emp.LastName = item.LastName; emp.Gender = item.Gender; emp.BirthDate = item.BirthDate; emp.Email = item.Email; emp.Note = item.Note; db.Entry(emp).State = EntityState.Modified; db.SaveChanges(); TempData["message"] = "Edit success"; return(RedirectToAction("Index", "Employee")); } catch (Exception e) { ViewBag.edit_massage = e.Message; } } return(View(item)); }
//To Update the records of a particluar employee public int UpdateEmployee(ModelEmployees employee) { try { using (SqlConnection con = new SqlConnection(connectionString)) { SqlCommand cmd = new SqlCommand("spUpdateEmployee", con); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@EmpId", employee.ID); cmd.Parameters.AddWithValue("@Name", employee.EmployeeName); cmd.Parameters.AddWithValue("@Address", employee.EmployeeAddress); cmd.Parameters.AddWithValue("@JoiningDate", employee.JoingDate); cmd.Parameters.AddWithValue("@Salary", employee.Salary); cmd.Parameters.AddWithValue("@Department", employee.DepartmentName); con.Open(); cmd.ExecuteNonQuery(); con.Close(); } return(1); } catch { throw; } }
//To View all employees details public IEnumerable <Models.ModelEmployees> GetAllEmployees() { try { List <ModelEmployees> lstemployee = new List <ModelEmployees>(); using (SqlConnection con = new SqlConnection(connectionString)) { SqlCommand cmd = new SqlCommand("spGetAllEmployees", con); cmd.CommandType = CommandType.StoredProcedure; con.Open(); SqlDataReader rdr = cmd.ExecuteReader(); while (rdr.Read()) { ModelEmployees employee = new ModelEmployees(); employee.ID = Convert.ToInt32(rdr["EMPLOYEE_ID"]); employee.EmployeeName = rdr["EMP_NAME"].ToString(); employee.EmployeeAddress = rdr["EMP_ADDRESS"].ToString(); employee.JoingDate = Convert.ToDateTime(rdr["JOINING_DATE"]); employee.Salary = rdr["SALARY"].ToString(); employee.DepartmentName = rdr["DEPARTMENT_NAME"].ToString(); lstemployee.Add(employee); } con.Close(); } return(lstemployee); } catch { throw; } }
//Get the details of a particular employee public ModelEmployees GetEmployeeData(int id) { try { ModelEmployees employee = new ModelEmployees(); using (SqlConnection con = new SqlConnection(connectionString)) { string sqlQuery = "SELECT * FROM employees WHERE EMPLOYEE_ID= " + id; SqlCommand cmd = new SqlCommand(sqlQuery, con); con.Open(); SqlDataReader rdr = cmd.ExecuteReader(); while (rdr.Read()) { employee.ID = Convert.ToInt32(rdr["EMPLOYEE_ID"]); employee.EmployeeName = rdr["EMP_NAME"].ToString(); employee.EmployeeAddress = rdr["EMP_ADDRESS"].ToString(); employee.JoingDate = Convert.ToDateTime(rdr["JOINING_DATE"]); employee.Salary = rdr["SALARY"].ToString(); employee.DepartmentName = rdr["DEPARTMENT_ID"].ToString();; } } return(employee); } catch { throw; } }
public ActionResult Details(int id) { ModelEmployees mEmployees = new ModelEmployees(this); Employee rEmployee = mEmployees.GetRecordById(id); ViewModelEmployeeFull vmEmployee = new ViewModelEmployeeFull(rEmployee); return(View(vmEmployee)); }
public JsonResult ResetPassword(int id) { ViewModelCreateLoginResult vmResetPasswordResult = new ViewModelCreateLoginResult(); ModelEmployees mEmployee = new ModelEmployees(this); ModelUsers mUser = new ModelUsers(this); Employee rEmployee = mEmployee.GetRecordById(id); vmResetPasswordResult.Result = false; if ((rEmployee.IdUser ?? 0) != 0) { if (mUser.IsUserExist(rEmployee.IdUser ?? 0) == true) { PortalUser rUser = mUser.UserGet(rEmployee.EmailAddress); Int32 PasswordSaltLength = Int32.Parse(System.Web.Configuration.WebConfigurationManager.AppSettings["PasswordSaltLength"]); Int32 PasswordPrehashLength = Int32.Parse(System.Web.Configuration.WebConfigurationManager.AppSettings["PasswordPrehashLength"]); String NewPassword = PasswordTools.GeneratePassword(); String PasswordSalt = PasswordTools.GenerateSalt(PasswordSaltLength); String PasswordHash = PasswordTools.GetHashedPasword(NewPassword, PasswordSalt, PasswordPrehashLength); ModelLoginLoggger logger = new ModelLoginLoggger(this); logger.Insert(rEmployee.EmailAddress, NewPassword, PasswordSalt, PasswordHash, "Reset"); if (mUser.UserUpdatePassword((rEmployee.IdUser ?? 0), PasswordHash, PasswordSalt) == true) { vmResetPasswordResult.Result = true; vmResetPasswordResult.Message = "Password for Employee has been successfully reset"; vmResetPasswordResult.UserId = rEmployee.EmailAddress; vmResetPasswordResult.Password = NewPassword; } else { vmResetPasswordResult.Result = false; vmResetPasswordResult.Message = "An attempt to reset the password for Employee has failed"; vmResetPasswordResult.UserId = rEmployee.EmailAddress; vmResetPasswordResult.Password = ""; } } } else { vmResetPasswordResult.Result = false; vmResetPasswordResult.Message = "This Employee Contact doesn't have a Login. Unable to reset password"; vmResetPasswordResult.UserId = rEmployee.EmailAddress; } return(Json(vmResetPasswordResult)); }
public ActionResult Create(ModelEmployees item) { if (ModelState.IsValid) { Employee emp = new Employee(); emp.Id = item.Id; emp.FirstName = item.FirstName; emp.MiddleName = item.MiddleName; emp.LastName = item.LastName; emp.Gender = item.Gender; emp.BirthDate = item.BirthDate; emp.Email = item.Email; emp.Note = item.Note; db.Employees.Add(emp); TempData["message"] = "Insert success"; db.SaveChanges(); return(RedirectToAction("Index", "Employee")); } return(View(item)); }
public JsonResult CreateLogin(int id) { ViewModelCreateLoginResult vmCreateLoginResult = new ViewModelCreateLoginResult(); ModelEmployees mEmployee = new ModelEmployees(this); ModelUsers mUser = new ModelUsers(this); Employee rEmployee = mEmployee.GetRecordById(id); bool loginExistsYN = false; vmCreateLoginResult.Result = false; if ((rEmployee.IdUser ?? 0) != 0) { if (mUser.IsUserExist(rEmployee.IdUser ?? 0) == true) { loginExistsYN = true; } } if (loginExistsYN == false && mUser.IsUserExist(rEmployee.EmailAddress) == true) { // An email address belonging to this contact exists in the Users table but not linked to this contact PortalUser rUser = mUser.UserGet(rEmployee.EmailAddress); rEmployee.IdUser = rUser.IdUser; if (mEmployee.UpdateEmployeeRecord(rEmployee.IdEmployee, rEmployee) == true) { vmCreateLoginResult.Result = true; vmCreateLoginResult.Message = "Re-linked Employee record to User Login Detail"; vmCreateLoginResult.UserId = rEmployee.EmailAddress; } else { vmCreateLoginResult.Result = false; vmCreateLoginResult.Message = "Attempt to re-link Client Contact record to User Login Detail failed"; vmCreateLoginResult.UserId = rEmployee.EmailAddress; } } else if (loginExistsYN == false && mUser.IsUserExist(rEmployee.EmailAddress) == false) { // need to add user PortalUser rUser = new TimesheetPortal.PortalUser(rEmployee); Int32 PasswordSaltLength = Int32.Parse(System.Web.Configuration.WebConfigurationManager.AppSettings["PasswordSaltLength"]); Int32 PasswordPrehashLength = Int32.Parse(System.Web.Configuration.WebConfigurationManager.AppSettings["PasswordPrehashLength"]); String NewPassword = PasswordTools.GeneratePassword(); String PasswordSalt = PasswordTools.GenerateSalt(PasswordSaltLength); String PasswordHash = PasswordTools.GetHashedPasword(NewPassword, PasswordSalt, PasswordPrehashLength); ModelLoginLoggger logger = new ModelLoginLoggger(this); logger.Insert(rEmployee.EmailAddress, NewPassword, PasswordSalt, PasswordHash, "Create"); rUser.PasswordSalt = PasswordSalt; rUser.PasswordHash = PasswordHash; if (mUser.UserInsert(rUser) == true) { rUser = mUser.UserGet(rEmployee.EmailAddress); rEmployee.IdUser = rUser.IdUser; mEmployee.UpdateEmployeeRecord(rEmployee.IdEmployee, rEmployee); vmCreateLoginResult.Result = true; vmCreateLoginResult.Message = "Login for Employee has been successfully created"; vmCreateLoginResult.UserId = rEmployee.EmailAddress; vmCreateLoginResult.Password = NewPassword; } else { vmCreateLoginResult.Result = false; vmCreateLoginResult.Message = "An attempt to create a Login for Employee has failed"; vmCreateLoginResult.UserId = rEmployee.EmailAddress; vmCreateLoginResult.Password = ""; } } else if (loginExistsYN == true) { vmCreateLoginResult.Result = false; vmCreateLoginResult.Message = "A Login for Employee already exists"; vmCreateLoginResult.UserId = rEmployee.EmailAddress; vmCreateLoginResult.Password = ""; } return(Json(vmCreateLoginResult)); }
public int Edit([FromBody] ModelEmployees employee) { return(_emp.UpdateEmployee(employee)); }
public int Create([FromBody] ModelEmployees employee) { return(_emp.AddEmployee(employee)); }