public ActionResult CreateAndAddRelation(long relationTypeId, long entityId, string relatedEntityId) { TEntity entity = Model.GetEntity(entityId); if (entity == null || !entity.IsEditable) { return(RedirectToAction("Index")); } // TODO better check of relationTypeId validity. RelationModel relationModel = RemoteFacade.Instance.GetModel <RelationModel> (db); TypedRelations relations = relationModel.GetRelations(relationTypeId, entity); if (relations == null) { return(RedirectToAction("Index")); } return(View(CreateAndAddRelationView, new CreateAndAddRelationViewModel() { Entity = entity, RelationTypeId = relationTypeId, NewEntity = relationModel.GetNewObjectiveEntity(relations.RelationType, relatedEntityId) })); }
public ActionResult PerformCreateAndAddRelation(long relationTypeId, long entityId, FormCollection formCollection) { TEntity entity = Model.GetEntity(entityId); if (entity == null || !entity.IsEditable) { return(RedirectToAction("Index")); } // TODO better check of relationTypeId validity. RelationModel relationModel = RemoteFacade.Instance.GetModel <RelationModel> (db); TypedRelations relations = relationModel.GetRelations(relationTypeId, entity); if (relations == null) { return(RedirectToAction("Index")); } Entity newEntity = relationModel.GetNewObjectiveEntity(relations.RelationType, String.Empty); TryUpdateModel(relations.RelationType.ObjectiveEntityType, newEntity, "NewEntity"); if (ModelState.IsValid) { newEntity = RemoteFacade.Instance.GetEntityModel(newEntity.GetType(), db).AddNewEntity(newEntity); relationModel.AddRelation(relationTypeId, entity, newEntity.Id); return(RedirectToAction("Relations", new { RelationTypeId = relationTypeId, EntityId = entityId })); } return(View(CreateAndAddRelationView, new CreateAndAddRelationViewModel() { Entity = entity, RelationTypeId = relationTypeId, NewEntity = (Entity)newEntity })); }
public ActionResult Relations(long relationTypeId, long entityId) { TEntity entity = Model.GetEntity(entityId); if (entity == null) { return(RedirectToAction("Index")); } TypedRelations relations = RemoteFacade.Instance.GetModel <RelationModel> (db).GetRelations(relationTypeId, entity); if (relations == null) { return(RedirectToAction("Index")); } return(View(RelationsView, new EntityRelationsViewModel() { Entity = entity, Relations = relations })); }