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

            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)
                {
                    PhotoTag photoTag = new PhotoTag();
                    photoTag.PhotoID   = this.PhotoID;
                    photoTag.DTCreated = DateTime.Now;
                    photoTag.Tag       = DedupedTags[j];
                    photoTag.Save();
                }
            }

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

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

            PhotoTag obj;

            while (dr.Read())
            {
                obj = new PhotoTag();
                if (list.IsColumnPresent("PhotoTagID")) { obj._photoTagID = (int)dr["PhotoTagID"]; }
                if (list.IsColumnPresent("PhotoID")) { obj._photoID = (int)dr["PhotoID"]; }
                if (list.IsColumnPresent("TagWordID")) { obj._tagWordID = (int)dr["TagWordID"]; }
                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;
        }
Ejemplo n.º 3
0
        public void UpdateTags()
        {

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

            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)
                {
                    PhotoTag photoTag = new PhotoTag();
                    photoTag.PhotoID = this.PhotoID;
                    photoTag.DTCreated = DateTime.Now;
                    photoTag.Tag = DedupedTags[j];
                    photoTag.Save();
                }
            }

            this.Tags = FormatedTags;
        }