public static UpdEmployeeViewModel GetUpdEmployee(int Id) { UpdEmployeeViewModel result = new UpdEmployeeViewModel(); //取得員工資料 EmployeeModel data = EmployeeRepository.GetEmployeesById(Id); if (data != null) { result.Id = data.Id; result.Name = data.Name; result.EnName = data.EnName; } return(result); }
public ActionResult UpdEmployee(UpdEmployeeViewModel param) { //表單驗證 if (ModelState.IsValid) { var Data = HomeDomain.UpdEmployee(param); if (String.IsNullOrWhiteSpace(Data)) { return(RedirectToAction("Index", "Home")); } else { TempData["message"] = Data; return(View(param)); } } return(View(param)); }
public static bool UpdEmployee(UpdEmployeeViewModel param) { bool result = true; try { #region 參數 string sqlQuery = String.Empty; DynamicParameters sqlparam = new DynamicParameters(); sqlparam.Add("Id", param.Id); sqlparam.Add("Name", param.Name.Trim()); if (!String.IsNullOrWhiteSpace(param.EnName)) { sqlparam.Add("EnName", param.EnName.Trim()); } else { sqlparam.Add("EnName", null); } #endregion #region SQL 語法 sqlQuery = @" UPDATE Employee SET Name = @Name , EnName = @EnName ,UpdateBy='SYS',UpdateTime=GETDATE() Where Id =@Id"; #endregion #region SQL 查詢 using (SqlConnection conn = new SqlConnection(strConn)) { conn.Execute(sqlQuery, sqlparam); } #endregion } catch (Exception ex) { result = false; } return(result); }
public static string UpdEmployee(UpdEmployeeViewModel param) { string result = string.Empty; //判斷Name是否重複 if (EmployeeRepository.GetEmployeesByName(param.Name, param.Id) == null) { //更新員工資料 bool data = EmployeeRepository.UpdEmployee(param); if (!data) { result = "更新失敗"; } } else { result = "名字已新增過"; } return(result); }