/// <summary> /// 修改人员 /// </summary> /// <param name="employee"></param> /// <returns></returns> public bool ModifyEmployee(T_QMDS_Employee employee) { var sql = @"UPDATE T_QMDS_Employee SET [EName] = @EName , Nickname = @Nickname , Phone = @Phone , [Address] = @Address , NativePlace = @NativePlace , [Message] = @Message , Picture = @Picture , ModifierID = @ModifierID , ModifyTime = GETDATE() WHERE ID=@ID" ; return(_dapperPlusDB.Execute(sql, employee) > 0); }
public IActionResult ModifyEmployee(T_QMDS_Employee employee) { try { var phone = _commercialRepository.GetEmployeeByID(employee.ID)[0].Phone; if (phone != employee.Phone && _commercialRepository.CheckPhone(employee.Phone)) //验证手机 { return(new JsonResult(0)); } _commercialRepository.ModifyEmployee(employee); return(new JsonResult(new { result = 1, message = "修改人员成功!" })); } catch (Exception exc) { _log.Fatal($"添加人员失败:{exc.Message}"); return(new JsonResult(new { result = 0, message = "修改人员失败!" })); } }
public IActionResult AddEmployee([FromServices] IHostingEnvironment env, T_QMDS_Employee employee, string password) { try { //验证手机 if (_commercialRepository.CheckPhone(employee.Phone)) { return(new JsonResult(0)); } employee.ENumber = _commercialRepository.YGNumber(); employee.ID = _commercialRepository.ProduceID(3); QRCode(env, employee.ID, employee.ENumber); _commercialRepository.AddEmployee(employee, password); return(new JsonResult(new { result = 1, message = "添加人员成功!" })); } catch (Exception exc) { _log.Fatal($"添加人员失败:{exc.Message}"); return(new JsonResult(new { result = 0, message = "添加人员失败!" })); } }
/// <summary> /// 添加人员并设置密码 /// </summary> /// <param name="employee">人员</param> /// <returns></returns> public bool AddEmployee(T_QMDS_Employee employee, string password) { #region sql语句 var sql = @"INSERT INTO dbo.T_QMDS_Employee ( ID, CompanyID , ENumber , EName , Nickname , Phone , [Address] , NativePlace , [Message] , Picture , CreaterID , CreateTime ) VALUES ( @ID, @CompanyID , @ENumber , @EName , @Nickname , @Phone , @Address , @NativePlace , @Message , @Picture , @CreaterID , GETDATE() )"; var sql1 = @"INSERT INTO dbo.T_QMDS_EmployeeUser ( UserName , PassWord , EmployeeID ) VALUES ( @Phone , @PassWord , @EmployeeID )"; #endregion IDbTransaction transaction = null; IDbConnection conn = null; try { conn = _dapperPlusDB.GetConnection(); conn.Open(); transaction = conn.BeginTransaction(); _dapperPlusDB.Execute(sql, employee, transaction); _dapperPlusDB.Execute(sql1, new { Phone = employee.Phone, PassWord = password, EmployeeID = employee.ID }, transaction); transaction.Commit(); return(true); } catch (Exception exc) { if (transaction != null) { transaction.Rollback(); } throw new Exception(exc.Message); } finally { if (conn != null) { conn.Close(); } } }