public static UserBookmarkResource Create(UserBookmark userBookmark)
        {
            var tags = userBookmark.UserBookmarkTags.Select(ubt => ubt.Tag);

            return new UserBookmarkResource
                       {
                           Username = userBookmark.User.Username,
                           PageUrl = userBookmark.Bookmark.Url,
                           PageTitle = string.IsNullOrEmpty(userBookmark.CustomTitle) ? userBookmark.Bookmark.Title : userBookmark.CustomTitle,
                           Tags = string.Join(" ", tags.ToArray())
                       };
        }
        // TODO: move most of this and similar business/domain logic heavy bits into separate service class(es)
        // TODO: look at this, linq2sql is crap, switch to nhibernate or something
        public OperationResult Post(string username, CreateUserBookmarkResource userBookmarkResource)
        {
            var user = _userRepository.GetByUsername(username);
            if (user == null)
                return new OperationResult.NotFound { Description = "User not found with username: " + username };

            var bookmark = _bookmarkRepository.FindByUrl(userBookmarkResource.PageUrl);
            if (bookmark == null)
            {
                bookmark = new Bookmark
                               {
                                   Title = userBookmarkResource.PageTitle,
                                   Url = userBookmarkResource.PageUrl
                               };
                _bookmarkRepository.SaveOrUpdate(bookmark);
            }

            var userBookmark = new UserBookmark
                                   {
                                       Bookmark = bookmark,
                                       User = user,
                                   };

            foreach (var tag in userBookmarkResource.Tags.Split(' '))
            {
                userBookmark.UserBookmarkTags.Add(new UserBookmarkTag {Tag = tag.Trim(), UserBookmark = userBookmark});
            }

            user.UserBookmarks.Add(userBookmark);

            _userRepository.SaveOrUpdate(user);

            return new OperationResult.SeeOther
                       {
                           RedirectLocation = _uriResolver.CreateUriFor(new UserResource {Username = username})
                       };
        }
		private void detach_UserBookmarks(UserBookmark entity)
		{
			this.SendPropertyChanging();
			entity.User = null;
		}
		private void attach_UserBookmarks(UserBookmark entity)
		{
			this.SendPropertyChanging();
			entity.User = this;
		}
 partial void DeleteUserBookmark(UserBookmark instance);
 partial void UpdateUserBookmark(UserBookmark instance);
 partial void InsertUserBookmark(UserBookmark instance);