コード例 #1
0
        private DataClass GetDataClass(DataClass request)
        {
            var       id    = request?.Id;
            DataClass ret   = null;
            var       query = DocQuery.ActiveQuery ?? Execute;

            DocPermissionFactory.SetSelect <DataClass>(currentUser, "DataClass", request.Select);

            DocEntityDataClass entity = null;

            if (id.HasValue)
            {
                entity = DocEntityDataClass.Get(id.Value);
            }
            if (null == entity)
            {
                throw new HttpError(HttpStatusCode.NotFound, $"No DataClass found for Id {id.Value}");
            }

            if (!DocPermissionFactory.HasPermission(entity, currentUser, DocConstantPermission.VIEW))
            {
                throw new HttpError(HttpStatusCode.Forbidden, "You do not have VIEW permission for this route.");
            }

            ret = entity?.ToDto();
            return(ret);
        }
コード例 #2
0
        private DataProperty _AssignValues(DataProperty request, DocConstantPermission permission, Session session)
        {
            if (permission != DocConstantPermission.ADD && (request == null || request.Id <= 0))
            {
                throw new HttpError(HttpStatusCode.NotFound, $"No record");
            }

            if (permission == DocConstantPermission.ADD && !DocPermissionFactory.HasPermissionTryAdd(currentUser, "DataProperty"))
            {
                throw new HttpError(HttpStatusCode.Forbidden, "You do not have ADD permission for this route.");
            }

            request.Select = request.Select ?? new List <string>();

            DataProperty ret = null;

            request = _InitAssignValues <DataProperty>(request, permission, session);
            //In case init assign handles create for us, return it
            if (permission == DocConstantPermission.ADD && request.Id > 0)
            {
                return(request);
            }

            var cacheKey = GetApiCacheKey <DataProperty>(DocConstantModelName.DATAPROPERTY, nameof(DataProperty), request);

            //First, assign all the variables, do database lookups and conversions
            var pAutoCreateMissing   = request.AutoCreateMissing;
            var pChildren            = GetVariable <Reference>(request, nameof(request.Children), request.Children?.ToList(), request.ChildrenIds?.ToList());
            var pClass               = DocEntityDataClass.Get(request.Class?.Id, true, Execute) ?? DocEntityDataClass.Get(request.ClassId, true, Execute);
            var pDescription         = request.Description;
            var pDisplayName         = request.DisplayName;
            var pIsAllowAddInForm    = request.IsAllowAddInForm;
            var pIsAllowCreateInForm = request.IsAllowCreateInForm;
            var pIsAllowEditInForm   = request.IsAllowEditInForm;
            var pIsAllowFreeText     = request.IsAllowFreeText;
            var pIsAllowRemoveInForm = request.IsAllowRemoveInForm;
            var pIsAudited           = request.IsAudited;
            var pIsCompressed        = request.IsCompressed;
            var pIsDisplayInForm     = request.IsDisplayInForm;
            var pIsDisplayInGrid     = request.IsDisplayInGrid;
            var pIsEditColumn        = request.IsEditColumn;
            var pIsInsertOnly        = request.IsInsertOnly;
            var pIsJSON              = request.IsJSON;
            var pIsLazy              = request.IsLazy;
            var pIsNullOnUpgrade     = request.IsNullOnUpgrade;
            var pIsReadOnly          = request.IsReadOnly;
            var pIsRelationship      = request.IsRelationship;
            var pIsRequired          = request.IsRequired;
            var pIsRequiredInForm    = request.IsRequiredInForm;
            var pIsVirtual           = request.IsVirtual;
            var pJsonType            = request.JsonType;
            var pLookupTableEnum     = DocEntityLookupTableEnum.Get(request.LookupTableEnum);
            var pName      = request.Name;
            var pOrder     = request.Order;
            var pOwner     = DocEntityDataProperty.Get(request.Owner?.Id, true, Execute) ?? DocEntityDataProperty.Get(request.OwnerId, true, Execute);
            var pPrecision = request.Precision;
            var pRelationshipOnOwnerRemove  = request.RelationshipOnOwnerRemove;
            var pRelationshipOnTargetRemove = request.RelationshipOnTargetRemove;
            var pRelationshipPairTo         = DocEntityDataProperty.Get(request.RelationshipPairTo?.Id, true, Execute) ?? DocEntityDataProperty.Get(request.RelationshipPairToId, true, Execute);
            var pScale           = request.Scale;
            var pSetDefaultValue = request.SetDefaultValue;
            var pTab             = DocEntityDataTab.Get(request.Tab?.Id, true, Execute) ?? DocEntityDataTab.Get(request.TabId, true, Execute);
            var pTarget          = DocEntityDataClass.Get(request.Target?.Id, true, Execute) ?? DocEntityDataClass.Get(request.TargetId, true, Execute);
            var pTargetAlias     = request.TargetAlias;
            var pType            = request.Type;
            var pUIType          = request.UIType;
            var pArchived        = true == request.Archived;
            var pLocked          = request.Locked;

            var entity = InitEntity <DocEntityDataProperty, DataProperty>(request, permission, session);

            if (AllowPatchValue <DataProperty, bool>(request, DocConstantModelName.DATAPROPERTY, pArchived, permission, nameof(request.Archived), pArchived != entity.Archived))
            {
                entity.Archived = pArchived;
            }
            if (AllowPatchValue <DataProperty, bool>(request, DocConstantModelName.DATAPROPERTY, pAutoCreateMissing, permission, nameof(request.AutoCreateMissing), pAutoCreateMissing != entity.AutoCreateMissing))
            {
                entity.AutoCreateMissing = pAutoCreateMissing;
            }
            if (AllowPatchValue <DataProperty, DocEntityDataClass>(request, DocConstantModelName.DATAPROPERTY, pClass, permission, nameof(request.Class), pClass != entity.Class))
            {
                entity.Class = pClass;
            }
            if (AllowPatchValue <DataProperty, string>(request, DocConstantModelName.DATAPROPERTY, pDescription, permission, nameof(request.Description), pDescription != entity.Description))
            {
                entity.Description = pDescription;
            }
            if (AllowPatchValue <DataProperty, string>(request, DocConstantModelName.DATAPROPERTY, pDisplayName, permission, nameof(request.DisplayName), pDisplayName != entity.DisplayName))
            {
                entity.DisplayName = pDisplayName;
            }
            if (AllowPatchValue <DataProperty, bool>(request, DocConstantModelName.DATAPROPERTY, pIsAllowAddInForm, permission, nameof(request.IsAllowAddInForm), pIsAllowAddInForm != entity.IsAllowAddInForm))
            {
                entity.IsAllowAddInForm = pIsAllowAddInForm;
            }
            if (AllowPatchValue <DataProperty, bool>(request, DocConstantModelName.DATAPROPERTY, pIsAllowCreateInForm, permission, nameof(request.IsAllowCreateInForm), pIsAllowCreateInForm != entity.IsAllowCreateInForm))
            {
                entity.IsAllowCreateInForm = pIsAllowCreateInForm;
            }
            if (AllowPatchValue <DataProperty, bool>(request, DocConstantModelName.DATAPROPERTY, pIsAllowEditInForm, permission, nameof(request.IsAllowEditInForm), pIsAllowEditInForm != entity.IsAllowEditInForm))
            {
                entity.IsAllowEditInForm = pIsAllowEditInForm;
            }
            if (AllowPatchValue <DataProperty, bool>(request, DocConstantModelName.DATAPROPERTY, pIsAllowFreeText, permission, nameof(request.IsAllowFreeText), pIsAllowFreeText != entity.IsAllowFreeText))
            {
                entity.IsAllowFreeText = pIsAllowFreeText;
            }
            if (AllowPatchValue <DataProperty, bool>(request, DocConstantModelName.DATAPROPERTY, pIsAllowRemoveInForm, permission, nameof(request.IsAllowRemoveInForm), pIsAllowRemoveInForm != entity.IsAllowRemoveInForm))
            {
                entity.IsAllowRemoveInForm = pIsAllowRemoveInForm;
            }
            if (AllowPatchValue <DataProperty, bool>(request, DocConstantModelName.DATAPROPERTY, pIsAudited, permission, nameof(request.IsAudited), pIsAudited != entity.IsAudited))
            {
                entity.IsAudited = pIsAudited;
            }
            if (AllowPatchValue <DataProperty, bool>(request, DocConstantModelName.DATAPROPERTY, pIsCompressed, permission, nameof(request.IsCompressed), pIsCompressed != entity.IsCompressed))
            {
                entity.IsCompressed = pIsCompressed;
            }
            if (AllowPatchValue <DataProperty, bool>(request, DocConstantModelName.DATAPROPERTY, pIsDisplayInForm, permission, nameof(request.IsDisplayInForm), pIsDisplayInForm != entity.IsDisplayInForm))
            {
                entity.IsDisplayInForm = pIsDisplayInForm;
            }
            if (AllowPatchValue <DataProperty, bool>(request, DocConstantModelName.DATAPROPERTY, pIsDisplayInGrid, permission, nameof(request.IsDisplayInGrid), pIsDisplayInGrid != entity.IsDisplayInGrid))
            {
                entity.IsDisplayInGrid = pIsDisplayInGrid;
            }
            if (AllowPatchValue <DataProperty, bool>(request, DocConstantModelName.DATAPROPERTY, pIsEditColumn, permission, nameof(request.IsEditColumn), pIsEditColumn != entity.IsEditColumn))
            {
                entity.IsEditColumn = pIsEditColumn;
            }
            if (AllowPatchValue <DataProperty, bool>(request, DocConstantModelName.DATAPROPERTY, pIsInsertOnly, permission, nameof(request.IsInsertOnly), pIsInsertOnly != entity.IsInsertOnly))
            {
                entity.IsInsertOnly = pIsInsertOnly;
            }
            if (AllowPatchValue <DataProperty, bool>(request, DocConstantModelName.DATAPROPERTY, pIsJSON, permission, nameof(request.IsJSON), pIsJSON != entity.IsJSON))
            {
                entity.IsJSON = pIsJSON;
            }
            if (AllowPatchValue <DataProperty, bool>(request, DocConstantModelName.DATAPROPERTY, pIsLazy, permission, nameof(request.IsLazy), pIsLazy != entity.IsLazy))
            {
                entity.IsLazy = pIsLazy;
            }
            if (AllowPatchValue <DataProperty, bool>(request, DocConstantModelName.DATAPROPERTY, pIsNullOnUpgrade, permission, nameof(request.IsNullOnUpgrade), pIsNullOnUpgrade != entity.IsNullOnUpgrade))
            {
                entity.IsNullOnUpgrade = pIsNullOnUpgrade;
            }
            if (AllowPatchValue <DataProperty, bool>(request, DocConstantModelName.DATAPROPERTY, pIsReadOnly, permission, nameof(request.IsReadOnly), pIsReadOnly != entity.IsReadOnly))
            {
                entity.IsReadOnly = pIsReadOnly;
            }
            if (AllowPatchValue <DataProperty, bool>(request, DocConstantModelName.DATAPROPERTY, pIsRelationship, permission, nameof(request.IsRelationship), pIsRelationship != entity.IsRelationship))
            {
                entity.IsRelationship = pIsRelationship;
            }
            if (AllowPatchValue <DataProperty, bool>(request, DocConstantModelName.DATAPROPERTY, pIsRequired, permission, nameof(request.IsRequired), pIsRequired != entity.IsRequired))
            {
                entity.IsRequired = pIsRequired;
            }
            if (AllowPatchValue <DataProperty, bool>(request, DocConstantModelName.DATAPROPERTY, pIsRequiredInForm, permission, nameof(request.IsRequiredInForm), pIsRequiredInForm != entity.IsRequiredInForm))
            {
                entity.IsRequiredInForm = pIsRequiredInForm;
            }
            if (AllowPatchValue <DataProperty, bool>(request, DocConstantModelName.DATAPROPERTY, pIsVirtual, permission, nameof(request.IsVirtual), pIsVirtual != entity.IsVirtual))
            {
                entity.IsVirtual = pIsVirtual;
            }
            if (AllowPatchValue <DataProperty, string>(request, DocConstantModelName.DATAPROPERTY, pJsonType, permission, nameof(request.JsonType), pJsonType != entity.JsonType))
            {
                entity.JsonType = pJsonType;
            }
            if (AllowPatchValue <DataProperty, DocEntityLookupTableEnum>(request, DocConstantModelName.DATAPROPERTY, pLookupTableEnum, permission, nameof(request.LookupTableEnum), pLookupTableEnum != entity.LookupTableEnum))
            {
                entity.LookupTableEnum = pLookupTableEnum;
            }
            if (AllowPatchValue <DataProperty, string>(request, DocConstantModelName.DATAPROPERTY, pName, permission, nameof(request.Name), pName != entity.Name))
            {
                entity.Name = pName;
            }
            if (AllowPatchValue <DataProperty, int?>(request, DocConstantModelName.DATAPROPERTY, pOrder, permission, nameof(request.Order), pOrder != entity.Order))
            {
                if (null != pOrder)
                {
                    entity.Order = (int)pOrder;
                }
            }
            if (AllowPatchValue <DataProperty, DocEntityDataProperty>(request, DocConstantModelName.DATAPROPERTY, pOwner, permission, nameof(request.Owner), pOwner != entity.Owner))
            {
                entity.Owner = pOwner;
            }
            if (AllowPatchValue <DataProperty, int?>(request, DocConstantModelName.DATAPROPERTY, pPrecision, permission, nameof(request.Precision), pPrecision != entity.Precision))
            {
                entity.Precision = pPrecision;
            }
            if (AllowPatchValue <DataProperty, OnRemoveAction?>(request, DocConstantModelName.DATAPROPERTY, pRelationshipOnOwnerRemove, permission, nameof(request.RelationshipOnOwnerRemove), pRelationshipOnOwnerRemove != entity.RelationshipOnOwnerRemove))
            {
                entity.RelationshipOnOwnerRemove = pRelationshipOnOwnerRemove;
            }
            if (AllowPatchValue <DataProperty, OnRemoveAction?>(request, DocConstantModelName.DATAPROPERTY, pRelationshipOnTargetRemove, permission, nameof(request.RelationshipOnTargetRemove), pRelationshipOnTargetRemove != entity.RelationshipOnTargetRemove))
            {
                entity.RelationshipOnTargetRemove = pRelationshipOnTargetRemove;
            }
            if (AllowPatchValue <DataProperty, DocEntityDataProperty>(request, DocConstantModelName.DATAPROPERTY, pRelationshipPairTo, permission, nameof(request.RelationshipPairTo), pRelationshipPairTo != entity.RelationshipPairTo))
            {
                entity.RelationshipPairTo = pRelationshipPairTo;
            }
            if (AllowPatchValue <DataProperty, int?>(request, DocConstantModelName.DATAPROPERTY, pScale, permission, nameof(request.Scale), pScale != entity.Scale))
            {
                entity.Scale = pScale;
            }
            if (AllowPatchValue <DataProperty, string>(request, DocConstantModelName.DATAPROPERTY, pSetDefaultValue, permission, nameof(request.SetDefaultValue), pSetDefaultValue != entity.SetDefaultValue))
            {
                entity.SetDefaultValue = pSetDefaultValue;
            }
            if (AllowPatchValue <DataProperty, DocEntityDataTab>(request, DocConstantModelName.DATAPROPERTY, pTab, permission, nameof(request.Tab), pTab != entity.Tab))
            {
                entity.Tab = pTab;
            }
            if (AllowPatchValue <DataProperty, DocEntityDataClass>(request, DocConstantModelName.DATAPROPERTY, pTarget, permission, nameof(request.Target), pTarget != entity.Target))
            {
                entity.Target = pTarget;
            }
            if (AllowPatchValue <DataProperty, string>(request, DocConstantModelName.DATAPROPERTY, pTargetAlias, permission, nameof(request.TargetAlias), pTargetAlias != entity.TargetAlias))
            {
                entity.TargetAlias = pTargetAlias;
            }
            if (AllowPatchValue <DataProperty, DataType?>(request, DocConstantModelName.DATAPROPERTY, pType, permission, nameof(request.Type), pType != entity.Type))
            {
                if (null != pType)
                {
                    entity.Type = pType.Value;
                }
            }
            if (AllowPatchValue <DataProperty, UiType?>(request, DocConstantModelName.DATAPROPERTY, pUIType, permission, nameof(request.UIType), pUIType != entity.UIType))
            {
                entity.UIType = pUIType;
            }
            if (request.Locked && AllowPatchValue <DataProperty, bool>(request, DocConstantModelName.DATAPROPERTY, pArchived, permission, nameof(request.Locked), pLocked != entity.Locked))
            {
                entity.Archived = pArchived;
            }
            entity.SaveChanges(permission);

            var idsToInvalidate = new List <int>();

            idsToInvalidate.AddRange(PatchCollection <DataProperty, DocEntityDataProperty, Reference, DocEntityDataProperty>(request, entity, pChildren, permission, nameof(request.Children)));
            if (idsToInvalidate.Any())
            {
                idsToInvalidate.Add(entity.Id);
                DocCacheClient.RemoveByEntityIds(idsToInvalidate);
                DocCacheClient.RemoveSearch(DocConstantModelName.DATAPROPERTY);
            }

            entity.SaveChanges(permission);
            DocPermissionFactory.SetSelect <DataProperty>(currentUser, nameof(DataProperty), request.Select);
            ret = entity.ToDto();

            var cacheExpires = DocResources.Metadata.GetCacheExpiration(DocConstantModelName.DATAPROPERTY);

            DocCacheClient.Set(key: cacheKey, value: ret, entityId: request.Id, entityType: DocConstantModelName.DATAPROPERTY, cacheExpires);

            return(ret);
        }
コード例 #3
0
ファイル: DataTabService.cs プロジェクト: crfroehlich/codegen
        private DataTab _AssignValues(DataTab request, DocConstantPermission permission, Session session)
        {
            if (permission != DocConstantPermission.ADD && (request == null || request.Id <= 0))
            {
                throw new HttpError(HttpStatusCode.NotFound, $"No record");
            }

            if (permission == DocConstantPermission.ADD && !DocPermissionFactory.HasPermissionTryAdd(currentUser, "DataTab"))
            {
                throw new HttpError(HttpStatusCode.Forbidden, "You do not have ADD permission for this route.");
            }

            request.Select = request.Select ?? new List <string>();

            DataTab ret = null;

            request = _InitAssignValues <DataTab>(request, permission, session);
            //In case init assign handles create for us, return it
            if (permission == DocConstantPermission.ADD && request.Id > 0)
            {
                return(request);
            }

            var cacheKey = GetApiCacheKey <DataTab>(DocConstantModelName.DATATAB, nameof(DataTab), request);

            //First, assign all the variables, do database lookups and conversions
            var pClass       = DocEntityDataClass.Get(request.Class?.Id, true, Execute) ?? DocEntityDataClass.Get(request.ClassId, true, Execute);
            var pDescription = request.Description;
            var pName        = request.Name;
            var pOrder       = request.Order;
            var pArchived    = true == request.Archived;
            var pLocked      = request.Locked;

            var entity = InitEntity <DocEntityDataTab, DataTab>(request, permission, session);

            if (AllowPatchValue <DataTab, bool>(request, DocConstantModelName.DATATAB, pArchived, permission, nameof(request.Archived), pArchived != entity.Archived))
            {
                entity.Archived = pArchived;
            }
            if (AllowPatchValue <DataTab, DocEntityDataClass>(request, DocConstantModelName.DATATAB, pClass, permission, nameof(request.Class), pClass != entity.Class))
            {
                entity.Class = pClass;
            }
            if (AllowPatchValue <DataTab, string>(request, DocConstantModelName.DATATAB, pDescription, permission, nameof(request.Description), pDescription != entity.Description))
            {
                entity.Description = pDescription;
            }
            if (AllowPatchValue <DataTab, string>(request, DocConstantModelName.DATATAB, pName, permission, nameof(request.Name), pName != entity.Name))
            {
                entity.Name = pName;
            }
            if (AllowPatchValue <DataTab, int?>(request, DocConstantModelName.DATATAB, pOrder, permission, nameof(request.Order), pOrder != entity.Order))
            {
                if (null != pOrder)
                {
                    entity.Order = (int)pOrder;
                }
            }
            if (request.Locked && AllowPatchValue <DataTab, bool>(request, DocConstantModelName.DATATAB, pArchived, permission, nameof(request.Locked), pLocked != entity.Locked))
            {
                entity.Archived = pArchived;
            }
            entity.SaveChanges(permission);

            var idsToInvalidate = new List <int>();

            if (idsToInvalidate.Any())
            {
                idsToInvalidate.Add(entity.Id);
                DocCacheClient.RemoveByEntityIds(idsToInvalidate);
                DocCacheClient.RemoveSearch(DocConstantModelName.DATATAB);
            }

            entity.SaveChanges(permission);
            DocPermissionFactory.SetSelect <DataTab>(currentUser, nameof(DataTab), request.Select);
            ret = entity.ToDto();

            var cacheExpires = DocResources.Metadata.GetCacheExpiration(DocConstantModelName.DATATAB);

            DocCacheClient.Set(key: cacheKey, value: ret, entityId: request.Id, entityType: DocConstantModelName.DATATAB, cacheExpires);

            return(ret);
        }