Пример #1
0
        public SubToSuperRelationshipDTO ToSubToSuperRelationshipDTO(SubToSuperRelationshipType item, RelationshipDTO baseRelationship = null)
        {
            BizRelationship biz = new MyModelManager.BizRelationship();

            if (baseRelationship == null)
            {
                baseRelationship = biz.ToRelationshipDTO(item.RelationshipType.Relationship);
            }
            Mapper.Initialize(cfg => cfg.CreateMap <RelationshipDTO, SubToSuperRelationshipDTO>());
            var result = AutoMapper.Mapper.Map <RelationshipDTO, SubToSuperRelationshipDTO>(baseRelationship);

            result.ISARelationship = ToISARelationshipDTO(item.ISARelationship);
            //  result.DeterminerColumnValue = item.RelationshipType.Relationship.Relationship2.RelationshipType.SuperToSubRelationshipType.DeterminerColumnValue;
            //  result.DeterminerColumnID = item.RelationshipType.Relationship.Relationship2.RelationshipType.SuperToSubRelationshipType.DeterminerColumnID ?? 0;

            foreach (var val in item.RelationshipType.Relationship.Relationship2.RelationshipType.SuperToSubRelationshipType.SuperToSubDeterminerValue)
            {
                result.DeterminerColumnValues.Add(new SuperToSubDeterminerValueDTO()
                {
                    ID = val.ID, Value = val.DeterminerValue
                });
            }
            if (item.RelationshipType.Relationship.Relationship2.RelationshipType.SuperToSubRelationshipType.SuperEntityDeterminerColumnID != null)
            {
                BizColumn bizColumn = new BizColumn();
                result.SuperEntityDeterminerColumnID = item.RelationshipType.Relationship.Relationship2.RelationshipType.SuperToSubRelationshipType.SuperEntityDeterminerColumnID.Value;
                result.SuperEntityDeterminerColumn   = bizColumn.GetColumn(result.SuperEntityDeterminerColumnID, true);
            }
            return(result);
        }
        private void SavePermission(MyProjectEntities context, PermissionDTO permission)
        {
            if (permission.SecurityObjectCategory == DatabaseObjectCategory.Column)
            {
                if (permission.Actions.Any(x => x == SecurityAction.NoAccess))
                {
                    BizColumn bizColumn = new BizColumn();
                    var       column    = bizColumn.GetColumn(permission.SecurityObjectID, true);
                    if (column.PrimaryKey)
                    {
                        throw new Exception("امکان تعیین عدم دسترسی به ستونهای کلید اصلی وجود ندارد");
                    }
                }
            }

            Permission dbItem = null;

            if (permission.ID != 0)
            {
                dbItem = context.Permission.First(x => x.ID == permission.ID);
            }
            else
            {
                dbItem = new Permission();
                context.Permission.Add(dbItem);
            }

            dbItem.SecurityObjectID  = permission.SecurityObjectID;
            dbItem.SecuritySubjectID = permission.SecuritySubjectID;
            //dbItem.SecurityObjectType = (short)permission.SecurityObjectCategory;

            while (dbItem.Permission_Action.Any())
            {
                context.Permission_Action.Remove(dbItem.Permission_Action.First());
            }

            foreach (var item in permission.Actions)
            {
                Permission_Action action = new Permission_Action();
                action.Action = item.ToString();
                dbItem.Permission_Action.Add(action);
            }
        }