Ejemplo n.º 1
0
        public void Add(Bookmark.Core.Bookmark bookmark, string tags)
        {
            var existingBookmark = this.dataContext.Bookmarks.SingleOrDefault(b => b.Article.URL == bookmark.Article.URL);

            if (existingBookmark == null)
            {
                this.dataContext.Bookmarks.Add(bookmark);

                // add tags logic, *refactor*, chain of responsibility?,
                foreach (var tag in tags.Split(','))
                {
                    // validate if the tag already exist in the database
                    var existingTag = this.dataContext.Tags.SingleOrDefault(t => t.Text == tag);
                    if (existingTag != null)
                    {
                        bookmark.Tags.Add(existingTag);
                    }
                    else
                    {
                        bookmark.Tags.Add(new Core.Tag {
                            Text = tag
                        });
                    }
                }
            }
            else
            {
                // to do: create exception (Custom exception, or use invalid operation exception, bookmark with same url already exist)
                // or move the validation logic to another service, BookmarkDuplicateValidator???
                // throw error message in front-end
            }
        }
Ejemplo n.º 2
0
 public void Delete(Bookmark.Core.Bookmark bookmark)
 {
     this.dataContext.Bookmarks.Remove(bookmark);
 }