private DocumentSet GetDocumentSet(DocumentSet request)
        {
            var         id    = request?.Id;
            DocumentSet ret   = null;
            var         query = DocQuery.ActiveQuery ?? Execute;

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

            DocEntityDocumentSet entity = null;

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

                    var en = DocEntityDocumentSet.Get(request?.Id);
                    if (null == en)
                    {
                        throw new HttpError(HttpStatusCode.NotFound, $"No DocumentSet 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.DOCUMENTSET);
                    DocCacheClient.RemoveById(request.Id);
                });
            }
        }
        private DiseaseStateSet _AssignValues(DiseaseStateSet 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, "DiseaseStateSet"))
            {
                throw new HttpError(HttpStatusCode.Forbidden, "You do not have ADD permission for this route.");
            }

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

            DiseaseStateSet ret = null;

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

            //First, assign all the variables, do database lookups and conversions
            var pClients             = GetVariable <Reference>(request, nameof(request.Clients), request.Clients?.ToList(), request.ClientsIds?.ToList());
            var pConfidential        = request.Confidential;
            var pDivisions           = GetVariable <Reference>(request, nameof(request.Divisions), request.Divisions?.ToList(), request.DivisionsIds?.ToList());
            var pDocuments           = GetVariable <Reference>(request, nameof(request.Documents), request.Documents?.ToList(), request.DocumentsIds?.ToList());
            var pDocumentSets        = GetVariable <Reference>(request, nameof(request.DocumentSets), request.DocumentSets?.ToList(), request.DocumentSetsIds?.ToList());
            var pHistories           = GetVariable <Reference>(request, nameof(request.Histories), request.Histories?.ToList(), request.HistoriesIds?.ToList());
            var pLegacyDocumentSetId = request.LegacyDocumentSetId;
            var pName        = request.Name;
            var pOwner       = DocEntityDocumentSet.Get(request.Owner?.Id, true, Execute) ?? DocEntityDocumentSet.Get(request.OwnerId, true, Execute);
            var pProjectTeam = DocEntityTeam.Get(request.ProjectTeam?.Id, true, Execute) ?? DocEntityTeam.Get(request.ProjectTeamId, true, Execute);
            var pScopes      = GetVariable <Reference>(request, nameof(request.Scopes), request.Scopes?.ToList(), request.ScopesIds?.ToList());
            var pSettings    = request.Settings;
            var pStats       = GetVariable <Reference>(request, nameof(request.Stats), request.Stats?.ToList(), request.StatsIds?.ToList());
            var pType        = request.Type;
            var pUsers       = GetVariable <Reference>(request, nameof(request.Users), request.Users?.ToList(), request.UsersIds?.ToList());
            var pArchived    = true == request.Archived;
            var pLocked      = request.Locked;

            var entity = InitEntity <DocEntityDiseaseStateSet, DiseaseStateSet>(request, permission, session);

            if (AllowPatchValue <DiseaseStateSet, bool>(request, DocConstantModelName.DISEASESTATESET, pArchived, permission, nameof(request.Archived), pArchived != entity.Archived))
            {
                entity.Archived = pArchived;
            }
            if (AllowPatchValue <DiseaseStateSet, bool>(request, DocConstantModelName.DISEASESTATESET, pConfidential, permission, nameof(request.Confidential), pConfidential != entity.Confidential))
            {
                entity.Confidential = pConfidential;
            }
            if (AllowPatchValue <DiseaseStateSet, int?>(request, DocConstantModelName.DISEASESTATESET, pLegacyDocumentSetId, permission, nameof(request.LegacyDocumentSetId), pLegacyDocumentSetId != entity.LegacyDocumentSetId))
            {
                entity.LegacyDocumentSetId = pLegacyDocumentSetId;
            }
            if (AllowPatchValue <DiseaseStateSet, string>(request, DocConstantModelName.DISEASESTATESET, pName, permission, nameof(request.Name), pName != entity.Name))
            {
                entity.Name = pName;
            }
            if (AllowPatchValue <DiseaseStateSet, DocEntityDocumentSet>(request, DocConstantModelName.DISEASESTATESET, pOwner, permission, nameof(request.Owner), pOwner != entity.Owner))
            {
                entity.Owner = pOwner;
            }
            if (AllowPatchValue <DiseaseStateSet, DocEntityTeam>(request, DocConstantModelName.DISEASESTATESET, pProjectTeam, permission, nameof(request.ProjectTeam), pProjectTeam != entity.ProjectTeam))
            {
                entity.ProjectTeam = pProjectTeam;
            }
            if (AllowPatchValue <DiseaseStateSet, string>(request, DocConstantModelName.DISEASESTATESET, pSettings, permission, nameof(request.Settings), pSettings != entity.Settings))
            {
                entity.Settings = pSettings;
            }
            if (AllowPatchValue <DiseaseStateSet, DocumentSetTypeEnm?>(request, DocConstantModelName.DISEASESTATESET, pType, permission, nameof(request.Type), pType != entity.Type))
            {
                if (null != pType)
                {
                    entity.Type = pType.Value;
                }
            }
            if (request.Locked && AllowPatchValue <DiseaseStateSet, bool>(request, DocConstantModelName.DISEASESTATESET, pArchived, permission, nameof(request.Locked), pLocked != entity.Locked))
            {
                entity.Archived = pArchived;
            }
            entity.SaveChanges(permission);

            var idsToInvalidate = new List <int>();

            idsToInvalidate.AddRange(PatchCollection <DiseaseStateSet, DocEntityDiseaseStateSet, Reference, DocEntityClient>(request, entity, pClients, permission, nameof(request.Clients)));
            idsToInvalidate.AddRange(PatchCollection <DiseaseStateSet, DocEntityDiseaseStateSet, Reference, DocEntityDivision>(request, entity, pDivisions, permission, nameof(request.Divisions)));
            idsToInvalidate.AddRange(PatchCollection <DiseaseStateSet, DocEntityDiseaseStateSet, Reference, DocEntityDocument>(request, entity, pDocuments, permission, nameof(request.Documents)));
            idsToInvalidate.AddRange(PatchCollection <DiseaseStateSet, DocEntityDiseaseStateSet, Reference, DocEntityDocumentSet>(request, entity, pDocumentSets, permission, nameof(request.DocumentSets)));
            idsToInvalidate.AddRange(PatchCollection <DiseaseStateSet, DocEntityDiseaseStateSet, Reference, DocEntityDocumentSetHistory>(request, entity, pHistories, permission, nameof(request.Histories)));
            idsToInvalidate.AddRange(PatchCollection <DiseaseStateSet, DocEntityDiseaseStateSet, Reference, DocEntityScope>(request, entity, pScopes, permission, nameof(request.Scopes)));
            idsToInvalidate.AddRange(PatchCollection <DiseaseStateSet, DocEntityDiseaseStateSet, Reference, DocEntityStatsStudySet>(request, entity, pStats, permission, nameof(request.Stats)));
            idsToInvalidate.AddRange(PatchCollection <DiseaseStateSet, DocEntityDiseaseStateSet, Reference, DocEntityUser>(request, entity, pUsers, permission, nameof(request.Users)));
            if (idsToInvalidate.Any())
            {
                idsToInvalidate.Add(entity.Id);
                DocCacheClient.RemoveByEntityIds(idsToInvalidate);
                DocCacheClient.RemoveSearch(DocConstantModelName.DISEASESTATESET);
            }

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

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

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

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

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

            Workflow ret = null;

            request = _InitAssignValues <Workflow>(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 <Workflow>(DocConstantModelName.WORKFLOW, nameof(Workflow), 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 pData        = request.Data;
            var pDescription = request.Description;
            var pDocuments   = GetVariable <Reference>(request, nameof(request.Documents), request.Documents?.ToList(), request.DocumentsIds?.ToList());
            var pDocumentSet = DocEntityDocumentSet.Get(request.DocumentSet?.Id, true, Execute) ?? DocEntityDocumentSet.Get(request.DocumentSetId, true, Execute);
            var pName        = request.Name;
            var pOwner       = DocEntityWorkflow.Get(request.Owner?.Id, true, Execute) ?? DocEntityWorkflow.Get(request.OwnerId, true, Execute);
            var pScopes      = GetVariable <Reference>(request, nameof(request.Scopes), request.Scopes?.ToList(), request.ScopesIds?.ToList());
            var pStatus      = request.Status;
            var pTasks       = GetVariable <Reference>(request, nameof(request.Tasks), request.Tasks?.ToList(), request.TasksIds?.ToList());
            var pType        = request.Type;
            var pUser        = DocEntityUser.Get(request.User?.Id, true, Execute) ?? DocEntityUser.Get(request.UserId, true, Execute);
            var pVariables   = GetVariable <Reference>(request, nameof(request.Variables), request.Variables?.ToList(), request.VariablesIds?.ToList());
            var pWorkflows   = GetVariable <Reference>(request, nameof(request.Workflows), request.Workflows?.ToList(), request.WorkflowsIds?.ToList());
            var pArchived    = true == request.Archived;
            var pLocked      = request.Locked;

            var entity = InitEntity <DocEntityWorkflow, Workflow>(request, permission, session);

            if (AllowPatchValue <Workflow, bool>(request, DocConstantModelName.WORKFLOW, pArchived, permission, nameof(request.Archived), pArchived != entity.Archived))
            {
                entity.Archived = pArchived;
            }
            if (AllowPatchValue <Workflow, string>(request, DocConstantModelName.WORKFLOW, pData, permission, nameof(request.Data), pData != entity.Data))
            {
                entity.Data = pData;
            }
            if (AllowPatchValue <Workflow, string>(request, DocConstantModelName.WORKFLOW, pDescription, permission, nameof(request.Description), pDescription != entity.Description))
            {
                entity.Description = pDescription;
            }
            if (AllowPatchValue <Workflow, DocEntityDocumentSet>(request, DocConstantModelName.WORKFLOW, pDocumentSet, permission, nameof(request.DocumentSet), pDocumentSet != entity.DocumentSet))
            {
                entity.DocumentSet = pDocumentSet;
            }
            if (AllowPatchValue <Workflow, string>(request, DocConstantModelName.WORKFLOW, pName, permission, nameof(request.Name), pName != entity.Name))
            {
                entity.Name = pName;
            }
            if (AllowPatchValue <Workflow, DocEntityWorkflow>(request, DocConstantModelName.WORKFLOW, pOwner, permission, nameof(request.Owner), pOwner != entity.Owner))
            {
                entity.Owner = pOwner;
            }
            if (AllowPatchValue <Workflow, WorkflowStatusEnm?>(request, DocConstantModelName.WORKFLOW, pStatus, permission, nameof(request.Status), pStatus != entity.Status))
            {
                entity.Status = pStatus;
            }
            if (AllowPatchValue <Workflow, WorkflowEnm?>(request, DocConstantModelName.WORKFLOW, pType, permission, nameof(request.Type), pType != entity.Type))
            {
                if (null != pType)
                {
                    entity.Type = pType.Value;
                }
            }
            if (AllowPatchValue <Workflow, DocEntityUser>(request, DocConstantModelName.WORKFLOW, pUser, permission, nameof(request.User), pUser != entity.User))
            {
                entity.User = pUser;
            }
            if (request.Locked && AllowPatchValue <Workflow, bool>(request, DocConstantModelName.WORKFLOW, pArchived, permission, nameof(request.Locked), pLocked != entity.Locked))
            {
                entity.Archived = pArchived;
            }
            entity.SaveChanges(permission);

            var idsToInvalidate = new List <int>();

            idsToInvalidate.AddRange(PatchCollection <Workflow, DocEntityWorkflow, Reference, DocEntityLookupTableBinding>(request, entity, pBindings, permission, nameof(request.Bindings)));
            idsToInvalidate.AddRange(PatchCollection <Workflow, DocEntityWorkflow, Reference, DocEntityDocument>(request, entity, pDocuments, permission, nameof(request.Documents)));
            idsToInvalidate.AddRange(PatchCollection <Workflow, DocEntityWorkflow, Reference, DocEntityScope>(request, entity, pScopes, permission, nameof(request.Scopes)));
            idsToInvalidate.AddRange(PatchCollection <Workflow, DocEntityWorkflow, Reference, DocEntityTask>(request, entity, pTasks, permission, nameof(request.Tasks)));
            idsToInvalidate.AddRange(PatchCollection <Workflow, DocEntityWorkflow, Reference, DocEntityVariableInstance>(request, entity, pVariables, permission, nameof(request.Variables)));
            idsToInvalidate.AddRange(PatchCollection <Workflow, DocEntityWorkflow, Reference, DocEntityWorkflow>(request, entity, pWorkflows, permission, nameof(request.Workflows)));
            if (idsToInvalidate.Any())
            {
                idsToInvalidate.Add(entity.Id);
                DocCacheClient.RemoveByEntityIds(idsToInvalidate);
                DocCacheClient.RemoveSearch(DocConstantModelName.WORKFLOW);
            }

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

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

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

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

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

            Scope ret = null;

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

            //First, assign all the variables, do database lookups and conversions
            var pApp            = DocEntityApp.Get(request.App?.Id, true, Execute) ?? DocEntityApp.Get(request.AppId, true, Execute);
            var pBindings       = GetVariable <Reference>(request, nameof(request.Bindings), request.Bindings?.ToList(), request.BindingsIds?.ToList());
            var pBroadcasts     = GetVariable <Reference>(request, nameof(request.Broadcasts), request.Broadcasts?.ToList(), request.BroadcastsIds?.ToList());
            var pClient         = DocEntityClient.Get(request.Client?.Id, true, Execute) ?? DocEntityClient.Get(request.ClientId, true, Execute);
            var pDelete         = request.Delete;
            var pDocumentSet    = DocEntityDocumentSet.Get(request.DocumentSet?.Id, true, Execute) ?? DocEntityDocumentSet.Get(request.DocumentSetId, true, Execute);
            var pEdit           = request.Edit;
            var pHelp           = GetVariable <Reference>(request, nameof(request.Help), request.Help?.ToList(), request.HelpIds?.ToList());
            var pIsGlobal       = request.IsGlobal;
            var pScopedComments = GetVariable <Reference>(request, nameof(request.ScopedComments), request.ScopedComments?.ToList(), request.ScopedCommentsIds?.ToList());
            var pScopedFiles    = GetVariable <Reference>(request, nameof(request.ScopedFiles), request.ScopedFiles?.ToList(), request.ScopedFilesIds?.ToList());
            var pScopedTags     = GetVariable <Reference>(request, nameof(request.ScopedTags), request.ScopedTags?.ToList(), request.ScopedTagsIds?.ToList());
            var pSynonyms       = GetVariable <Reference>(request, nameof(request.Synonyms), request.Synonyms?.ToList(), request.SynonymsIds?.ToList());
            var pTeam           = DocEntityTeam.Get(request.Team?.Id, true, Execute) ?? DocEntityTeam.Get(request.TeamId, true, Execute);
            var pType           = request.Type;
            var pUser           = DocEntityUser.Get(request.User?.Id, true, Execute) ?? DocEntityUser.Get(request.UserId, true, Execute);
            var pVariableRules  = GetVariable <Reference>(request, nameof(request.VariableRules), request.VariableRules?.ToList(), request.VariableRulesIds?.ToList());
            var pView           = request.View;
            var pWorkflows      = GetVariable <Reference>(request, nameof(request.Workflows), request.Workflows?.ToList(), request.WorkflowsIds?.ToList());
            var pArchived       = true == request.Archived;
            var pLocked         = request.Locked;

            var entity = InitEntity <DocEntityScope, Scope>(request, permission, session);

            if (AllowPatchValue <Scope, bool>(request, DocConstantModelName.SCOPE, pArchived, permission, nameof(request.Archived), pArchived != entity.Archived))
            {
                entity.Archived = pArchived;
            }
            if (AllowPatchValue <Scope, DocEntityApp>(request, DocConstantModelName.SCOPE, pApp, permission, nameof(request.App), pApp != entity.App))
            {
                entity.App = pApp;
            }
            if (AllowPatchValue <Scope, DocEntityClient>(request, DocConstantModelName.SCOPE, pClient, permission, nameof(request.Client), pClient != entity.Client))
            {
                entity.Client = pClient;
            }
            if (AllowPatchValue <Scope, bool>(request, DocConstantModelName.SCOPE, pDelete, permission, nameof(request.Delete), pDelete != entity.Delete))
            {
                entity.Delete = pDelete;
            }
            if (AllowPatchValue <Scope, DocEntityDocumentSet>(request, DocConstantModelName.SCOPE, pDocumentSet, permission, nameof(request.DocumentSet), pDocumentSet != entity.DocumentSet))
            {
                entity.DocumentSet = pDocumentSet;
            }
            if (AllowPatchValue <Scope, bool>(request, DocConstantModelName.SCOPE, pEdit, permission, nameof(request.Edit), pEdit != entity.Edit))
            {
                entity.Edit = pEdit;
            }
            if (AllowPatchValue <Scope, bool>(request, DocConstantModelName.SCOPE, pIsGlobal, permission, nameof(request.IsGlobal), pIsGlobal != entity.IsGlobal))
            {
                entity.IsGlobal = pIsGlobal;
            }
            if (AllowPatchValue <Scope, DocEntityTeam>(request, DocConstantModelName.SCOPE, pTeam, permission, nameof(request.Team), pTeam != entity.Team))
            {
                entity.Team = pTeam;
            }
            if (AllowPatchValue <Scope, ScopeEnm?>(request, DocConstantModelName.SCOPE, pType, permission, nameof(request.Type), pType != entity.Type))
            {
                if (null != pType)
                {
                    entity.Type = pType.Value;
                }
            }
            if (AllowPatchValue <Scope, DocEntityUser>(request, DocConstantModelName.SCOPE, pUser, permission, nameof(request.User), pUser != entity.User))
            {
                entity.User = pUser;
            }
            if (AllowPatchValue <Scope, bool>(request, DocConstantModelName.SCOPE, pView, permission, nameof(request.View), pView != entity.View))
            {
                entity.View = pView;
            }
            if (request.Locked && AllowPatchValue <Scope, bool>(request, DocConstantModelName.SCOPE, pArchived, permission, nameof(request.Locked), pLocked != entity.Locked))
            {
                entity.Archived = pArchived;
            }
            entity.SaveChanges(permission);

            var idsToInvalidate = new List <int>();

            idsToInvalidate.AddRange(PatchCollection <Scope, DocEntityScope, Reference, DocEntityLookupTableBinding>(request, entity, pBindings, permission, nameof(request.Bindings)));
            idsToInvalidate.AddRange(PatchCollection <Scope, DocEntityScope, Reference, DocEntityBroadcast>(request, entity, pBroadcasts, permission, nameof(request.Broadcasts)));
            idsToInvalidate.AddRange(PatchCollection <Scope, DocEntityScope, Reference, DocEntityHelp>(request, entity, pHelp, permission, nameof(request.Help)));
            idsToInvalidate.AddRange(PatchCollection <Scope, DocEntityScope, Reference, DocEntityComment>(request, entity, pScopedComments, permission, nameof(request.ScopedComments)));
            idsToInvalidate.AddRange(PatchCollection <Scope, DocEntityScope, Reference, DocEntityFile>(request, entity, pScopedFiles, permission, nameof(request.ScopedFiles)));
            idsToInvalidate.AddRange(PatchCollection <Scope, DocEntityScope, Reference, DocEntityTag>(request, entity, pScopedTags, permission, nameof(request.ScopedTags)));
            idsToInvalidate.AddRange(PatchCollection <Scope, DocEntityScope, Reference, DocEntityTermSynonym>(request, entity, pSynonyms, permission, nameof(request.Synonyms)));
            idsToInvalidate.AddRange(PatchCollection <Scope, DocEntityScope, Reference, DocEntityVariableRule>(request, entity, pVariableRules, permission, nameof(request.VariableRules)));
            idsToInvalidate.AddRange(PatchCollection <Scope, DocEntityScope, Reference, DocEntityWorkflow>(request, entity, pWorkflows, permission, nameof(request.Workflows)));
            if (idsToInvalidate.Any())
            {
                idsToInvalidate.Add(entity.Id);
                DocCacheClient.RemoveByEntityIds(idsToInvalidate);
                DocCacheClient.RemoveSearch(DocConstantModelName.SCOPE);
            }

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

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

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

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

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

            History ret = null;

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

            //First, assign all the variables, do database lookups and conversions
            var pApp           = DocEntityApp.Get(request.App?.Id, true, Execute) ?? DocEntityApp.Get(request.AppId, true, Execute);
            var pDocumentSet   = DocEntityDocumentSet.Get(request.DocumentSet?.Id, true, Execute) ?? DocEntityDocumentSet.Get(request.DocumentSetId, true, Execute);
            var pImpersonation = DocEntityImpersonation.Get(request.Impersonation?.Id, true, Execute) ?? DocEntityImpersonation.Get(request.ImpersonationId, true, Execute);
            var pPage          = DocEntityPage.Get(request.Page?.Id, true, Execute) ?? DocEntityPage.Get(request.PageId, true, Execute);
            var pURL           = request.URL;
            var pUser          = DocEntityUser.Get(request.User?.Id, true, Execute) ?? DocEntityUser.Get(request.UserId, true, Execute);
            var pUserSession   = DocEntityUserSession.Get(request.UserSession?.Id, true, Execute) ?? DocEntityUserSession.Get(request.UserSessionId, true, Execute);
            var pWorkflow      = DocEntityWorkflow.Get(request.Workflow?.Id, true, Execute) ?? DocEntityWorkflow.Get(request.WorkflowId, true, Execute);
            var pArchived      = true == request.Archived;
            var pLocked        = request.Locked;

            var entity = InitEntity <DocEntityHistory, History>(request, permission, session);

            if (AllowPatchValue <History, bool>(request, DocConstantModelName.HISTORY, pArchived, permission, nameof(request.Archived), pArchived != entity.Archived))
            {
                entity.Archived = pArchived;
            }
            if (AllowPatchValue <History, DocEntityApp>(request, DocConstantModelName.HISTORY, pApp, permission, nameof(request.App), pApp != entity.App))
            {
                entity.App = pApp;
            }
            if (AllowPatchValue <History, DocEntityDocumentSet>(request, DocConstantModelName.HISTORY, pDocumentSet, permission, nameof(request.DocumentSet), pDocumentSet != entity.DocumentSet))
            {
                entity.DocumentSet = pDocumentSet;
            }
            if (AllowPatchValue <History, DocEntityImpersonation>(request, DocConstantModelName.HISTORY, pImpersonation, permission, nameof(request.Impersonation), pImpersonation != entity.Impersonation))
            {
                entity.Impersonation = pImpersonation;
            }
            if (AllowPatchValue <History, DocEntityPage>(request, DocConstantModelName.HISTORY, pPage, permission, nameof(request.Page), pPage != entity.Page))
            {
                entity.Page = pPage;
            }
            if (AllowPatchValue <History, string>(request, DocConstantModelName.HISTORY, pURL, permission, nameof(request.URL), pURL != entity.URL))
            {
                entity.URL = pURL;
            }
            if (AllowPatchValue <History, DocEntityUser>(request, DocConstantModelName.HISTORY, pUser, permission, nameof(request.User), pUser != entity.User))
            {
                entity.User = pUser;
            }
            if (AllowPatchValue <History, DocEntityUserSession>(request, DocConstantModelName.HISTORY, pUserSession, permission, nameof(request.UserSession), pUserSession != entity.UserSession))
            {
                entity.UserSession = pUserSession;
            }
            if (AllowPatchValue <History, DocEntityWorkflow>(request, DocConstantModelName.HISTORY, pWorkflow, permission, nameof(request.Workflow), pWorkflow != entity.Workflow))
            {
                entity.Workflow = pWorkflow;
            }
            if (request.Locked && AllowPatchValue <History, bool>(request, DocConstantModelName.HISTORY, 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.HISTORY);
            }

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

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

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

            return(ret);
        }
        public DocumentSet Post(DocumentSetCopy request)
        {
            DocumentSet ret = null;

            using (Execute)
            {
                Execute.Run(ssn =>
                {
                    var entity = DocEntityDocumentSet.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 pClients             = entity.Clients.ToList();
                    var pConfidential        = entity.Confidential;
                    var pDivisions           = entity.Divisions.ToList();
                    var pDocuments           = entity.Documents.ToList();
                    var pDocumentSets        = entity.DocumentSets.ToList();
                    var pHistories           = entity.Histories.ToList();
                    var pLegacyDocumentSetId = entity.LegacyDocumentSetId;
                    var pName = entity.Name;
                    if (!DocTools.IsNullOrEmpty(pName))
                    {
                        pName += " (Copy)";
                    }
                    var pOwner       = entity.Owner;
                    var pProjectTeam = entity.ProjectTeam;
                    var pScopes      = entity.Scopes.ToList();
                    var pSettings    = entity.Settings;
                    var pStats       = entity.Stats.ToList();
                    var pType        = entity.Type;
                    var pUsers       = entity.Users.ToList();
                    var copy         = new DocEntityDocumentSet(ssn)
                    {
                        Hash                  = Guid.NewGuid()
                        , Confidential        = pConfidential
                        , LegacyDocumentSetId = pLegacyDocumentSetId
                        , Name                = pName
                        , Owner               = pOwner
                        , ProjectTeam         = pProjectTeam
                        , Settings            = pSettings
                        , Type                = pType
                    };
                    foreach (var item in pClients)
                    {
                        entity.Clients.Add(item);
                    }

                    foreach (var item in pDivisions)
                    {
                        entity.Divisions.Add(item);
                    }

                    foreach (var item in pDocuments)
                    {
                        entity.Documents.Add(item);
                    }

                    foreach (var item in pDocumentSets)
                    {
                        entity.DocumentSets.Add(item);
                    }

                    foreach (var item in pHistories)
                    {
                        entity.Histories.Add(item);
                    }

                    foreach (var item in pScopes)
                    {
                        entity.Scopes.Add(item);
                    }

                    foreach (var item in pStats)
                    {
                        entity.Stats.Add(item);
                    }

                    foreach (var item in pUsers)
                    {
                        entity.Users.Add(item);
                    }

                    copy.SaveChanges(DocConstantPermission.ADD);
                    ret = copy.ToDto();
                });
            }
            return(ret);
        }