Exemplo n.º 1
0
        public void UpdateTags()
        {
            char[]          sep  = { ',' };
            List <VideoTag> tags = this.VideoTag;

            string[] NewTags = this.Tags.Split(sep);

            string        FormatedTags = string.Empty;
            List <string> TrimmedTags  = new List <string>();
            List <string> DedupedTags  = new List <string>();


            //1. Trim all tags
            for (int i = 0; i < NewTags.Length; i++)
            {
                if (NewTags[i].Trim() != string.Empty)
                {
                    TrimmedTags.Add(NewTags[i].Trim());
                }
            }

            //2. dedupe the list
            for (int i = 0; i < TrimmedTags.Count; i++)
            {
                bool Duplicate = false;

                for (int j = 0; j < DedupedTags.Count; j++)
                {
                    if (DedupedTags[j] == TrimmedTags[i])
                    {
                        Duplicate = true;
                    }
                }

                if (!Duplicate)
                {
                    // make sure isnt a blank string
                    if (FormatedTags != string.Empty)
                    {
                        FormatedTags += ", ";
                    }

                    DedupedTags.Add(TrimmedTags[i]);
                    FormatedTags += TrimmedTags[i];
                }
            }


            //3. remove all the tags that arent in the new set
            for (int i = 0; i < tags.Count; i++)
            {
                bool Delete = true;

                for (int j = 0; j < DedupedTags.Count; j++)
                {
                    if (DedupedTags[j] == tags[i].Tag)
                    {
                        Delete = false;
                    }
                }

                if (Delete)
                {
                    tags[i].Delete();
                }
            }


            // 4. insert new tags
            for (int j = 0; j < DedupedTags.Count; j++)
            {
                bool Insert = true;

                for (int i = 0; i < tags.Count; i++)
                {
                    if (DedupedTags[j] == tags[i].Tag)
                    {
                        Insert = false;
                    }
                }


                if (Insert)
                {
                    VideoTag VideoTag = new VideoTag();
                    VideoTag.VideoID   = this.VideoID;
                    VideoTag.DTCreated = DateTime.Now;
                    VideoTag.Tag       = DedupedTags[j];
                    VideoTag.Save();
                }
            }

            this.Tags = FormatedTags;
        }
Exemplo n.º 2
0
        /// <summary>
        /// Takes an prepopulated IDataReader and creates an array of VideoTags
        /// </summary>
        public static List<VideoTag> PopulateObject(IDataReader dr)
        {
            ColumnFieldList list = new ColumnFieldList(dr);

            List<VideoTag> arr = new List<VideoTag>();

            VideoTag obj;

            while (dr.Read())
            {
                obj = new VideoTag();
                if (list.IsColumnPresent("VideoTagID")) { obj._videoTagID = (int)dr["VideoTagID"]; }
                if (list.IsColumnPresent("VideoID")) { obj._videoID = (int)dr["VideoID"]; }
                if (list.IsColumnPresent("Tag")) { obj._tag = (string)dr["Tag"]; }
                if (list.IsColumnPresent("DTCreated")) { obj._dTCreated = (DateTime)dr["DTCreated"]; }

                arr.Add(obj);
            }

            dr.Close();

            return arr;
        }
Exemplo n.º 3
0
        public void UpdateTags()
        {

            char[] sep = { ',' };
            List<VideoTag> tags = this.VideoTag;

            string[] NewTags = this.Tags.Split(sep);

            string FormatedTags = string.Empty;
            List<string> TrimmedTags = new List<string>();
            List<string> DedupedTags = new List<string>();


            //1. Trim all tags
            for (int i = 0; i < NewTags.Length; i++)
            {
                if (NewTags[i].Trim() != string.Empty)
                {
                    TrimmedTags.Add(NewTags[i].Trim());
                }
            }

            //2. dedupe the list
            for (int i = 0; i < TrimmedTags.Count; i++)
            {
                bool Duplicate = false;

                for (int j = 0; j < DedupedTags.Count; j++)
                {
                    if (DedupedTags[j] == TrimmedTags[i])
                    {
                        Duplicate = true;
                    }
                }

                if (!Duplicate)
                {
                    // make sure isnt a blank string
                    if (FormatedTags != string.Empty)
                    {
                        FormatedTags += ", ";
                    }

                    DedupedTags.Add(TrimmedTags[i]);
                    FormatedTags += TrimmedTags[i];
                }

            }


            //3. remove all the tags that arent in the new set
            for (int i = 0; i < tags.Count; i++)
            {
                bool Delete = true;

                for (int j = 0; j < DedupedTags.Count; j++)
                {
                    if (DedupedTags[j] == tags[i].Tag)
                    {
                        Delete = false;
                    }
                }

                if (Delete)
                {
                    tags[i].Delete();
                }
            }


            // 4. insert new tags
            for (int j = 0; j < DedupedTags.Count; j++)
            {
                bool Insert = true;

                for (int i = 0; i < tags.Count; i++)
                {
                    if (DedupedTags[j] == tags[i].Tag)
                    {
                        Insert = false;
                    }
                }


                if (Insert)
                {
                    VideoTag VideoTag = new VideoTag();
                    VideoTag.VideoID = this.VideoID;
                    VideoTag.DTCreated = DateTime.Now;
                    VideoTag.Tag = DedupedTags[j];
                    VideoTag.Save();
                }
            }

            this.Tags = FormatedTags;
        }