Ejemplo n.º 1
0
        private LookupTableEnum GetLookupTableEnum(LookupTableEnum request)
        {
            var             id    = request?.Id;
            LookupTableEnum ret   = null;
            var             query = DocQuery.ActiveQuery ?? Execute;

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

            DocEntityLookupTableEnum entity = null;

            if (id.HasValue)
            {
                entity = DocEntityLookupTableEnum.Get(id.Value);
            }
            if (null == entity)
            {
                throw new HttpError(HttpStatusCode.NotFound, $"No LookupTableEnum 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);
        }
Ejemplo n.º 2
0
        public void Delete(LookupTableEnum request)
        {
            using (Execute)
            {
                Execute.Run(ssn =>
                {
                    if (!(request?.Id > 0))
                    {
                        throw new HttpError(HttpStatusCode.NotFound, $"No Id provided for delete.");
                    }

                    var en = DocEntityLookupTableEnum.Get(request?.Id);
                    if (null == en)
                    {
                        throw new HttpError(HttpStatusCode.NotFound, $"No LookupTableEnum could be found for Id {request?.Id}.");
                    }
                    if (en.IsRemoved)
                    {
                        return;
                    }

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

                    en.Remove();

                    DocCacheClient.RemoveSearch(DocConstantModelName.LOOKUPTABLEENUM);
                    DocCacheClient.RemoveById(request.Id);
                });
            }
        }
Ejemplo n.º 3
0
        public LookupTableEnum Post(LookupTableEnumCopy request)
        {
            LookupTableEnum ret = null;

            using (Execute)
            {
                Execute.Run(ssn =>
                {
                    var entity = DocEntityLookupTableEnum.Get(request?.Id);
                    if (null == entity)
                    {
                        throw new HttpError(HttpStatusCode.NoContent, "The COPY request did not succeed.");
                    }
                    if (!DocPermissionFactory.HasPermission(entity, currentUser, DocConstantPermission.ADD))
                    {
                        throw new HttpError(HttpStatusCode.Forbidden, "You do not have ADD permission for this route.");
                    }

                    var pIsBindable = entity.IsBindable;
                    var pIsGlobal   = entity.IsGlobal;
                    var pName       = entity.Name;
                    if (!DocTools.IsNullOrEmpty(pName))
                    {
                        pName += " (Copy)";
                    }
                    var copy = new DocEntityLookupTableEnum(ssn)
                    {
                        Hash         = Guid.NewGuid()
                        , IsBindable = pIsBindable
                        , IsGlobal   = pIsGlobal
                        , Name       = pName
                    };

                    copy.SaveChanges(DocConstantPermission.ADD);
                    ret = copy.ToDto();
                });
            }
            return(ret);
        }
Ejemplo n.º 4
0
        private Glossary _AssignValues(Glossary 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, "Glossary"))
            {
                throw new HttpError(HttpStatusCode.Forbidden, "You do not have ADD permission for this route.");
            }

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

            Glossary ret = null;

            request = _InitAssignValues <Glossary>(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 <Glossary>(DocConstantModelName.GLOSSARY, nameof(Glossary), request);

            //First, assign all the variables, do database lookups and conversions
            var pDefinition = request.Definition;
            var pEnum       = DocEntityLookupTableEnum.Get(request.Enum);
            var pIcon       = request.Icon;
            var pPage       = DocEntityPage.Get(request.Page?.Id, true, Execute) ?? DocEntityPage.Get(request.PageId, true, Execute);
            var pTerm       = DocEntityTermMaster.Get(request.Term?.Id, true, Execute) ?? DocEntityTermMaster.Get(request.TermId, true, Execute);
            var pArchived   = true == request.Archived;
            var pLocked     = request.Locked;

            var entity = InitEntity <DocEntityGlossary, Glossary>(request, permission, session);

            if (AllowPatchValue <Glossary, bool>(request, DocConstantModelName.GLOSSARY, pArchived, permission, nameof(request.Archived), pArchived != entity.Archived))
            {
                entity.Archived = pArchived;
            }
            if (AllowPatchValue <Glossary, string>(request, DocConstantModelName.GLOSSARY, pDefinition, permission, nameof(request.Definition), pDefinition != entity.Definition))
            {
                entity.Definition = pDefinition;
            }
            if (AllowPatchValue <Glossary, DocEntityLookupTableEnum>(request, DocConstantModelName.GLOSSARY, pEnum, permission, nameof(request.Enum), pEnum != entity.Enum))
            {
                entity.Enum = pEnum;
            }
            if (AllowPatchValue <Glossary, string>(request, DocConstantModelName.GLOSSARY, pIcon, permission, nameof(request.Icon), pIcon != entity.Icon))
            {
                entity.Icon = pIcon;
            }
            if (AllowPatchValue <Glossary, DocEntityPage>(request, DocConstantModelName.GLOSSARY, pPage, permission, nameof(request.Page), pPage != entity.Page))
            {
                entity.Page = pPage;
            }
            if (AllowPatchValue <Glossary, DocEntityTermMaster>(request, DocConstantModelName.GLOSSARY, pTerm, permission, nameof(request.Term), pTerm != entity.Term))
            {
                entity.Term = pTerm;
            }
            if (request.Locked && AllowPatchValue <Glossary, bool>(request, DocConstantModelName.GLOSSARY, 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.GLOSSARY);
            }

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

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

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

            return(ret);
        }
Ejemplo n.º 5
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);
        }
Ejemplo n.º 6
0
        private LookupTable _AssignValues(LookupTable 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, "LookupTable"))
            {
                throw new HttpError(HttpStatusCode.Forbidden, "You do not have ADD permission for this route.");
            }

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

            LookupTable ret = null;

            request = _InitAssignValues <LookupTable>(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 <LookupTable>(DocConstantModelName.LOOKUPTABLE, nameof(LookupTable), request);

            //First, assign all the variables, do database lookups and conversions
            var pBindings   = GetVariable <Reference>(request, nameof(request.Bindings), request.Bindings?.ToList(), request.BindingsIds?.ToList());
            var pCategories = GetVariable <Reference>(request, nameof(request.Categories), request.Categories?.ToList(), request.CategoriesIds?.ToList());
            var pDocuments  = GetVariable <Reference>(request, nameof(request.Documents), request.Documents?.ToList(), request.DocumentsIds?.ToList());
            var pEnum       = DocEntityLookupTableEnum.Get(request.Enum);
            var pName       = request.Name;
            var pArchived   = true == request.Archived;
            var pLocked     = request.Locked;

            var entity = InitEntity <DocEntityLookupTable, LookupTable>(request, permission, session);

            if (AllowPatchValue <LookupTable, bool>(request, DocConstantModelName.LOOKUPTABLE, pArchived, permission, nameof(request.Archived), pArchived != entity.Archived))
            {
                entity.Archived = pArchived;
            }
            if (AllowPatchValue <LookupTable, DocEntityLookupTableEnum>(request, DocConstantModelName.LOOKUPTABLE, pEnum, permission, nameof(request.Enum), pEnum != entity.Enum))
            {
                entity.Enum = pEnum;
            }
            if (AllowPatchValue <LookupTable, string>(request, DocConstantModelName.LOOKUPTABLE, pName, permission, nameof(request.Name), pName != entity.Name))
            {
                entity.Name = pName;
            }
            if (request.Locked && AllowPatchValue <LookupTable, bool>(request, DocConstantModelName.LOOKUPTABLE, pArchived, permission, nameof(request.Locked), pLocked != entity.Locked))
            {
                entity.Archived = pArchived;
            }
            entity.SaveChanges(permission);

            var idsToInvalidate = new List <int>();

            idsToInvalidate.AddRange(PatchCollection <LookupTable, DocEntityLookupTable, Reference, DocEntityLookupTableBinding>(request, entity, pBindings, permission, nameof(request.Bindings)));
            idsToInvalidate.AddRange(PatchCollection <LookupTable, DocEntityLookupTable, Reference, DocEntityLookupCategory>(request, entity, pCategories, permission, nameof(request.Categories)));
            idsToInvalidate.AddRange(PatchCollection <LookupTable, DocEntityLookupTable, Reference, DocEntityDocument>(request, entity, pDocuments, permission, nameof(request.Documents)));
            if (idsToInvalidate.Any())
            {
                idsToInvalidate.Add(entity.Id);
                DocCacheClient.RemoveByEntityIds(idsToInvalidate);
                DocCacheClient.RemoveSearch(DocConstantModelName.LOOKUPTABLE);
            }

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

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

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

            return(ret);
        }
Ejemplo n.º 7
0
        private TermMaster _AssignValues(TermMaster 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, "TermMaster"))
            {
                throw new HttpError(HttpStatusCode.Forbidden, "You do not have ADD permission for this route.");
            }

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

            TermMaster ret = null;

            request = _InitAssignValues <TermMaster>(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 <TermMaster>(DocConstantModelName.TERMMASTER, nameof(TermMaster), request);

            //First, assign all the variables, do database lookups and conversions
            var pBioPortal  = request.BioPortal;
            var pCategories = GetVariable <TermCategory>(request, nameof(request.Categories), request.Categories?.ToList(), request.CategoriesIds?.ToList());
            var pCUI        = request.CUI;
            var pEnum       = DocEntityLookupTableEnum.Get(request.Enum);
            var pMedDRA     = request.MedDRA;
            var pName       = request.Name;
            var pRxNorm     = request.RxNorm;
            var pSNOWMED    = request.SNOWMED;
            var pSynonyms   = GetVariable <Reference>(request, nameof(request.Synonyms), request.Synonyms?.ToList(), request.SynonymsIds?.ToList());
            var pTUI        = request.TUI;
            var pURI        = request.URI;
            var pArchived   = true == request.Archived;
            var pLocked     = request.Locked;

            var entity = InitEntity <DocEntityTermMaster, TermMaster>(request, permission, session);

            if (AllowPatchValue <TermMaster, bool>(request, DocConstantModelName.TERMMASTER, pArchived, permission, nameof(request.Archived), pArchived != entity.Archived))
            {
                entity.Archived = pArchived;
            }
            if (AllowPatchValue <TermMaster, string>(request, DocConstantModelName.TERMMASTER, pBioPortal, permission, nameof(request.BioPortal), pBioPortal != entity.BioPortal))
            {
                entity.BioPortal = pBioPortal;
            }
            if (AllowPatchValue <TermMaster, string>(request, DocConstantModelName.TERMMASTER, pCUI, permission, nameof(request.CUI), pCUI != entity.CUI))
            {
                entity.CUI = pCUI;
            }
            if (AllowPatchValue <TermMaster, DocEntityLookupTableEnum>(request, DocConstantModelName.TERMMASTER, pEnum, permission, nameof(request.Enum), pEnum != entity.Enum))
            {
                entity.Enum = pEnum;
            }
            if (AllowPatchValue <TermMaster, string>(request, DocConstantModelName.TERMMASTER, pMedDRA, permission, nameof(request.MedDRA), pMedDRA != entity.MedDRA))
            {
                entity.MedDRA = pMedDRA;
            }
            if (AllowPatchValue <TermMaster, string>(request, DocConstantModelName.TERMMASTER, pName, permission, nameof(request.Name), pName != entity.Name))
            {
                entity.Name = pName;
            }
            if (AllowPatchValue <TermMaster, string>(request, DocConstantModelName.TERMMASTER, pRxNorm, permission, nameof(request.RxNorm), pRxNorm != entity.RxNorm))
            {
                entity.RxNorm = pRxNorm;
            }
            if (AllowPatchValue <TermMaster, string>(request, DocConstantModelName.TERMMASTER, pSNOWMED, permission, nameof(request.SNOWMED), pSNOWMED != entity.SNOWMED))
            {
                entity.SNOWMED = pSNOWMED;
            }
            if (AllowPatchValue <TermMaster, string>(request, DocConstantModelName.TERMMASTER, pTUI, permission, nameof(request.TUI), pTUI != entity.TUI))
            {
                entity.TUI = pTUI;
            }
            if (AllowPatchValue <TermMaster, string>(request, DocConstantModelName.TERMMASTER, pURI, permission, nameof(request.URI), pURI != entity.URI))
            {
                entity.URI = pURI;
            }
            if (request.Locked && AllowPatchValue <TermMaster, bool>(request, DocConstantModelName.TERMMASTER, pArchived, permission, nameof(request.Locked), pLocked != entity.Locked))
            {
                entity.Archived = pArchived;
            }
            entity.SaveChanges(permission);

            var idsToInvalidate = new List <int>();

            idsToInvalidate.AddRange(PatchCollection <TermMaster, DocEntityTermMaster, TermCategory, DocEntityTermCategory>(request, entity, pCategories, permission, nameof(request.Categories)));
            idsToInvalidate.AddRange(PatchCollection <TermMaster, DocEntityTermMaster, Reference, DocEntityTermSynonym>(request, entity, pSynonyms, permission, nameof(request.Synonyms)));
            if (idsToInvalidate.Any())
            {
                idsToInvalidate.Add(entity.Id);
                DocCacheClient.RemoveByEntityIds(idsToInvalidate);
                DocCacheClient.RemoveSearch(DocConstantModelName.TERMMASTER);
            }

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

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

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

            return(ret);
        }