public void PostLayerRelationRuleTest403() { var expected = _layerRelationRule; var model = new LayerRelationRuleFormModel() { SourceLayerId = expected.SourceLayerId, TargetLayerId = expected.TargetLayerId, Color = expected.Color, ArrowStyle = expected.ArrowStyle }; MyMvc .Controller <AnnotationController>() .WithAuthenticatedUser(user => user.WithClaim("Id", _student.Id.ToString())) .WithDbContext(dbContext => dbContext .WithSet <User>(db => db.Add(_student)) .WithSet <Layer>(db => db.AddRange(expected.SourceLayer, expected.TargetLayer)) ) .Calling(c => c.PostLayerRelationRule(model)) .ShouldHave() .DbContext(db => db.WithSet <LayerRelationRule>(relations => !relations.Any(actual => actual.Equals(expected)) )) .AndAlso() .ShouldReturn() .Forbid(); }
public void PostLayerRelationRuleTest() { var expected = _layerRelationRule; var model = new LayerRelationRuleFormModel() { SourceLayerId = expected.SourceLayerId, TargetLayerId = expected.TargetLayerId, Color = expected.Color, ArrowStyle = expected.ArrowStyle }; MyMvc .Controller <AnnotationController>() .WithAuthenticatedUser(user => user.WithClaim("Id", _supervisor.Id.ToString())) .WithDbContext(dbContext => dbContext .WithSet <User>(db => db.Add(_supervisor)) .WithSet <Layer>(db => db.AddRange(_layerRelationRule.SourceLayer, _layerRelationRule.TargetLayer)) ) .Calling(c => c.PostLayerRelationRule(model)) .ShouldHave() .DbContext(db => db.WithSet <LayerRelationRule>(relations => relations.Any(actual => expected.SourceLayerId == actual.SourceLayerId && expected.TargetLayerId == actual.TargetLayerId && expected.Color == actual.Color && expected.ArrowStyle == actual.ArrowStyle ) )) .AndAlso() .ShouldReturn() .Ok(); }
internal bool ChangeLayerRelationRule(int sourceId, int targetId, LayerRelationRuleFormModel model) { if (!(DbContext.Layers.Any(l => l.Id == sourceId) || DbContext.Layers.Any(l => l.Id == targetId))) { return(false); } var rule = DbContext.LayerRelationRules.Single(r => r.SourceLayerId == sourceId && r.TargetLayerId == targetId); rule.ArrowStyle = model.ArrowStyle; rule.Color = model.Color; DbContext.SaveChanges(); Console.Write("changed relation:" + model.SourceLayerId + model.TargetLayerId); return(true); }
internal bool AddLayerRelationRule(LayerRelationRuleFormModel model) { if (!(DbContext.Layers.Any(l => l.Id == model.SourceLayerId) || DbContext.Layers.Any(l => l.Id == model.TargetLayerId))) { return(false); } var rule = new LayerRelationRule() { SourceLayerId = model.SourceLayerId, TargetLayerId = model.TargetLayerId, Color = model.Color, ArrowStyle = model.ArrowStyle }; DbContext.LayerRelationRules.Add(rule); DbContext.SaveChanges(); Console.Write("added relation:" + model.SourceLayerId + model.TargetLayerId); return(true); }
public IActionResult PostLayerRelationRule([FromBody] LayerRelationRuleFormModel model) { if (!_annotationPermissions.IsAllowedToCreateRelationRules(User.Identity.GetUserId())) { return(Forbid()); } try { if (_tagManager.AddLayerRelationRule(model)) { return(Ok()); } return(BadRequest()); } catch (InvalidOperationException) { return(NotFound()); } }
public IActionResult PutLayerRelationRule([FromQuery] int sourceId, [FromQuery] int targetId, [FromBody] LayerRelationRuleFormModel model) { if (!_annotationPermissions.IsAllowedToCreateRelationRules(User.Identity.GetUserId())) { return(Forbid()); } try { if (_tagManager.ChangeLayerRelationRule(sourceId, targetId, model)) { return(Ok()); } return(BadRequest()); } catch (InvalidOperationException) { return(BadRequest()); } }