public KnowledgeBaseArticle KnowledgeBaseArticleCommunicationViewModel2KnowledgeBaseArticle(CommunicationItemKnowledgeBaseArticleViewModel viewModel)
		{
			KnowledgeBaseArticle retVal = new KnowledgeBaseArticle
			{
				AuthorName = viewModel.AuthorName,
				Body = viewModel.Body,
				Title = viewModel.Title,

			};
			if (viewModel.Id != null)
				retVal.KnowledgeBaseArticleId = viewModel.Id;

			return retVal;
		}
		public CommunicationItemKnowledgeBaseArticleViewModel KnowledgeBaseArticle2KnowledgeBaseArticleCommunicationViewModel(KnowledgeBaseArticle item)
		{

			CommunicationItemKnowledgeBaseArticleViewModel retVal = new CommunicationItemKnowledgeBaseArticleViewModel
			{
				//LastModified = item.LastModified,
				//Created = item.Created,
				AuthorId = item.AuthorId,
				AuthorName = item.AuthorName,
				Body = item.Body,
				Title = item.Title,
				Id = item.KnowledgeBaseArticleId
			};
			if (item.Attachments != null)
			{
				foreach (var attachment in item.Attachments)
				{
					retVal.Attachments.Add(Attachment2CommunicationAttachment(attachment));
				}
			}

			return retVal;

		}
		public void KnowledgeBaseGroup_AddArticle()
		{
			// create group and arcicle KnowledgeBaseGroups
			var g = new KnowledgeBaseGroup() { Name = "g", Title = "g" };
			var a = new KnowledgeBaseArticle() { Title = "a", Body = "a" };
			string g_Id = g.KnowledgeBaseGroupId;
			string a_Id = a.KnowledgeBaseArticleId;

			var repository = GetRepository();

			EndTestAction.Add((() =>
			{
				repository.Remove(a);
				repository.Remove(g);
				repository.UnitOfWork.Commit();
			}));


			// add created items to DB
			repository.Attach(g);
			repository.Add(g);
			repository.UnitOfWork.Commit();


			a.GroupId = g.KnowledgeBaseGroupId;
			repository.Attach(a);
			repository.Add(a);
			repository.UnitOfWork.Commit();

			//KnowledgeBaseGroup is saved correctly?
			var a_check = repository.KnowledgeBaseArticles.Where(x => x.KnowledgeBaseArticleId == a_Id).SingleOrDefault();
			var g_check = repository.KnowledgeBaseGroups.Where(x => x.KnowledgeBaseGroupId == g_Id).SingleOrDefault();

			Assert.IsTrue(g_check != null && g_check.KnowledgeBaseGroupId == g_Id);
			Assert.IsTrue(a_check != null && a_check.KnowledgeBaseArticleId == a_Id && a_check.GroupId == g_check.KnowledgeBaseGroupId);
		}
		public void AddKnowledgeBaseArticleToGroupTest()
		{
			var client = GetRepository();

			var groupFromDb = client.KnowledgeBaseGroups.Where(g => g.KnowledgeBaseGroupId == "ccb57007-dac9-4d8d-8bf4-47f2c3df3c3a")
				.Expand(g => g.Parent).FirstOrDefault();

			Assert.IsNotNull(groupFromDb);
			Assert.IsNotNull(groupFromDb.Parent);

			client.Attach(groupFromDb);


			var articleToParent = new KnowledgeBaseArticle();
			articleToParent.Title = "articleToParent";
			articleToParent.GroupId = groupFromDb.Parent.KnowledgeBaseGroupId;

			var articleToGroup = new KnowledgeBaseArticle();
			articleToGroup.Title = "artickeToGroup";
			articleToGroup.GroupId = groupFromDb.KnowledgeBaseGroupId;

			client.Add(articleToParent);
			client.Add(articleToGroup);

			client.UnitOfWork.Commit();

		}
		private void SyncAttach(KnowledgeBaseArticle original, KnowledgeBaseArticle article)
		{
			var repository = _repositoryFactory.GetRepositoryInstance();
			// removing attachments
			if (original != null)
			{
				foreach (var attach in original.Attachments)
				{
					if (article != null || article.Attachments == null || !article.Attachments.Any(x => (x.AttachmentId == attach.AttachmentId)))
					{
						repository.Attach(attach);
						repository.Remove(attach);
					}
				}
			}

			// appending attachments
			if (article != null)
			{
				foreach (var attach in article.Attachments)
				{
					if (original == null || original.Attachments == null || !original.Attachments.Any(x => (x.AttachmentId == attach.AttachmentId)))
					{
						attach.CommunicationItemId = article.KnowledgeBaseArticleId;
						repository.Attach(attach);
						repository.Add(attach);
					}
				}
			}
			int i = repository.UnitOfWork.Commit();
		}