Example #1
0
        public NewsTags GetNewsTags(int _tagsID, int _newsGroupID)
        {
            NewsTags _newsTags = null;

            using (SqlConnection connection = GetConnection())
            {
                SqlCommand command = new SqlCommand("_NewsTagsGet", connection);
                command.CommandType = CommandType.StoredProcedure;
                command.Parameters.AddWithValue("@TagsID", _tagsID);
                command.Parameters.AddWithValue("@NewsGroupID", _newsGroupID);
                connection.Open();
                using (SqlDataReader reader = command.ExecuteReader(CommandBehavior.CloseConnection))
                {
                    if (reader.Read())
                    {
                        _newsTags = NewsTagsReader(reader);
                    }
                    else
                    {
                        _newsTags = null;
                    }
                    //  throw new DataAccessException("Không tìm thấy giá trị");
                    command.Dispose();
                }
            }
            return(_newsTags);
        }
Example #2
0
        public NewsTags GetNewsTagsById(int Id)
        {
            NewsTags _newsTags = null;

            using (SqlConnection connection = GetConnection())
            {
                SqlCommand command = new SqlCommand("_NewsTagsGetById", connection);
                command.CommandType = CommandType.StoredProcedure;
                command.Parameters.AddWithValue("@NewsTagsID", Id);
                connection.Open();
                using (SqlDataReader reader = command.ExecuteReader(CommandBehavior.CloseConnection))
                {
                    if (reader.Read())
                    {
                        _newsTags = NewsTagsReader(reader);
                    }
                    else
                    {
                        throw new DataAccessException("Khong tim thay gia tri nao");
                    }
                    command.Dispose();
                }
            }
            return(_newsTags);
        }
Example #3
0
        public virtual IList <NewsTags> GetAllNewsTags(int storeId, int languageId, bool showHidden = false)
        {
            var blogPostTags = new List <NewsTags>();

            var news = GetAllNews(storeId: storeId, languageId: languageId, showHidden: showHidden);

            foreach (var newsItem in news)
            {
                var tags = this.ParseTags(newsItem);
                foreach (var tag in tags)
                {
                    var foundNewsTag = blogPostTags.Find(bpt => bpt.Name.Equals(tag, StringComparison.InvariantCultureIgnoreCase));
                    if (foundNewsTag == null)
                    {
                        foundNewsTag = new NewsTags
                        {
                            Name      = tag,
                            NewsCount = 1
                        };
                        blogPostTags.Add(foundNewsTag);
                    }
                    else
                    {
                        foundNewsTag.NewsCount++;
                    }
                }
            }

            return(blogPostTags);
        }
Example #4
0
 public NewsTagsDto CreateNewsTagDto(NewsTags newsTags)
 {
     return(new NewsTagsDto
     {
         Name = newsTags.Name
     });
 }
Example #5
0
        public static string GetTagDescription(NewsTags tag)
        {
            switch (tag)
            {
            case NewsTags.Clothes:
                return("#smartclothes");

            case NewsTags.Startups:
                return("#startups");

            case NewsTags.Devices:
                return("#devices");

            case NewsTags.Robots:
                return("#robots");

            case NewsTags.AI:
                return("#ai");

            case NewsTags.Video:
                return("#video");

            default:
                return("#commons");
            }
        }
Example #6
0
        private NewsTags NewsTagsReader(SqlDataReader reader)
        {
            NewsTags _newsTags = new NewsTags();

            _newsTags.NewsTagsID  = (int)reader["NewsTagsID"];
            _newsTags.TagsID      = (int)reader["TagsID"];
            _newsTags.NewsGroupID = (int)reader["NewsGroupID"];

            return(_newsTags);
        }
Example #7
0
        public bool CheckExitTags(int _tagsID, int _newsGroupID)
        {
            bool check = false;

            NewsTags _newstags = new NewsTags();

            _newstags = GetNewsTags(_tagsID, _newsGroupID);

            if (_newstags != null)
            {
                check = true;
            }
            return(check);
        }
Example #8
0
 internal static void InserNewPair(int newId, int tagId)
 {
     using (SampleContext context = new SampleContext())
     {
         var idTag = context.newsTags.SingleOrDefault(u => u.newsId == newId && tagId == u.tagId);
         if (idTag == null)
         {
             NewsTags newsTags = new NewsTags();
             newsTags.newsId = newId;
             newsTags.tagId  = tagId;
             context.newsTags.Add(newsTags);
             context.SaveChanges();
         }
     }
 }
Example #9
0
 internal static void InserNewPairs(List <string> tagList, string title)
 {
     if (tagList.Count != 0)
     {
         using (SampleContext context = new SampleContext())
         {
             int      newId      = context.news.SingleOrDefault(x => x.title == title).newsId;
             NewsTags newTagNews = new NewsTags();
             foreach (var item in tagList)
             {
                 var tagId = context.tags.SingleOrDefault(x => x.tag == item).tagId;
                 newTagNews.newsId = newId;
                 newTagNews.tagId  = tagId;
                 context.newsTags.Add(newTagNews);
                 context.SaveChanges();
             }
         }
         JsonController.tagList.Clear();
     }
 }
Example #10
0
 public void UpdateNewsTags(NewsTags _newsTags)
 {
     using (SqlConnection connection = GetConnection())
     {
         SqlCommand command = new SqlCommand("_NewsTagsUpdate", connection);
         command.CommandType = CommandType.StoredProcedure;
         command.Parameters.AddWithValue("@Type", 1);
         command.Parameters.AddWithValue("@NewsTagsID", _newsTags.NewsTagsID);
         command.Parameters.AddWithValue("@TagsID", _newsTags.TagsID);
         command.Parameters.AddWithValue("@NewsGroupID", _newsTags.NewsGroupID);
         connection.Open();
         if (command.ExecuteNonQuery() <= 0)
         {
             throw new DataAccessException("Khong cap nhat duoc quang cao");
         }
         else
         {
             command.Dispose();
         }
     }
 }
Example #11
0
        public void UpdateNewsTags(NewsTags _newsTags)
        {
            NewsTagsDAO _newstagsDAO = new NewsTagsDAO();

            _newstagsDAO.UpdateNewsTags(_newsTags);
        }
Example #12
0
        public void CreateNewsTags(NewsTags _newsTags)
        {
            NewsTagsDAO _newstagsDAO = new NewsTagsDAO();

            _newstagsDAO.CreateNewsTags(_newsTags);
        }