public int AddEmployee(Employees employees) { string procName = "spEmployeeInsert"; var param = new DynamicParameters(); int EmployeeId = 0; param.Add("@EmployeeId", employees.EmployeeID, null, ParameterDirection.Output); param.Add("@Title", employees.Title); param.Add("@TitleOfCourtesy", employees.TitleOfCourtesy); param.Add("@FirstName", employees.FirstName); param.Add("@LastName", employees.LastName); param.Add("@Address", employees.Address); param.Add("@City", employees.City); param.Add("@Region", employees.Region); param.Add("@PostalCode", employees.PostalCode); param.Add("@HomePhone", employees.HomePhone); param.Add("@Country", employees.Country); try { SqlMapper.Execute(_connectionFactory.GetConnection, procName, param, commandType: CommandType.StoredProcedure, commandTimeout: 1800); EmployeeId = param.Get <int>("@EmployeeId"); } finally { _connectionFactory.CloseConnection(); } return(EmployeeId); }
public void CloseConnection(IDbConnection connection) { if (connection is ProfiledDbConnection profiledConnection) { _factory.CloseConnection(profiledConnection.WrappedConnection); } }
public void CloseConnection(IDbConnection connection) { var profiledConnection = connection as ProfiledDbConnection; if (profiledConnection != null) { _factory.CloseConnection(profiledConnection.WrappedConnection); } }
public async Task <Employees> GetByIdAsync(int id) { var Employees = new Employees(); var procName = "spEmployeesFetch"; var param = new DynamicParameters(); param.Add("@EmployeeId", id); try { using (var multiResult = await SqlMapper.QueryMultipleAsync(_connectionFactory.GetConnection, procName, param, commandType: CommandType.StoredProcedure, commandTimeout: 1800)) { Employees = multiResult.ReadFirstOrDefault <Employees>(); Employees.Territories = multiResult.Read <EmployeesTerritory>().ToList(); } } finally { _connectionFactory.CloseConnection(); } return(Employees); }
public IEnumerable <TResult> GetData <TResult>(StringBuilder queryScript, DynamicParameters parameters) { try { using (var conn = connectionFactory.CreateConnection(false)) { var result = conn.Query <TResult>(queryScript.ToString(), parameters); connectionFactory.CloseConnection(conn); return(result); } } catch (DbException ex) { throw new FattalDbException(ErrorTypeEnum.DbOperationException, MethodBase.GetCurrentMethod().GetMethodName(), ex.Message, ex); } catch (Exception ex) { throw new FattalDbException(ErrorTypeEnum.DbOperationException, MethodBase.GetCurrentMethod().GetMethodName(), ex.Message, ex); } }