Esempio n. 1
0
        private Workflow GetWorkflow(Workflow request)
        {
            var      id    = request?.Id;
            Workflow ret   = null;
            var      query = DocQuery.ActiveQuery ?? Execute;

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

            DocEntityWorkflow entity = null;

            if (id.HasValue)
            {
                entity = DocEntityWorkflow.Get(id.Value);
            }
            if (null == entity)
            {
                throw new HttpError(HttpStatusCode.NotFound, $"No Workflow 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);
        }
Esempio n. 2
0
        public Workflow Post(WorkflowCopy request)
        {
            Workflow ret = null;

            using (Execute)
            {
                Execute.Run(ssn =>
                {
                    var entity = DocEntityWorkflow.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 pBindings    = entity.Bindings.ToList();
                    var pData        = entity.Data;
                    var pDescription = entity.Description;
                    if (!DocTools.IsNullOrEmpty(pDescription))
                    {
                        pDescription += " (Copy)";
                    }
                    var pDocuments   = entity.Documents.ToList();
                    var pDocumentSet = entity.DocumentSet;
                    var pName        = entity.Name;
                    if (!DocTools.IsNullOrEmpty(pName))
                    {
                        pName += " (Copy)";
                    }
                    var pOwner     = entity.Owner;
                    var pScopes    = entity.Scopes.ToList();
                    var pStatus    = entity.Status;
                    var pTasks     = entity.Tasks.ToList();
                    var pType      = entity.Type;
                    var pUser      = entity.User;
                    var pVariables = entity.Variables.ToList();
                    var pWorkflows = entity.Workflows.ToList();
                    var copy       = new DocEntityWorkflow(ssn)
                    {
                        Hash          = Guid.NewGuid()
                        , Data        = pData
                        , Description = pDescription
                        , DocumentSet = pDocumentSet
                        , Name        = pName
                        , Owner       = pOwner
                        , Status      = pStatus
                        , Type        = pType
                        , User        = pUser
                    };
                    foreach (var item in pBindings)
                    {
                        entity.Bindings.Add(item);
                    }

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

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

                    foreach (var item in pTasks)
                    {
                        entity.Tasks.Add(item);
                    }

                    foreach (var item in pVariables)
                    {
                        entity.Variables.Add(item);
                    }

                    foreach (var item in pWorkflows)
                    {
                        entity.Workflows.Add(item);
                    }

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

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

            Rating ret = null;

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

            //First, assign all the variables, do database lookups and conversions
            var pAssignee       = DocEntityUser.Get(request.Assignee?.Id, true, Execute) ?? DocEntityUser.Get(request.AssigneeId, true, Execute);
            var pData           = request.Data;
            var pDescription    = request.Description;
            var pDocument       = DocEntityDocument.Get(request.Document?.Id, true, Execute) ?? DocEntityDocument.Get(request.DocumentId, true, Execute);
            var pDueDate        = request.DueDate;
            var pRating         = request.Rating;
            var pReasonRejected = request.ReasonRejected;
            var pReporter       = DocEntityUser.Get(request.Reporter?.Id, true, Execute) ?? DocEntityUser.Get(request.ReporterId, true, Execute);
            var pType           = request.Type;
            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 <DocEntityRating, Rating>(request, permission, session);

            if (AllowPatchValue <Rating, bool>(request, DocConstantModelName.RATING, pArchived, permission, nameof(request.Archived), pArchived != entity.Archived))
            {
                entity.Archived = pArchived;
            }
            if (AllowPatchValue <Rating, DocEntityUser>(request, DocConstantModelName.RATING, pAssignee, permission, nameof(request.Assignee), pAssignee != entity.Assignee))
            {
                entity.Assignee = pAssignee;
            }
            if (AllowPatchValue <Rating, string>(request, DocConstantModelName.RATING, pData, permission, nameof(request.Data), pData != entity.Data))
            {
                entity.Data = pData;
            }
            if (AllowPatchValue <Rating, string>(request, DocConstantModelName.RATING, pDescription, permission, nameof(request.Description), pDescription != entity.Description))
            {
                entity.Description = pDescription;
            }
            if (AllowPatchValue <Rating, DocEntityDocument>(request, DocConstantModelName.RATING, pDocument, permission, nameof(request.Document), pDocument != entity.Document))
            {
                entity.Document = pDocument;
            }
            if (AllowPatchValue <Rating, DateTime?>(request, DocConstantModelName.RATING, pDueDate, permission, nameof(request.DueDate), pDueDate != entity.DueDate))
            {
                entity.DueDate = pDueDate;
            }
            if (AllowPatchValue <Rating, RatingEnm?>(request, DocConstantModelName.RATING, pRating, permission, nameof(request.Rating), pRating != entity.Rating))
            {
                if (null != pRating)
                {
                    entity.Rating = pRating.Value;
                }
            }
            if (AllowPatchValue <Rating, ReasonRejectedEnm?>(request, DocConstantModelName.RATING, pReasonRejected, permission, nameof(request.ReasonRejected), pReasonRejected != entity.ReasonRejected))
            {
                entity.ReasonRejected = pReasonRejected;
            }
            if (AllowPatchValue <Rating, DocEntityUser>(request, DocConstantModelName.RATING, pReporter, permission, nameof(request.Reporter), pReporter != entity.Reporter))
            {
                entity.Reporter = pReporter;
            }
            if (AllowPatchValue <Rating, TaskTypeEnm?>(request, DocConstantModelName.RATING, pType, permission, nameof(request.Type), pType != entity.Type))
            {
                if (null != pType)
                {
                    entity.Type = pType.Value;
                }
            }
            if (AllowPatchValue <Rating, DocEntityWorkflow>(request, DocConstantModelName.RATING, pWorkflow, permission, nameof(request.Workflow), pWorkflow != entity.Workflow))
            {
                entity.Workflow = pWorkflow;
            }
            if (request.Locked && AllowPatchValue <Rating, bool>(request, DocConstantModelName.RATING, 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.RATING);
            }

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

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

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

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

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

            Project ret = null;

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

            //First, assign all the variables, do database lookups and conversions
            var pChildren            = GetVariable <Reference>(request, nameof(request.Children), request.Children?.ToList(), request.ChildrenIds?.ToList());
            var pClient              = DocEntityClient.Get(request.Client?.Id, true, Execute) ?? DocEntityClient.Get(request.ClientId, true, Execute);
            var pDatabaseDeadline    = request.DatabaseDeadline;
            var pDatabaseName        = request.DatabaseName;
            var pDataset             = DocEntityDataSet.Get(request.Dataset?.Id, true, Execute) ?? DocEntityDataSet.Get(request.DatasetId, true, Execute);
            var pDeliverableDeadline = request.DeliverableDeadline;
            var pFqId                  = request.FqId;
            var pFqWorkflow            = DocEntityWorkflow.Get(request.FqWorkflow?.Id, true, Execute) ?? DocEntityWorkflow.Get(request.FqWorkflowId, true, Execute);
            var pLegacyPackageId       = request.LegacyPackageId;
            var pLibrary               = DocEntityLibrarySet.Get(request.Library?.Id, true, Execute) ?? DocEntityLibrarySet.Get(request.LibraryId, true, Execute);
            var pLibraryPackageId      = request.LibraryPackageId;
            var pLibraryPackageName    = request.LibraryPackageName;
            var pNumber                = request.Number;
            var pOperationsDeliverable = request.OperationsDeliverable;
            var pOpportunityId         = request.OpportunityId;
            var pOpportunityName       = request.OpportunityName;
            var pParent                = DocEntityProject.Get(request.Parent?.Id, true, Execute) ?? DocEntityProject.Get(request.ParentId, true, Execute);
            var pPICO                  = request.PICO;
            var pProjectId             = request.ProjectId;
            var pProjectName           = request.ProjectName;
            var pStatus                = request.Status;
            var pTimeCards             = GetVariable <Reference>(request, nameof(request.TimeCards), request.TimeCards?.ToList(), request.TimeCardsIds?.ToList());
            var pArchived              = true == request.Archived;
            var pLocked                = request.Locked;

            var entity = InitEntity <DocEntityProject, Project>(request, permission, session);

            if (AllowPatchValue <Project, bool>(request, DocConstantModelName.PROJECT, pArchived, permission, nameof(request.Archived), pArchived != entity.Archived))
            {
                entity.Archived = pArchived;
            }
            if (AllowPatchValue <Project, DocEntityClient>(request, DocConstantModelName.PROJECT, pClient, permission, nameof(request.Client), pClient != entity.Client))
            {
                entity.Client = pClient;
            }
            if (AllowPatchValue <Project, DateTime?>(request, DocConstantModelName.PROJECT, pDatabaseDeadline, permission, nameof(request.DatabaseDeadline), pDatabaseDeadline != entity.DatabaseDeadline))
            {
                entity.DatabaseDeadline = pDatabaseDeadline;
            }
            if (AllowPatchValue <Project, string>(request, DocConstantModelName.PROJECT, pDatabaseName, permission, nameof(request.DatabaseName), pDatabaseName != entity.DatabaseName))
            {
                entity.DatabaseName = pDatabaseName;
            }
            if (AllowPatchValue <Project, DocEntityDataSet>(request, DocConstantModelName.PROJECT, pDataset, permission, nameof(request.Dataset), pDataset != entity.Dataset))
            {
                entity.Dataset = pDataset;
            }
            if (AllowPatchValue <Project, DateTime?>(request, DocConstantModelName.PROJECT, pDeliverableDeadline, permission, nameof(request.DeliverableDeadline), pDeliverableDeadline != entity.DeliverableDeadline))
            {
                entity.DeliverableDeadline = pDeliverableDeadline;
            }
            if (AllowPatchValue <Project, int?>(request, DocConstantModelName.PROJECT, pFqId, permission, nameof(request.FqId), pFqId != entity.FqId))
            {
                entity.FqId = pFqId;
            }
            if (AllowPatchValue <Project, DocEntityWorkflow>(request, DocConstantModelName.PROJECT, pFqWorkflow, permission, nameof(request.FqWorkflow), pFqWorkflow != entity.FqWorkflow))
            {
                entity.FqWorkflow = pFqWorkflow;
            }
            if (AllowPatchValue <Project, int?>(request, DocConstantModelName.PROJECT, pLegacyPackageId, permission, nameof(request.LegacyPackageId), pLegacyPackageId != entity.LegacyPackageId))
            {
                entity.LegacyPackageId = pLegacyPackageId;
            }
            if (AllowPatchValue <Project, DocEntityLibrarySet>(request, DocConstantModelName.PROJECT, pLibrary, permission, nameof(request.Library), pLibrary != entity.Library))
            {
                entity.Library = pLibrary;
            }
            if (AllowPatchValue <Project, int?>(request, DocConstantModelName.PROJECT, pLibraryPackageId, permission, nameof(request.LibraryPackageId), pLibraryPackageId != entity.LibraryPackageId))
            {
                entity.LibraryPackageId = pLibraryPackageId;
            }
            if (AllowPatchValue <Project, string>(request, DocConstantModelName.PROJECT, pLibraryPackageName, permission, nameof(request.LibraryPackageName), pLibraryPackageName != entity.LibraryPackageName))
            {
                entity.LibraryPackageName = pLibraryPackageName;
            }
            if (AllowPatchValue <Project, string>(request, DocConstantModelName.PROJECT, pNumber, permission, nameof(request.Number), pNumber != entity.Number))
            {
                entity.Number = pNumber;
            }
            if (AllowPatchValue <Project, string>(request, DocConstantModelName.PROJECT, pOperationsDeliverable, permission, nameof(request.OperationsDeliverable), pOperationsDeliverable != entity.OperationsDeliverable))
            {
                entity.OperationsDeliverable = pOperationsDeliverable;
            }
            if (AllowPatchValue <Project, string>(request, DocConstantModelName.PROJECT, pOpportunityId, permission, nameof(request.OpportunityId), pOpportunityId != entity.OpportunityId))
            {
                entity.OpportunityId = pOpportunityId;
            }
            if (AllowPatchValue <Project, string>(request, DocConstantModelName.PROJECT, pOpportunityName, permission, nameof(request.OpportunityName), pOpportunityName != entity.OpportunityName))
            {
                entity.OpportunityName = pOpportunityName;
            }
            if (AllowPatchValue <Project, DocEntityProject>(request, DocConstantModelName.PROJECT, pParent, permission, nameof(request.Parent), pParent != entity.Parent))
            {
                entity.Parent = pParent;
            }
            if (AllowPatchValue <Project, string>(request, DocConstantModelName.PROJECT, pPICO, permission, nameof(request.PICO), pPICO != entity.PICO))
            {
                entity.PICO = pPICO;
            }
            if (AllowPatchValue <Project, string>(request, DocConstantModelName.PROJECT, pProjectId, permission, nameof(request.ProjectId), pProjectId != entity.ProjectId))
            {
                entity.ProjectId = pProjectId;
            }
            if (AllowPatchValue <Project, string>(request, DocConstantModelName.PROJECT, pProjectName, permission, nameof(request.ProjectName), pProjectName != entity.ProjectName))
            {
                entity.ProjectName = pProjectName;
            }
            if (AllowPatchValue <Project, ForeignKeyStatusEnm?>(request, DocConstantModelName.PROJECT, pStatus, permission, nameof(request.Status), pStatus != entity.Status))
            {
                entity.Status = pStatus;
            }
            if (request.Locked && AllowPatchValue <Project, bool>(request, DocConstantModelName.PROJECT, pArchived, permission, nameof(request.Locked), pLocked != entity.Locked))
            {
                entity.Archived = pArchived;
            }
            entity.SaveChanges(permission);

            var idsToInvalidate = new List <int>();

            idsToInvalidate.AddRange(PatchCollection <Project, DocEntityProject, Reference, DocEntityProject>(request, entity, pChildren, permission, nameof(request.Children)));
            idsToInvalidate.AddRange(PatchCollection <Project, DocEntityProject, Reference, DocEntityTimeCard>(request, entity, pTimeCards, permission, nameof(request.TimeCards)));
            if (idsToInvalidate.Any())
            {
                idsToInvalidate.Add(entity.Id);
                DocCacheClient.RemoveByEntityIds(idsToInvalidate);
                DocCacheClient.RemoveSearch(DocConstantModelName.PROJECT);
            }

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

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

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

            return(ret);
        }
Esempio n. 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);
        }