Ejemplo n.º 1
0
        private void Save()
        {
            try
            {
                if (string.IsNullOrEmpty(Name))
                {
                    throw new Exception("Name is empty");
                }

                switch (type)
                {
                case ItemType.Author:
                    Author author = item as Author;
                    if (author.Name == Name)
                    {
                        Close();
                        return;
                    }

                    if (ds.GetAuthors().Where(x => x.Name == Name).FirstOrDefault() != null)
                    {
                        throw new Exception(Name + " already exists");
                    }

                    author.Name = Name;
                    ds.UpdateAuthor(author);
                    break;

                case ItemType.Tag:
                    Tag tag = item as Tag;
                    if (tag.TagName == Name)
                    {
                        Close();
                        return;
                    }

                    if (ds.GetTags().Where(x => x.TagName == Name).FirstOrDefault() != null)
                    {
                        throw new Exception(Name + " already exists");
                    }

                    tag.TagName = Name;
                    ds.UpdateTag(tag);

                    break;
                }

                Close();
            }
            catch (Exception e)
            {
                MessageBoxFactory.ShowError(e);
            }
        }
Ejemplo n.º 2
0
        public void Save()
        {
            try
            {
                bool isUpdate = existingQuote != null;

                Quote qt = isUpdate ? existingQuote : new DAO.Quote();
                qt.Text = Quote;

                var author = ds.GetAuthors(Author).FirstOrDefault();
                if (author == null)
                {
                    qt.Author = ds.CreateAuthor(new Author()
                    {
                        Name = Author
                    });
                }
                else
                {
                    qt.Author = author;
                }

                qt.Text = Quote;
                //qt.Rating = Rating;

                if (!isUpdate)
                {
                    qt = ds.InsertQuote(qt);
                }
                else
                {
                    ds.UpdateQuote(qt);
                }

                //Tags
                if (TagsChanged)
                {
                    ds.UpdateTags(qt, TagsList);
                }


                window.Close();
            }
            catch (Exception e)
            {
                MessageBoxFactory.ShowError(e);
            }
        }
Ejemplo n.º 3
0
        private void RefreshList()
        {
            int id = 0;

            if (SelectedListItem != null)
            {
                var author = SelectedListItem as Author;
                if (author != null)
                {
                    id = author.ID;
                }
                else
                {
                    var tag = SelectedListItem as Tag;
                    if (tag != null)
                    {
                        id = tag.ID;
                    }
                }
            }

            switch (selectedList)
            {
            case Author:

                var authors = dataStore.GetAuthors();     //.OrderBy(x => x.Name);

                ListItems.Clear();
                foreach (var a in authors)
                {
                    ListItems.Add(a);
                }

                ListPath = "Name";

                if (id != 0)
                {
                    var author = ListItems.FirstOrDefault(x => ((Author)x).ID == id);
                    SelectedListItem = author;
                }
                break;

            case Tag:
                var tags = dataStore.GetTags();

                ListItems.Clear();
                foreach (var t in tags)
                {
                    ListItems.Add(t);
                }

                ListPath = "TagName";

                if (id != 0)
                {
                    var tag = ListItems.FirstOrDefault(x => ((Tag)x).ID == id);
                    SelectedListItem = tag;
                }
                break;
            }
        }