//Data conversion public List<Tag> ConvertTagStringToList(string TagString) { TagString = Regex.Replace(TagString, @"\s+", ""); List<Tag> NewTaglist = new List<Tag>(); var TagArray = TagString.Split(',').ToList(); foreach (var item in TagArray) { Tag tag = new Tag(); tag.TagName = item; NewTaglist.Add(tag); } return NewTaglist; }
public int AddNewHashtag(string NewTagToAdd) { Tag tagtoAdd = new Tag(); var tagList = GetHashtagIDs(_hashTags); int tagIdCount = tagList.Max(x => x.TagId); tagtoAdd.TagName = NewTagToAdd; tagtoAdd.TagId = tagIdCount + 1; _hashTags.Add(tagtoAdd); return (tagtoAdd.TagId); }
public List<Tag> GetTagsPerPost(int BlogId) { List<Tag> blogTags = new List<Tag>(); using (var cn = new SqlConnection(Settings.ConnectionString)) { var cmd = new SqlCommand(); cmd.CommandText = "GetTagsPerPost"; cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@BlogId", BlogId); cmd.Connection = cn; cn.Open(); using (SqlDataReader dr = cmd.ExecuteReader()) { while (dr.Read()) { Tag newTag = new Tag(); newTag.TagId = (int)dr["TagId"]; newTag.TagName = dr["TagName"].ToString(); blogTags.Add(newTag); } } return blogTags; } }
public List<Tag> GetHashtagIDs(List<Tag> TagList) { List<Tag> AllTags = new List<Tag>(); using (var cn = new SqlConnection(Settings.ConnectionString)) { var cmd = new SqlCommand(); cmd.CommandText = "GetAllHashtags"; cmd.CommandType = CommandType.StoredProcedure; cmd.Connection = cn; cn.Open(); using (SqlDataReader dr = cmd.ExecuteReader()) { while (dr.Read()) { Tag newtag = new Tag(); newtag.TagId = (int)dr["TagId"]; newtag.TagName = dr["TagName"].ToString(); AllTags.Add(newtag); } } } foreach (var item in TagList) { var tagfound = false; foreach (var tag in AllTags) { if(tag.TagName == item.TagName) { item.TagId = tag.TagId; tagfound = true; } } if (tagfound == false) { item.TagId = AddNewHashtag(item.TagName); } } return TagList; }