public int CreateNewsEventRelationGet(NewsEventRelation newsRelation)
        {
            int i = 0;

            using (SqlConnection connection = GetConnection())
            {
                SqlCommand command = new SqlCommand("_NewsEventRelationInsert", connection);
                command.CommandType = CommandType.StoredProcedure;
                command.Parameters.AddWithValue("@Type", 0);
                command.Parameters.AddWithValue("@Id", 0);
                command.Parameters.AddWithValue("@NewsEventID", newsRelation.NewsEventID);
                command.Parameters.AddWithValue("@NewsGroupID", newsRelation.NewsGroupID);

                SqlParameter parameter = new SqlParameter("@ReturnId", SqlDbType.Int);
                parameter.Direction = ParameterDirection.ReturnValue;
                command.Parameters.Add(parameter);
                connection.Open();
                if (command.ExecuteNonQuery() <= 0)
                {
                    throw new DataAccessException("Khong them duoc");
                }
                else
                {
                    i = (int)parameter.Value;
                    command.Dispose();
                }
            }
            return(i);
        }
        public NewsEventRelation GetNewsEventRelationByID(int newsGroupID, int newsEventID)
        {
            NewsEventRelation _newRelation = null;

            using (SqlConnection connection = GetConnection())
            {
                SqlCommand command = new SqlCommand("_NewsEventRelationGetByID", connection);
                command.CommandType = CommandType.StoredProcedure;
                command.Parameters.AddWithValue("@NewsGroupID", newsGroupID);
                command.Parameters.AddWithValue("@NewsEventID", newsEventID);
                connection.Open();
                using (SqlDataReader reader = command.ExecuteReader(CommandBehavior.CloseConnection))
                {
                    if (reader.Read())
                    {
                        _newRelation = NewsEventRelationReader(reader);
                    }
                    else
                    {
                        // throw new DataAccessException("Không tìm thấy tin");
                        _newRelation = null;
                    }
                }
                command.Dispose();
            }
            return(_newRelation);
        }
        private NewsEventRelation NewsEventRelationReader(SqlDataReader reader)
        {
            NewsEventRelation newsRelation = new NewsEventRelation();

            newsRelation.Id          = (int)reader["Id"];
            newsRelation.NewsEventID = (int)reader["NewsEventID"];
            newsRelation.NewsGroupID = (int)reader["NewsGroupID"];

            return(newsRelation);
        }
 public void UpdateNewsEventRelation(NewsEventRelation newsRelation)
 {
     using (SqlConnection connection = GetConnection())
     {
         SqlCommand command = new SqlCommand("_NewsEventRelationUpdate", connection);
         command.CommandType = CommandType.StoredProcedure;
         command.Parameters.AddWithValue("@Type", 1);
         command.Parameters.AddWithValue("@Id", newsRelation.Id);
         command.Parameters.AddWithValue("@NewsEventID", newsRelation.NewsEventID);
         command.Parameters.AddWithValue("@NewsGroupID", newsRelation.NewsGroupID);
         connection.Open();
         if (command.ExecuteNonQuery() <= 0)
         {
             throw new DataAccessException("khong cap nhat duoc newsRelation");
         }
         else
         {
             command.Dispose();
         }
     }
 }
示例#5
0
        public void UpdateNewsEventRelation(NewsEventRelation newsEventRealation)
        {
            NewsEventRelationDAO newsEventRealationDAO = new NewsEventRelationDAO();

            newsEventRealationDAO.UpdateNewsEventRelation(newsEventRealation);
        }
示例#6
0
        public int CreateNewsEventRelationGet(NewsEventRelation newsEventRealation)
        {
            NewsEventRelationDAO newsEventRealationDAO = new NewsEventRelationDAO();

            return(newsEventRealationDAO.CreateNewsEventRelationGet(newsEventRealation));
        }