public virtual EntityResult AssociateTopic(int parentId, int childId) { // TODO throw errors if (!DbContext.Topics.Any(t => t.Id == childId)) { return(EntityResult.Error("Child not Found")); } if (!DbContext.Topics.Any(t => t.Id == parentId)) { return(EntityResult.Error("Parent not Found")); } if (DbContext.AssociatedTopics.Any(at => at.ChildTopicId == childId && at.ParentTopicId == parentId)) { return(EntityResult.Error("Allready exists")); } var relation = new AssociatedTopic() { ChildTopicId = childId, ParentTopicId = parentId }; DbContext.Add(relation); DbContext.SaveChanges(); return(EntityResult.Successfull(null)); }
public TopicsControllerAssociatedTopicsTest() { _tester = new ControllerTester <TopicsController>(); AssociatedTopic = new AssociatedTopic { ParentTopicId = _tester.TopicOne.Id, ChildTopicId = _tester.TopicTwo.Id }; }