/// <summary> /// Add a new entry to the EmployeeAvailability table /// </summary> public static EmployeeAvailability Add(int employeeId, Days day, TimeSpan startTime, TimeSpan endTime) { EmployeeAvailability result = null; DateTime purchaseTime = DateTime.Now; SqlConnection cn = GetConnection(); string cmd = "AddEmployeeAvailability"; using (SqlCommand sqlCmd = new SqlCommand(cmd, cn)) { sqlCmd.CommandType = CommandType.StoredProcedure; BuildSqlParameter(sqlCmd, "@EmployeeAvailabilityEmployeeId", SqlDbType.Int, employeeId); BuildSqlParameter(sqlCmd, "@EmployeeAvailabilityDayOfTheWeek", SqlDbType.TinyInt, day); BuildSqlParameter(sqlCmd, "@EmployeeAvailabilityStartTime", SqlDbType.Time, startTime); BuildSqlParameter(sqlCmd, "@EmployeeAvailabilityEndTime", SqlDbType.Text, endTime); BuildSqlParameter(sqlCmd, "@EmployeeAvailabilityId", SqlDbType.Int, ParameterDirection.ReturnValue); if (sqlCmd.ExecuteNonQuery() > 0) { result = new EmployeeAvailability(Convert.ToInt32(sqlCmd.Parameters["@EmployeeAvailabilityId"].Value), employeeId, day, startTime, endTime); } } FinishedWithConnection(cn); return(result); }
/// <summary> /// Update an entry in the EmployeeAvailability table /// </summary> public static bool Update(EmployeeAvailability employeeAvailability) { bool result = false; SqlConnection cn = GetConnection(); result = Update(cn, employeeAvailability); FinishedWithConnection(cn); return(result); }
/// <summary> /// Get an entry from the EmployeeAvailability table /// </summary> public static EmployeeAvailability Get(int id) { EmployeeAvailability result = null; SqlConnection cn = GetConnection(); result = Get(cn, id); FinishedWithConnection(cn); return(result); }
private static EmployeeAvailability Get(SqlConnection cn, int id) { EmployeeAvailability result = null; using (SqlCommand cmd = new SqlCommand("SELECT * FROM EmployeeAvailability WHERE EmployeeAvailabilityId=" + id, cn)) { using (SqlDataReader rdr = cmd.ExecuteReader()) { if (rdr.Read()) { result = BuildEmployeeAvailability(rdr); } } } return(result); }
private static bool Update(SqlConnection cn, EmployeeAvailability employeeAvailability) { Int32 rowsAffected = 0; using (SqlCommand sqlCmd = cn.CreateCommand()) { sqlCmd.CommandText = "UPDATE EmployeeAvailability SET EmployeeAvailabilityEmployeeId=@EmployeeAvailabilityEmployeeId,EmployeeAvailabilityDayOfTheWeek=@EmployeeAvailabilityDayOfTheWeek,EmployeeAvailabilityStartTime=@EmployeeAvailabilityStartTime,EmployeeAvailabilityEndTime=@EmployeeAvailabilityEndTime WHERE EmployeeAvailabilityId=@EmployeeAvailabilityId"; BuildSqlParameter(sqlCmd, "@EmployeeAvailabilityId", SqlDbType.Int, employeeAvailability.Id); BuildSqlParameter(sqlCmd, "@EmployeeAvailabilityEmployeeId", SqlDbType.Int, employeeAvailability.EmployeeId); BuildSqlParameter(sqlCmd, "@EmployeeAvailabilityDayOfTheWeek", SqlDbType.TinyInt, employeeAvailability.Day); BuildSqlParameter(sqlCmd, "@EmployeeAvailabilityStartTime", SqlDbType.Time, employeeAvailability.StartTime); BuildSqlParameter(sqlCmd, "@EmployeeAvailabilityEndTime", SqlDbType.Text, employeeAvailability.EndTime); rowsAffected = sqlCmd.ExecuteNonQuery(); } return(rowsAffected != 0); }