public bool ChangeTagRelation(RelationUpdateModel update) { if (!(DbContext.AnnotationTagInstances.Any(l => l.Id == update.SourceId) && DbContext.AnnotationTagInstances.Any(l => l.Id == update.TargetId))) { return(false); } var rule = DbContext.AnnotationTagRelations.Single(rel => true); if (update.NewTitle != null) { rule.Title = update.NewTitle; } if (update.Description != null) { rule.Description = update.Description; } if (update.ArrowStyle != null) { rule.ArrowStyle = update.ArrowStyle; } if (update.Color != null) { rule.Color = update.Color; } DbContext.SaveChanges(); return(true); }
public void PutTagRelationTest() { var expectedColor = "oldColor"; _tester.Relation12.Color = expectedColor; var original = RelationFormModelFromRelation(_tester.Relation12); var updated = new RelationUpdateModel() { SourceId = _tester.Relation12.SourceTag.Id, TargetId = _tester.Relation12.TargetTag.Id, Title = original.Title, NewTitle = "changed" }; _tester.TestController() .WithDbContext(dbContext => dbContext .WithSet <AnnotationTagInstance>(db => db.AddRange(_tester.TagInstance1, _tester.TagInstance2)) .WithSet <AnnotationTagInstanceRelation>(db => db.Add(_tester.Relation12)) ) .Calling(c => c.PutTagInstanceRelation(updated)) .ShouldHave() .DbContext(db => db.WithSet <AnnotationTagInstanceRelation>(relations => relations.Any(actual => actual.SourceTagId == updated.SourceId && actual.TargetTagId == updated.TargetId && actual.Title == updated.Title && actual.Color == expectedColor // color should not change as it was not set in the model ) )) .AndAlso() .ShouldReturn() .Ok(); }
private static bool TagRulesEqual(AnnotationTagRelationRule actual, RelationUpdateModel expected) { return(actual.SourceTagId == expected.SourceId && actual.TargetTagId == expected.TargetId && actual.Title == expected.Title && actual.Description == expected.Description && actual.Color == expected.Color && actual.ArrowStyle == expected.ArrowStyle); }
public void PutTagRelationTest403() { var model = RelationFormModelFromRelation(_tester.Relation12); var update = new RelationUpdateModel() { SourceId = _tester.Relation12.SourceTag.Id, TargetId = _tester.Relation12.TargetTag.Id, Title = model.Title, NewTitle = "changed" }; _tester.TestController(_tester.Student.UId) // --> log in as student .Calling(c => c.PutTagInstanceRelation(update)) .ShouldReturn() .Forbid(); }
public bool ChangeTagRelationRule(RelationUpdateModel update) { if (!(DbContext.AnnotationTags.Any(l => l.Id == update.SourceId) && DbContext.AnnotationTags.Any(l => l.Id == update.TargetId))) { return(false); } var rule = DbContext.TagRelationRules.Single(EqualsTagRelationRule(update)); rule.Title = update.NewTitle; rule.Description = update.Description; rule.ArrowStyle = update.ArrowStyle; rule.Color = update.Color; DbContext.SaveChanges(); return(true); }
public IActionResult PutTagRelationRule([FromBody] RelationUpdateModel update) { if (!_annotationPermissions.IsAllowedToEditTags(User.Identity.GetUserIdentity())) { return(Forbid()); } try { if (_tagManager.ChangeTagRelationRule(update)) { return(Ok()); } return(NotFound()); } catch (InvalidOperationException) { return(NotFound()); } }
public void PutTagRelationRuleTest() { var original = RelationFormModelFromRelationRule(_tester.RelationRule12); var update = new RelationUpdateModel() { SourceId = _tester.RelationRule12.SourceTagId, TargetId = _tester.RelationRule12.TargetTagId, Title = original.Title, Description = "my relation", Color = "schwarzgelb", ArrowStyle = "dotted" }; _tester.TestControllerWithMockData() .Calling(c => c.PutTagRelationRule(update)) .ShouldHave() .DbContext(db => db.WithSet <AnnotationTagRelationRule>(relations => relations.Any(actual => TagRulesEqual(actual, update)) )) .AndAlso() .ShouldReturn() .Ok(); }
private static Expression <Func <AnnotationTagRelationRule, bool> > EqualsTagRelationRule(RelationUpdateModel original) { return(r => r.SourceTagId == original.SourceId && r.TargetTagId == original.TargetId && r.Title == original.Title); }