public ActionResult MainEntityList(string type, object id, List <string> entities)
 {
     if (entities != null)
     {
         var objectType   = ContextProvider.GetTypeByTableName(type);
         var objectId     = LinqToSqlUtils.CorrectPKType(id, objectType);
         var oldRelations = SiteObjectRelationRepository
                            .GetAll(x => x.Object_ID == objectId && x.ObjectType == type).ToList();
         foreach (var entity in entities)
         {
             var parts      = entity.Split(';');
             var tableName  = parts[0];
             var entityType = ContextProvider.GetTypeByTableName(tableName);
             var entityId   = LinqToSqlUtils.CorrectPKType(parts[1], entityType);
             var relation   = new SiteObjectRelation {
                 Object_ID          = objectId,
                 ObjectType         = type,
                 RelationObject_ID  = entityId,
                 RelationObjectType = tableName
             };
             if (!oldRelations.Any(x => x.RelationObject_ID.Equals(relation.RelationObject_ID) &&
                                   x.RelationObjectType == relation.RelationObjectType))
             {
                 SiteObjectRelationRepository.Insert(relation);
             }
         }
         SiteObjectRelationRepository.SubmitChanges();
     }
     return(Json("ok"));
 }
        public virtual ActionResult DeleteAll(string tableName, object id)
        {
            var entityType = ContextProvider.GetTypeByTableName(tableName);
            var relations  = SiteObjectRelationRepository.GetAll(x => x.ObjectType == tableName && x.Object_ID ==
                                                                 LinqToSqlUtils.CorrectPKType(id, entityType));

            foreach (var relation in relations)
            {
                SiteObjectRelationRepository.Delete(relation);
            }
            SiteObjectRelationRepository.SubmitChanges();
            return(null);
        }
        public ActionResult UpdateRelationSorting(List <long> relationIds)
        {
            var relations = SiteObjectRelationRepository.GetAll(
                x => relationIds.Contains(x.SiteObjectRelation_ID)).ToList();

            for (short i = 0; i < relationIds.Count; i++)
            {
                var relationId = relationIds[i];
                var relation   = relations.FirstOrDefault(x => x.
                                                          SiteObjectRelation_ID == relationId);
                if (relation != null)
                {
                    relation.RelationOrder = i;
                }
            }

            SiteObjectRelationRepository.SubmitChanges();

            return(Json("ok"));
        }