Ejemplo n.º 1
0
        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
            }));
        }
Ejemplo n.º 2
0
        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)
            }));
        }