Exemplo n.º 1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="Name"></param>
        public Guid CreateTag(string Name, Color TagColor, bool Unique, Guid DecayTagId)
        {
            Tag Tag = new Tag();

            Tag.Id         = Guid.NewGuid();
            Tag.Name       = Name;
            Tag.Color      = TagColor;
            Tag.Unique     = Unique;
            Tag.DecayTagId = DecayTagId;

            Tags.Add(Tag);

            TagsUpdated?.Invoke();

            return(Tag.Id);
        }
Exemplo n.º 2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="TagId"></param>
        public void RenameTag(Guid TagId, string Name, Color TagColor, bool Unique, Guid DecayTagId)
        {
            Tag Tag = GetTagById(TagId);

            if (Tag == null)
            {
                return;
            }

            Tag.Name       = Name;
            Tag.Color      = TagColor;
            Tag.Unique     = Unique;
            Tag.DecayTagId = DecayTagId;

            TagsUpdated?.Invoke();
        }
Exemplo n.º 3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="TagId"></param>
        public void DeleteTag(Guid TagId)
        {
            Tag Tag = GetTagById(TagId);

            if (Tag == null)
            {
                return;
            }

            Tags.Remove(Tag);

            foreach (Tag SubTag in Tags)
            {
                if (SubTag.DecayTagId == Tag.Id)
                {
                    SubTag.DecayTagId = Guid.Empty;
                }
            }

            TagDeleted?.Invoke(TagId);

            TagsUpdated?.Invoke();
        }
Exemplo n.º 4
0
        public ManageTagsForItemDialog(Item item)
        {
            InitializeComponent();

            this._tagService = new TagService();

            this._item = item;
            this.itemTitleLabel.Text = item.Title;

            this.tagsList.CheckOnClick = true;

            this.CenterToParent();

            // initially disable add and save buttons
            this.buttonSave.Enabled      = false;
            this.addNewTagButton.Enabled = false;

            // register event handlers
            this.buttonCancel.Click += ((sender, args) =>
            {
                this.Close();
            });
            this.buttonSave.Click += (async(sender, args) =>
            {
                // disable add, save and cancel buttons
                this.addNewTagButton.Enabled = false;
                this.buttonSave.Enabled = false;
                this.buttonCancel.Enabled = false;

                // save changes
                List <string> originalTags = new List <string>();
                foreach (var tag in this._item.Tags)
                {
                    originalTags.Add(tag.Name);
                }
                ItemTagsDto dto = new ItemTagsDto(this._item.Id, originalTags, this.SelectedTags);
                try
                {
                    if (this._item.Type == ItemType.Book)
                    {
                        IBookService _bookService = new BookService();
                        await _bookService.UpdateTags(dto);
                    }
                    else
                    {
                        IMediaItemService _itemRepo = new MediaItemService();
                        await _itemRepo.UpdateTags(dto);
                    }

                    this.Close();
                }
                catch (Exception ex)
                {
                    // something bad happened
                    // notify the user
                    MessageBox.Show("Error updating tags: " + ex.Message, "manage tags", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                finally
                {
                    // re-enable buttons
                    this.addNewTagButton.Enabled = true;
                    this.buttonSave.Enabled = true;
                    this.buttonCancel.Enabled = true;
                }

                TagsUpdated?.Invoke(this, args);
            });
            this.newTagField.TextChanged += ((sender, args) =>
            {
                this.addNewTagButton.Enabled = !string.IsNullOrWhiteSpace(this.newTagField.Text);
            });
            this.addNewTagButton.Click += (async(sender, args) =>
            {
                // disable add, save and cancel buttons
                this.addNewTagButton.Enabled = false;
                this.buttonSave.Enabled = false;
                this.buttonCancel.Enabled = false;

                string newTagName = this.newTagField.Text;

                try
                {
                    // check for existing tag
                    bool tagAlreadyInList = false;
                    foreach (var tagInList in this.tagsList.Items)
                    {
                        if (tagInList.ToString().Equals(newTagName))
                        {
                            tagAlreadyInList = true;
                        }
                    }
                    if (await this._tagService.ExistsWithName(newTagName) ||
                        tagAlreadyInList)
                    {
                        MessageBox.Show("Tag: \"" + newTagName + "\" already exists.", "Manage tags", MessageBoxButtons.OK, MessageBoxIcon.Warning);

                        // re-enable buttons
                        this.addNewTagButton.Enabled = true;
                        this.buttonSave.Enabled = true;
                        this.buttonCancel.Enabled = true;

                        return;
                    }
                }
                catch (Exception ex)
                {
                    // something bad happened
                    MessageBox.Show("Error checking if tag \"" + newTagName + "\" exists: " + ex.Message, "Manage tags", MessageBoxButtons.OK, MessageBoxIcon.Error);

                    // re-enable buttons
                    this.addNewTagButton.Enabled = true;
                    this.buttonSave.Enabled = true;
                    this.buttonCancel.Enabled = true;

                    return;
                }

                this.tagsList.Items.Add(this.newTagField.Text, true);

                // re-enable buttons
                this.addNewTagButton.Enabled = true;
                this.buttonSave.Enabled = true;
                this.buttonCancel.Enabled = true;
            });
            this.tagsList.ItemCheck += ((sender, args) =>
            {
                this.buttonSave.Enabled = true;
            });
        }
Exemplo n.º 5
0
        private ManageTagsForm()
        {
            InitializeComponent();

            this.tagsList.MultiSelect = false;

            this._service = new TagService();

            // set up ListView
            this.tagsList.GridLines = true;
            this.tagsList.Columns.Clear();
            this.tagsList.Columns.Add("");
            this.tagsList.View             = View.Details;
            this.tagsList.HeaderStyle      = ColumnHeaderStyle.None;
            this.tagsList.Columns[0].Width = this.tagsList.Width;

            this.deleteSelectedTagButton.Enabled = false;
            this.addTagButton.Enabled            = false;

            this.CenterToParent();

            // register event handlers
            this.tagsList.SelectedIndexChanged += ((sender, args) =>
            {
                if (this.tagsList.SelectedItems.Count > 0)
                {
                    this.deleteSelectedTagButton.Enabled = true;
                }
                else
                {
                    this.deleteSelectedTagButton.Enabled = false;
                }
            });
            this.newTagText.TextChanged += ((sender, args) =>
            {
                if (string.IsNullOrWhiteSpace(this.newTagText.Text))
                {
                    this.addTagButton.Enabled = false;
                }
                else
                {
                    this.addTagButton.Enabled = true;
                }
            });
            this.addTagButton.Click += (async(sender, args) =>
            {
                // disable add and delete buttons
                this.addTagButton.Enabled = false;
                this.deleteSelectedTagButton.Enabled = false;

                string newTagName = this.newTagText.Text;

                try
                {
                    // check for existing tag
                    if (await this._service.ExistsWithName(newTagName))
                    {
                        MessageBox.Show("Tag: \"" + newTagName + "\" already exists.", "Manage Tags", MessageBoxButtons.OK, MessageBoxIcon.Warning);

                        // re-enable add and delete buttons
                        this.addTagButton.Enabled = true;
                        this.deleteSelectedTagButton.Enabled = true;

                        return;
                    }
                }
                catch (Exception ex)
                {
                    // something bad happened
                    MessageBox.Show("Error checking if tag \"" + newTagName + "\" already exists.", "Manage Tags", MessageBoxButtons.OK, MessageBoxIcon.Error);

                    // re-enable add and delete buttons
                    this.addTagButton.Enabled = true;
                    this.deleteSelectedTagButton.Enabled = true;

                    return;
                }

                try
                {
                    // add tag
                    await this._service.Add(new Tag {
                        Name = newTagName
                    });

                    // clear new tag field
                    this.newTagText.Clear();
                }
                catch (Exception ex)
                {
                    // something bad happened
                    MessageBox.Show("Error creating tag: " + ex.Message, "Manage Tags", MessageBoxButtons.OK, MessageBoxIcon.Error);

                    // re-enable add and delete buttons
                    this.addTagButton.Enabled = true;
                    this.deleteSelectedTagButton.Enabled = true;

                    return;
                }

                try
                {
                    // re-populate the list
                    await PopulateTags();
                }
                catch (Exception ex)
                {
                    // something bad happened
                    MessageBox.Show("Error reading tags: " + ex.Message, "Manage Tags", MessageBoxButtons.OK, MessageBoxIcon.Error);

                    // re-enable add and delete buttons
                    this.addTagButton.Enabled = true;
                    this.deleteSelectedTagButton.Enabled = true;

                    return;
                }

                // re-enable add and delete buttons
                this.addTagButton.Enabled = true;
                this.deleteSelectedTagButton.Enabled = true;

                TagsUpdated?.Invoke(this, args);
            });
            this.deleteSelectedTagButton.Click += (async(sender, args) =>
            {
                // disable add and delete buttons
                this.addTagButton.Enabled = false;
                this.deleteSelectedTagButton.Enabled = false;

                string selectedTag = this.tagsList.SelectedItems[0].SubItems[0].Text;

                try
                {
                    // delete tag
                    await this._service.DeleteByName(selectedTag);
                }
                catch (Exception ex)
                {
                    // something bad happened
                    MessageBox.Show("Error deleting tag ", "Manage Tags", MessageBoxButtons.OK, MessageBoxIcon.Error);

                    // re-enable add and delete buttons
                    this.addTagButton.Enabled = true;
                    this.deleteSelectedTagButton.Enabled = true;

                    return;
                }

                try
                {
                    // re-populate the list
                    await PopulateTags();
                }
                catch (Exception ex)
                {
                    // something bad happened
                    MessageBox.Show("Error reading tags: " + ex.Message, "Manage Tags", MessageBoxButtons.OK, MessageBoxIcon.Error);

                    // re-enable add and delete buttons
                    this.addTagButton.Enabled = true;
                    this.deleteSelectedTagButton.Enabled = true;

                    return;
                }

                TagsUpdated?.Invoke(this, args);
            });
        }
Exemplo n.º 6
0
 private void TagsSet() => TagsUpdated?.Invoke();