Ejemplo n.º 1
0
        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));
        }
Ejemplo n.º 2
0
 public TopicsControllerAssociatedTopicsTest()
 {
     _tester         = new ControllerTester <TopicsController>();
     AssociatedTopic = new AssociatedTopic
     {
         ParentTopicId = _tester.TopicOne.Id,
         ChildTopicId  = _tester.TopicTwo.Id
     };
 }