public IActionResult Edit(EmployeeModels model) { if (model.Id != 0) { EmployeeRepository employeeRepo = new EmployeeRepository(); Employee employee = employeeRepo.GetEmployeeById(model.Id); if (employee != null) { employee.DepartmentId = model.DepartmentId; employee.Email = model.Email; employee.Name = model.Name; employee.Nik = model.NIK; employee.Phone = model.Phone; employee.PositionId = model.PositionId; employee.SubdepartmentId = model.SubDepartmentId; employee.Updatedate = DateTime.Now; employeeRepo.UpdateEmployee(); return(RedirectToAction("Manage", "Employee")); } else { return(View(model)); } } else { return(View(model)); } }
public JsonResult GetEmployee(DTParameters param) { EmployeeViewStore employee = new EmployeeViewStore(); employee.PageIndex = param.Start / param.Length + 1; employee.PageSize = param.Length; if (param.Search.Value == null) { employee.Search = "%%"; } else { employee.Search = "%" + param.Search.Value + "%"; } employee.Order = param.SortOrder; EmployeeViewStore categories = new EmployeeModels().GetEmployeeByPage(employee.Search, employee.Order, employee.PageIndex, employee.PageSize); DTResult <EmployeeDTO> final = new DTResult <EmployeeDTO>() { draw = param.Draw, data = categories.Employee.ToList(), recordsFiltered = categories.RecordCount, recordsTotal = categories.Employee.Count }; return(Json(final)); }
public ActionResult List(string searchText) { // string searchText = form["txtSearch"]; List <vw_Employees> empl = new List <vw_Employees>(); if (Session["ClientId"] != null) { if (Roles.IsUserInRole("CenterManager") && Session["BranchId"] != null) { empl = EmployeeModels.GetEmployeesList(searchText, (int)Session["ClientId"], (int)Session["BranchId"]); } else { empl = EmployeeModels.GetEmployeesList(searchText, (int)Session["ClientId"], null); } } else { if (Roles.IsUserInRole("SuperAdmin")) { empl = EmployeeModels.GetEmployeesList(); } } if (Request.IsAjaxRequest()) { return(PartialView("EmployeeListUserControl", empl)); } return(View()); }
public PartialViewResult Edit(string id) { EmployeeModels model = GetDetail(id); model.ConfirmPassword = model.Password; return(PartialView("_Edit", model)); }
public IActionResult Profile(int Id) { string ESMJson = HttpContext.Session.GetString("ESM"); EmployeeSessionModel ESM = new EmployeeSessionModel(); EmployeeRepository employeeRepo = new EmployeeRepository(); if (!string.IsNullOrEmpty(ESMJson)) { ESM = JsonConvert.DeserializeObject <EmployeeSessionModel>(ESMJson); Employee employee = employeeRepo.GetEmployeeById(Convert.ToInt32(ESM.EmployeeId)); EmployeeModels eModel = new EmployeeModels(); eModel.active = true; eModel.Department = employee.Department.Name; eModel.DepartmentId = (int)employee.DepartmentId; eModel.Email = employee.Email; eModel.Id = employee.Id; eModel.Name = ESM.Name; eModel.NIK = ESM.NIK; eModel.Phone = employee.Phone; eModel.Position = ESM.Position; eModel.PositionId = Convert.ToInt32(ESM.PositionId); eModel.Subdepartment = ESM.SubDepartment; eModel.SubDepartmentId = Convert.ToInt32(ESM.SubDeparmentId); return(View(eModel)); } else { return(View(new EmployeeModels())); } }
public IHttpActionResult AddEmployee([FromBody] EmployeeModels.Add employee) { string logForm = "Form : " + Startup._jsSerializer.Serialize(employee); string logAPI = "[Post] " + Request.RequestUri.ToString(); if (!ModelState.IsValid || employee == null) { Startup._sfAppLogger.Warn(logAPI + " || Input Parameter not expected || " + logForm); return(BadRequest("Invalid data")); } try { EmployeeModels employeeModel = new EmployeeModels(); int employeeId = employeeModel.addEmployee(employee); return(Json(new { id = employeeId })); } catch (Exception ex) { StringBuilder logMessage = LogUtility.BuildExceptionMessage(ex); logMessage.AppendLine(logForm); Startup._sfAppLogger.Error(logAPI + logMessage); return(InternalServerError(ex)); } }
// GET: Employee/Details/5 public ActionResult Details(int?id) { EmployeeModels employee = db.EmployeeModels.Find(id); return(View(employee)); }
public string EditEmployee(EmployeeModels emp) { if (ModelState.IsValid) { if (emp != null) { var empStatus = db.EmployeeTables.Where(a => a.EmpID == emp.empID); if (empStatus != null) { EmployeeTable employee = db.EmployeeTables.Where(a => a.EmpID == emp.empID).FirstOrDefault(); employee.EmpID = emp.empID; employee.EmpName = emp.employeeName; employee.EmpAddress = emp.employeeAddress; employee.EmpDesignation = emp.employeeDesignation; employee.CreatedBy = emp.createdBy; db.SaveChanges(); return("Successfull"); } else { return("No record found"); } } else { return("error while updating employee"); } } else { return("Please insert data in correct format"); } }
public IHttpActionResult EditEmployeeById(int id, [FromBody] EmployeeModels.Update employee) { JavaScriptSerializer js = new JavaScriptSerializer(); string logForm = "Form : " + js.Serialize(employee); string logAPI = "[Put] " + Request.RequestUri.ToString(); if (!ModelState.IsValid || employee == null) { Startup._sfAppLogger.Warn(logAPI + " || Input Parameter not expected || " + logForm); return(BadRequest("Invalid data")); } try { EmployeeModels employeeModel = new EmployeeModels(); employeeModel.updateEmployee(id, employee); RedisCacheHelper.DeleteEmployeeCache(id); return(Ok("Success")); } catch (Exception ex) { StringBuilder logMessage = LogUtility.BuildExceptionMessage(ex); logMessage.AppendLine(logForm); Startup._sfAppLogger.Error(logAPI + logMessage); return(InternalServerError(ex)); } }
public void updateEmpData(EmployeeModels Model) { try { string strConn = ConfigurationManager.ConnectionStrings["NorthwndConnection"].ToString(); using (SqlConnection conn = new SqlConnection(strConn)) { string Sql = @"UPDATE Employees SET [LastName] = @LastName ,[FirstName] = @FirstName ,[BirthDate] = @BirthDate ,[Address] = @Address WHERE EmployeeID = @EmployeeID"; using (SqlCommand cmd = new SqlCommand(Sql, conn)) { conn.Open(); cmd.Parameters.Add("EmployeeID", SqlDbType.Int, 4).Value = Model.EmployeeID; cmd.Parameters.Add("LastName", SqlDbType.NVarChar, 40).Value = Model.LastName; cmd.Parameters.Add("FirstName", SqlDbType.NVarChar, 20).Value = Model.FirstName; cmd.Parameters.Add("BirthDate", SqlDbType.DateTime).Value = Model.BirthDate == null ? (object)DBNull.Value : Convert.ToDateTime(Model.BirthDate).ToString("yyyy-MM-dd"); cmd.Parameters.Add("Address", SqlDbType.NVarChar, 120).Value = Model.Address; cmd.ExecuteNonQuery(); } } } catch (Exception ex) { //單筆入檔,就不放Transaction了 //Write Log.. throw ex; } }
public string AddEmployee(EmployeeModels emp) { if (ModelState.IsValid) { if (emp != null) { var emptable = new EmployeeTable { EmpName = emp.employeeName, EmpDesignation = emp.employeeDesignation, EmpAddress = emp.employeeAddress, CreatedBy = emp.createdBy, DepartmentID = emp.deptID, }; db.EmployeeTables.Add(emptable); db.SaveChanges(); return("Successfull"); } else { return("error while adding employee"); } } else { return("Please insert data in correct format"); } }
public void InsertEmpData(EmployeeModels Model) { try { string strConn = ConfigurationManager.ConnectionStrings["NorthwndConnection"].ToString(); using (SqlConnection conn = new SqlConnection(strConn)) { string Sql = @"Insert into Employees (LastName, FirstName, BirthDate, Address) values( @LastName, @FirstName, @BirthDate, @Address)"; using (SqlCommand cmd = new SqlCommand(Sql, conn)) { conn.Open(); cmd.Parameters.Add("LastName", SqlDbType.NVarChar, 40).Value = Model.LastName; cmd.Parameters.Add("FirstName", SqlDbType.NVarChar, 20).Value = Model.FirstName; cmd.Parameters.Add("BirthDate", SqlDbType.DateTime).Value = Model.BirthDate == null ? (object)DBNull.Value : Convert.ToDateTime(Model.BirthDate).ToString("yyyy-MM-dd"); cmd.Parameters.Add("Address", SqlDbType.NVarChar, 120).Value = Model.Address; cmd.ExecuteNonQuery(); } } } catch (Exception ex) { //單筆入檔,就不放Transaction了 //Write Log.. throw ex; } }
public static List <EmployeeModels> GetAll() { SqlConnection con = new SqlConnection(connection); SqlCommand cmd = new SqlCommand("usp_Employee_GetAll", con); cmd.CommandType = CommandType.StoredProcedure; //cmd.CommandText = "usp_Employee_GetAll"; //cmd.Connection = con; cmd.Connection.Open(); SqlDataReader reader = cmd.ExecuteReader(); List <EmployeeModels> empList = new List <EmployeeModels>(); while (reader.Read()) { EmployeeModels model = new EmployeeModels(); model.EmpoyeeName = DBNull.Value != reader["EmpoyeeName"] ? (string)reader["EmpoyeeName"] : default(string); model.Salary = DBNull.Value != reader["Salary"] ? (double)reader["Salary"] : default(double); model.DepartmentId = DBNull.Value != reader["DepartmentId"] ? (int)reader["DepartmentId"] : default(int); model.RowStatus = DBNull.Value != reader["RowStatus"] ? (int)reader["RowStatus"] : default(int); model.DepartmentName = DBNull.Value != reader["DepartmentName"]?(string)reader["DepartmentName"] :default(string); empList.Add(model); } reader.Close(); con.Close(); return(empList); }
public ActionResult Edit(string id) { ViewData["EmployeeRanks"] = Utilities.GetEmployeeRankNameList(); if (Session["ClientId"] != null) { ViewData["Branchs"] = Utilities.GetBranchNameList((int)Session["ClientId"]); ViewData["Zones"] = Utilities.GetZoneNameList((int)Session["ClientId"]); if (Session["ZoneId"] != null) { ViewData["Regions"] = Utilities.GetRegionNameList((int)Session["ClientId"], (int)Session["ZoneId"]); } else { ViewData["Regions"] = Utilities.GetRegionNameList((int)Session["ClientId"], null); } ViewData.Model = EmployeeModels.GetEmployeeById(id); } else { if (Roles.IsUserInRole("SuperAdmin")) { return(RedirectToAction("List", "Client")); } } ViewData["Genders"] = Utilities.GetGenderNameList(); ViewData["MaritalStstus"] = Utilities.GetMaritalStatusList(); ViewData["Qualifications"] = Utilities.GetQualificationList(); ViewData["States"] = Utilities.GetStateList(Utilities.IndiaCountryCode); ViewData["Countries"] = Utilities.GetCountryList(); return(View()); }
public ActionResult Add() { try { var objPosition = employeeRepository.GetPosition(); EmployeeAdd employeeAdd = new EmployeeAdd(); var savePath = Server.MapPath("~/Uploads/"); var fileName = "default.jpg"; employeeAdd.ImageStream = ImageHelper.BaseDateImage(savePath + "/" + fileName); var strValue = "1990-01-01"; DateTime objDate; DateTime.TryParse(strValue, out objDate); employeeAdd.Dob = objDate; employeeModel = new EmployeeModels { employeeAdd = employeeAdd, checkPost = false, positions = objPosition }; } catch (Exception ex) { log.Error(ex); ModelState.AddModelError(string.Empty, Translator.UnexpectedError); } return(View(employeeModel)); }
public JsonResult GetEmployeeByID(int id) { EmployeeDTO employee = new EmployeeModels().GetEmployeeById(id); return(Json(new { employee.Address, employee.BirthDate, employee.City, employee.Country, employee.EmployeeID, employee.Extension, employee.FirstName, employee.HireDate, employee.HomePhone, employee.LastName, employee.Notes, employee.Photo, employee.PhotoPath, employee.PostalCode, employee.Region, employee.ReportsTo, employee.Title, employee.TitleOfCourtesy }, JsonRequestBehavior.AllowGet)); }
public bool UpdateEmployee(EmployeeModels model, ref string msg) { bool result = true; using (DataContext cxt = new DataContext()) { var _isExits = cxt.dbEmployee.Any(x => x.Email.Equals(model.Email) && x.IsActive && !x.ID.Equals(model.ID)); if (_isExits) { result = false; msg = "Địa chỉ email đã tồn tại"; } else { using (var transaction = cxt.Database.BeginTransaction()) { try { var itemUpdate = cxt.dbEmployee.Where(x => x.ID == model.ID).FirstOrDefault(); if (itemUpdate != null) { itemUpdate.FirstName = model.FirstName; itemUpdate.LastName = model.LastName; itemUpdate.Name = model.Name; itemUpdate.Phone = model.Phone; itemUpdate.Email = model.Email; itemUpdate.Password = model.Password; itemUpdate.Country = model.Country; itemUpdate.BirthDate = model.BirthDate; itemUpdate.Address = model.Address; itemUpdate.Gender = model.Gender; itemUpdate.MaritalStatus = model.MaritalStatus; itemUpdate.IsActive = model.IsActive; itemUpdate.IsSupperAdmin = model.IsSupperAdmin; itemUpdate.ModifiedDate = DateTime.Now; itemUpdate.ModifiedUser = model.CreatedUser; cxt.SaveChanges(); transaction.Commit(); } } catch (Exception ex) { NSLog.Logger.Error("Không thể cập nhập cho nhân viên này. Làm ơn kiểm tra lại!", ex); result = false; msg = "Không thể cập nhập cho nhân viên này. Làm ơn kiểm tra lại!"; transaction.Rollback(); } finally { if (cxt != null) { cxt.Dispose(); } } } } } return(result); }
public ActionResult DeleteConfirmed(int id) { EmployeeModels employeeModels = db.Employee.Find(id); db.Employee.Remove(employeeModels); db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult Test() { List <EmployeeModels> empList = TempData.Peek("Value") as List <EmployeeModels>; EmployeeModels em = new EmployeeModels(); empList.Add(em); return(View("Index", empList)); }
public ActionResult Edit(EmployeeModels model) { if (ModelState.IsValid) { repository.UpdateEmployee(model.Id, model); return(RedirectToAction("GelAllRecords")); } return(View()); }
public ActionResult DeleteConfirmed(int id) { EmployeeModels employeeModels = db.EmployeeModels.Find(id); // Don't actually delete - the record needs to be maintained for required record retention employeeModels.NotActive = true; db.SaveChanges(); return(RedirectToAction("Index")); }
public IActionResult addEmp() { EmployeeModels emp = new EmployeeModels(); emp.insertEmp(); string str = emp.turnId; return(RedirectToAction("emp", new { ID = str })); }
public ActionResult Add(MyClinic.Infrastructure.EmployeeAdd objFrm) { bool checkError = true; try { if (ModelState.IsValid) { Employee employee = new Employee(); Dictionary <string, string> dictItem = TransactionHelper.processGenerateArray(employee); employee = TransactionHelper.TransDict <Employee>(dictItem, employee); var objSession = Session["user"] as MyClinic.Infrastructure.SessUser; employee.Image = employee.Id + "jpg"; employee.Status = 1; employeeRepository.Add(employee); var fileName = employee.Id + ".jpg"; var savePath = Server.MapPath("~/Uploads/employee/") + employee.Id; ImageHelper.SaveImage(savePath, employee.Id + ".jpg", objFrm.ImageStream); Employee newEmployee = Utilities.ObjectCopier.Copy <Employee>(employee); newEmployee.Image = employee.Id + ".jpg"; employeeRepository.UpdateFieldChangedOnly(employee, newEmployee); /*For Add New Record to LogTable*/ int userId = objSession.UserId; logTran.UserId = userId; logTran.ProcessType = "Add Employee"; logTran.Description = "Add Employee Name : " + employee.Name; logTran.LogDate = DateTime.Now; logRepository.Add(logTran); checkError = false; } } catch (Exception ex) { log.Error(ex); ModelState.AddModelError(string.Empty, Translator.UnexpectedError); } if (checkError == true) { var objPosition = employeeRepository.GetPosition(); //objFrm.Dob = objFrm.DateOfBirth; employeeModel = new EmployeeModels { employeeAdd = objFrm, checkPost = true, positions = objPosition }; return(View(employeeModel)); } else { return(RedirectToAction("Index", "Employee")); } }
public ActionResult Edit(FormCollection form, Employees newEmp) { ViewData["EmployeeRanks"] = Utilities.GetEmployeeRankNameList(); if (Session["ClientId"] != null) { newEmp.ClientId = (int)Session["ClientId"]; // if (Session["BranchId"] != null) // newEmp.BranchId = (int)Session["BranchId"]; ViewData["Branchs"] = Utilities.GetBranchNameList((int)Session["ClientId"]); if (Session["ZoneId"] != null) { ViewData["Regions"] = Utilities.GetRegionNameList((int)Session["ClientId"], (int)Session["ZoneId"]); } else { ViewData["Regions"] = Utilities.GetRegionNameList((int)Session["ClientId"], null); } ViewData["Zones"] = Utilities.GetZoneNameList((int)Session["ClientId"]); } else { if (Roles.IsUserInRole("SuperAdmin")) { return(RedirectToAction("List", "Client")); } } ViewData["Genders"] = Utilities.GetGenderNameList(); ViewData["MaritalStstus"] = Utilities.GetMaritalStatusList(); ViewData["Qualifications"] = Utilities.GetQualificationList(); ViewData["States"] = Utilities.GetStateList(Utilities.IndiaCountryCode); ViewData["Countries"] = Utilities.GetCountryList(); if (!ModelState.IsValid) { //ModelState.AddModelError("error", "Employee Id already exists"); ApplicationMessages msg = new ApplicationMessages("Invalid entry.", MessageType.Error); ViewData["Message"] = msg; return(View()); } int result = EmployeeModels.UpdateEmployee(newEmp); if (result > 0) { ApplicationMessages msg = new ApplicationMessages("Employee details updated successfully.", MessageType.Success); ViewData["Message"] = msg; } else { ApplicationMessages msg = new ApplicationMessages("Failed to update. Please try again.", MessageType.Faild); ViewData["Message"] = msg; } return(View()); }
public ActionResult Edit([Bind(Include = "id,FIRSTNAME,LASTNAME,USERNAME,STARTDATE,DEPARTMENT,SALES,RATING")] EmployeeModels employeeModels) { if (ModelState.IsValid) { db.Entry(employeeModels).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(employeeModels)); }
public string dataForEdit(string emp) { EmployeeModels em = new EmployeeModels(); em.emp_id = emp; em.tab_employee(); string data = em.emp_id + "^" + em.emp_prefix_th + "^" + em.emp_name_th + "^" + em.emp_lastname_th + "^" + em.emp_prefix_en + "^" + em.emp_name_en + "^" + em.emp_lastname_en + "^" + em.emp_type + "^" + em.emp_status + "^" + em.emp_start_date + "^" + em.emp_end_date; return(data); }
public ActionResult Edit([Bind(Include = "Id,FirstName,LastName,DisplayName,NotActive,Force")] EmployeeModels employeeModels) { if (ModelState.IsValid) { db.Entry(employeeModels).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(employeeModels)); }
public ActionResult Edit([Bind(Include = "Id,Email,Name,Salary,AddDate")] EmployeeModels employeeModels) { if (ModelState.IsValid) { db.Entry(employeeModels).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(employeeModels)); }
public bool ChangePassword(EmployeeModels model, ref string msg, string mec) { try { SBEmployeeApiModels paraBody = new SBEmployeeApiModels(); paraBody.AppKey = Commons.AppKey; paraBody.AppSecret = Commons.AppSecret; paraBody.CreatedUser = Commons.CreateUser; paraBody.ID = model.ID; paraBody.OldPassword = CommonHelper.GetSHA512(model.OldPassword); paraBody.NewPassword = CommonHelper.GetSHA512(model.NewPassword); var result = (ResponseApiModels)ApiResponse.Post <ResponseApiModels>(Commons.ChangePassword, null, paraBody); if (result != null) { if (result.Success) { using (NuWebContext cxt = new NuWebContext()) { try { var IsCheckExist = cxt.G_POSEmployeeConfig.Where(x => x.UserName == model.Email).FirstOrDefault(); if (IsCheckExist != null) { IsCheckExist.Password = CommonHelper.GetSHA512(model.NewPassword); cxt.SaveChanges(); } } catch (Exception ex) { _logger.Error("Update EmployeeConfig " + ex); return(false); } } return(true); } else { msg = result.Message; _logger.Error(result.Message); return(false); } } else { _logger.Error(result); return(false); } } catch (Exception ex) { _logger.Error("Employee_ChangePassword: " + ex); //msg = e.ToString(); return(false); } }
public ActionResult Edit(MyClinic.Infrastructure.EmployeeEdit employeeEdit) { bool checkError = true; try { Employee originEmployee = employeeRepository.GetEmployeeById(employeeEdit.Id); if (ModelState.IsValid) { Employee newEmployee = new Employee(); Dictionary <string, string> dictItem = TransactionHelper.processGenerateArray(newEmployee); newEmployee = TransactionHelper.TransDict <Employee>(dictItem, newEmployee); var objSession = Session["user"] as MyClinic.Infrastructure.SessUser; var savePathImage = Server.MapPath("~/Uploads/employee/") + originEmployee.Id; ImageHelper.SaveImage(savePathImage, originEmployee.Id + ".jpg", employeeEdit.ImageStream); string diffString = originEmployee.EnumeratePropertyDifferencesInString(newEmployee); newEmployee.Image = newEmployee.Id + ".jpg"; employeeRepository.UpdateFieldChangedOnly(originEmployee, newEmployee); /*For Add New Record to LogTable*/ logTran.UserId = objSession.UserId; logTran.ProcessType = "Edit Employee"; logTran.Description = "Edit Employee value as follow: " + diffString; logTran.LogDate = DateTime.Now; logRepository.Add(logTran); checkError = false; } if (checkError == true) { var objPosition = employeeRepository.GetPosition(); employeeModel = new EmployeeModels { employee = originEmployee, employeeEdit = employeeEdit, checkError = checkError, positions = objPosition, checkPost = true }; return(View(employeeModel)); } else { return(RedirectToAction("Index", "Employee")); } } catch (Exception ex) { log.Error(ex); ModelState.AddModelError(string.Empty, Translator.UnexpectedError); } return(View(employeeModel)); }