コード例 #1
0
        /// <summary>
        /// Adding new tag into database.
        /// </summary>
        /// <param name="newTag">New tag entity.</param>
        /// <returns>ID for created tag.</returns>
        public int AddTag(Tag newTag)
        {
            using (PhotoCollectionDatabaseEntities context = new PhotoCollectionDatabaseEntities(_connectionString))
            {
                newTag.ID = context.Tags.NextId(p => p.ID);

                context.Tags.AddObject(newTag);
                context.SaveChanges();

                return newTag.ID;
            }
        }
コード例 #2
0
        /// <summary>
        /// Adds the template tag.
        /// </summary>
        /// <returns>Sample tag ID.</returns>
        public int AddTemplateTag()
        {
            using (PhotoCollectionDatabaseEntities context = new PhotoCollectionDatabaseEntities(_connectionString))
            {
                Tag tag = new Tag();

                tag.ID = context.Tags.NextId(t => t.ID);
                tag.IconPath = "none";
                tag.CreationDate = System.Convert.ToDateTime(System.DateTime.Now);
                tag.Name = "TemporaryTag";
                tag.ParentID = null;

                context.Tags.AddObject(tag);
                context.SaveChanges();

                return tag.ID;
            }
        }
コード例 #3
0
        private void FixupTags1(Tag previousValue)
        {
            // This is the principal end in an association that performs cascade deletes.
            // Update the event listener to refer to the new dependent.
            if (previousValue != null)
            {
                ChangeTracker.ObjectStateChanging -= previousValue.HandleCascadeDelete;
            }

            if (Tags1 != null)
            {
                ChangeTracker.ObjectStateChanging += Tags1.HandleCascadeDelete;
            }

            if (IsDeserializing)
            {
                return;
            }

            if (previousValue != null && ReferenceEquals(previousValue.Tag1, this))
            {
                previousValue.Tag1 = null;
            }

            if (Tags1 != null)
            {
                Tags1.Tag1 = this;
            }

            if (ChangeTracker.ChangeTrackingEnabled)
            {
                if (ChangeTracker.OriginalValues.ContainsKey("Tags1")
                    && (ChangeTracker.OriginalValues["Tags1"] == Tags1))
                {
                    ChangeTracker.OriginalValues.Remove("Tags1");
                }
                else
                {
                    ChangeTracker.RecordOriginalValue("Tags1", previousValue);
                    // This is the principal end of an identifying association, so the dependent must be deleted when the relationship is removed.
                    // If the current state of the dependent is Added, the relationship can be changed without causing the dependent to be deleted.
                    if (previousValue != null && previousValue.ChangeTracker.State != ObjectState.Added)
                    {
                        previousValue.MarkAsDeleted();
                    }
                }
                if (Tags1 != null && !Tags1.ChangeTracker.ChangeTrackingEnabled)
                {
                    Tags1.StartTracking();
                }
            }
        }
コード例 #4
0
        private void FixupTag1(Tag previousValue)
        {
            if (IsDeserializing)
            {
                return;
            }

            if (previousValue != null && ReferenceEquals(previousValue.Tags1, this))
            {
                previousValue.Tags1 = null;
            }

            if (Tag1 != null)
            {
                Tag1.Tags1 = this;
                ID = Tag1.ID;
            }

            if (ChangeTracker.ChangeTrackingEnabled)
            {
                if (ChangeTracker.OriginalValues.ContainsKey("Tag1")
                    && (ChangeTracker.OriginalValues["Tag1"] == Tag1))
                {
                    ChangeTracker.OriginalValues.Remove("Tag1");
                }
                else
                {
                    ChangeTracker.RecordOriginalValue("Tag1", previousValue);
                }
                if (Tag1 != null && !Tag1.ChangeTracker.ChangeTrackingEnabled)
                {
                    Tag1.StartTracking();
                }
            }
        }
コード例 #5
0
        private void FixupTag(Tag previousValue)
        {
            if (IsDeserializing)
            {
                return;
            }

            if (previousValue != null && previousValue.Tags2Photos.Contains(this))
            {
                previousValue.Tags2Photos.Remove(this);
            }

            if (Tag != null)
            {
                if (!Tag.Tags2Photos.Contains(this))
                {
                    Tag.Tags2Photos.Add(this);
                }

                TagID = Tag.ID;
            }
            if (ChangeTracker.ChangeTrackingEnabled)
            {
                if (ChangeTracker.OriginalValues.ContainsKey("Tag")
                    && (ChangeTracker.OriginalValues["Tag"] == Tag))
                {
                    ChangeTracker.OriginalValues.Remove("Tag");
                }
                else
                {
                    ChangeTracker.RecordOriginalValue("Tag", previousValue);
                }
                if (Tag != null && !Tag.ChangeTracker.ChangeTrackingEnabled)
                {
                    Tag.StartTracking();
                }
            }
        }
コード例 #6
0
        /// <summary>
        /// Add a tag to database.
        /// </summary>
        /// <param name="tagName">Body of a tag.</param>
        /// <returns>Returns true if successful.</returns>
        public static bool AddTag(string tagName)
        {
            TagsDataSource db = new TagsDataSource(ConnectionStringHelper.GetActualConnectionString());

            List<Tag> allTags = db.GetAllTags();
            Tag toAdd = new Tag();

            // If list is empty skip some steps.
            if (allTags.Count == 0)
            {
                toAdd.Name = tagName;
                toAdd.CreationDate = System.DateTime.Now;

                db.AddTag(toAdd);

                return true;
            }

            // If already exists returning false.
            Tag findResult = allTags.Find((temporary) => temporary.Name == tagName);
            if (findResult != null)
            {
                return false;
            }

            toAdd.Name = tagName;
            toAdd.CreationDate = System.DateTime.Now;

            db.AddTag(toAdd);

            return true;
        }