コード例 #1
0
        public VariableRule Post(VariableRuleCopy request)
        {
            VariableRule ret = null;

            using (Execute)
            {
                Execute.Run(ssn =>
                {
                    var entity = DocEntityVariableRule.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 pChildren   = entity.Children.ToList();
                    var pDefinition = entity.Definition;
                    var pInstances  = entity.Instances.ToList();
                    var pName       = entity.Name;
                    if (!DocTools.IsNullOrEmpty(pName))
                    {
                        pName += " (Copy)";
                    }
                    var pOwner  = entity.Owner;
                    var pRule   = entity.Rule;
                    var pScopes = entity.Scopes.ToList();
                    var pType   = entity.Type;
                    var copy    = new DocEntityVariableRule(ssn)
                    {
                        Hash         = Guid.NewGuid()
                        , Definition = pDefinition
                        , Name       = pName
                        , Owner      = pOwner
                        , Rule       = pRule
                        , Type       = pType
                    };
                    foreach (var item in pChildren)
                    {
                        entity.Children.Add(item);
                    }

                    foreach (var item in pInstances)
                    {
                        entity.Instances.Add(item);
                    }

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

                    copy.SaveChanges(DocConstantPermission.ADD);
                    ret = copy.ToDto();
                });
            }
            return(ret);
        }
コード例 #2
0
ファイル: FileService.cs プロジェクト: crfroehlich/codegen
        public File Post(FileCopy request)
        {
            File ret = null;

            using (Execute)
            {
                Execute.Run(ssn =>
                {
                    var entity = DocEntityFile.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 pCost      = entity.Cost;
                    var pFileLabel = entity.FileLabel;
                    if (!DocTools.IsNullOrEmpty(pFileLabel))
                    {
                        pFileLabel += " (Copy)";
                    }
                    var pFileName = entity.FileName;
                    if (!DocTools.IsNullOrEmpty(pFileName))
                    {
                        pFileName += " (Copy)";
                    }
                    var pOriginalFileName = entity.OriginalFileName;
                    if (!DocTools.IsNullOrEmpty(pOriginalFileName))
                    {
                        pOriginalFileName += " (Copy)";
                    }
                    var pRights = entity.Rights;
                    var pScopes = entity.Scopes.ToList();
                    var pSource = entity.Source;
                    var pType   = entity.Type;
                    var copy    = new DocEntityFile(ssn)
                    {
                        Hash               = Guid.NewGuid()
                        , Cost             = pCost
                        , FileLabel        = pFileLabel
                        , FileName         = pFileName
                        , OriginalFileName = pOriginalFileName
                        , Rights           = pRights
                        , Source           = pSource
                        , Type             = pType
                    };
                    foreach (var item in pScopes)
                    {
                        entity.Scopes.Add(item);
                    }

                    copy.SaveChanges(DocConstantPermission.ADD);
                    ret = copy.ToDto();
                });
            }
            return(ret);
        }
コード例 #3
0
        public Junction Post(JunctionCopy request)
        {
            Junction ret = null;

            using (Execute)
            {
                Execute.Run(ssn =>
                {
                    var entity = DocEntityJunction.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 pChildren  = entity.Children.ToList();
                    var pData      = entity.Data;
                    var pOwnerId   = entity.OwnerId;
                    var pOwnerType = entity.OwnerType;
                    if (!DocTools.IsNullOrEmpty(pOwnerType))
                    {
                        pOwnerType += " (Copy)";
                    }
                    var pParent     = entity.Parent;
                    var pTargetId   = entity.TargetId;
                    var pTargetType = entity.TargetType;
                    if (!DocTools.IsNullOrEmpty(pTargetType))
                    {
                        pTargetType += " (Copy)";
                    }
                    var pType = entity.Type;
                    var pUser = entity.User;
                    var copy  = new DocEntityJunction(ssn)
                    {
                        Hash         = Guid.NewGuid()
                        , Data       = pData
                        , OwnerId    = pOwnerId
                        , OwnerType  = pOwnerType
                        , Parent     = pParent
                        , TargetId   = pTargetId
                        , TargetType = pTargetType
                        , Type       = pType
                        , User       = pUser
                    };
                    foreach (var item in pChildren)
                    {
                        entity.Children.Add(item);
                    }

                    copy.SaveChanges(DocConstantPermission.ADD);
                    ret = copy.ToDto();
                });
            }
            return(ret);
        }
コード例 #4
0
        private void MiCreateDoc_1_Click(object sender, RoutedEventArgs e)
        {
            Vacation vacation = lvVacations.SelectedItem as Vacation;

            var fileTemplate = new FileInfo(@"C:\Users\Vladimir\source\repos\OVA.EasyLive\OVA.EasyLive\Template\Template_01.xlsx");

            string fullPath = "";

            // For World
            Dictionary <string, string> values = new Dictionary <string, string>();


            ExcelPackage.LicenseContext = LicenseContext.NonCommercial;

            using (var pakage = new ExcelPackage(fileTemplate))
            {
                // For Excel
                var sheet = pakage.Workbook.Worksheets["Лист1"];
                sheet.Cells[5, 6].Value  = currentUser.name.last;
                sheet.Cells[11, 3].Value = string.Format("с  {0:dd MMMM yyyy} по с  {1:dd MMMM yyyy}", vacation.End, vacation.Start);
                sheet.Cells[12, 4].Value = vacation.Length;
                sheet.Cells[16, 7].Value = string.Format("{0:dd MMMM yyyy} г.", vacation.Start);
                sheet.Cells[18, 7].Value = this.currentUser.name;

                // For World
                values.Add("flmUser", currentUser.name.first.ToString());
                values.Add("startDate", vacation.Start.ToString());
                values.Add("endDate", vacation.Start.ToString());
                values.Add("currentDate", DateTime.Now.ToString());


                DirectoryInfo dir = new DirectoryInfo(@"C:\Users\Vladimir\source\repos\OVA.EasyLive\OVA.EasyLive\Files\" + currentUser.name.last);

                if (!dir.Exists)
                {
                    dir.Create();
                }

                dir = new DirectoryInfo(@"C:\Users\Vladimir\source\repos\OVA.EasyLive\OVA.EasyLive\Files\" + currentUser.name.last + @"\" + vacation.Type);
                if (!dir.Exists)
                {
                    dir.Create();
                }

                fullPath = string.Format(@"{0}\{1}_{2:ddmmyyyy}.xlsx",
                                         dir.FullName,
                                         Guid.NewGuid().ToString(),
                                         DateTime.Now);

                pakage.SaveAs(File.Create(fullPath));
            }

            DocTools.SearchAndReplace(@"C:\Users\Vladimir\source\repos\OVA.EasyLive\OVA.EasyLive\Template\Template_01.docx",
                                      fullPath.Replace(".xlsx", ".docx"),
                                      values, "");
        }
コード例 #5
0
        public Broadcast Post(BroadcastCopy request)
        {
            Broadcast ret = null;

            using (Execute)
            {
                Execute.Run(ssn =>
                {
                    var entity = DocEntityBroadcast.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 pApp          = entity.App;
                    var pConfluenceId = entity.ConfluenceId;
                    if (!DocTools.IsNullOrEmpty(pConfluenceId))
                    {
                        pConfluenceId += " (Copy)";
                    }
                    var pName = entity.Name;
                    if (!DocTools.IsNullOrEmpty(pName))
                    {
                        pName += " (Copy)";
                    }
                    var pReprocess   = entity.Reprocess;
                    var pReprocessed = entity.Reprocessed;
                    var pScopes      = entity.Scopes.ToList();
                    var pStatus      = entity.Status;
                    var pType        = entity.Type;
                    var copy         = new DocEntityBroadcast(ssn)
                    {
                        Hash           = Guid.NewGuid()
                        , App          = pApp
                        , ConfluenceId = pConfluenceId
                        , Name         = pName
                        , Reprocess    = pReprocess
                        , Reprocessed  = pReprocessed
                        , Status       = pStatus
                        , Type         = pType
                    };
                    foreach (var item in pScopes)
                    {
                        entity.Scopes.Add(item);
                    }

                    copy.SaveChanges(DocConstantPermission.ADD);
                    ret = copy.ToDto();
                });
            }
            return(ret);
        }
コード例 #6
0
        public LookupTable Post(LookupTableCopy request)
        {
            LookupTable ret = null;

            using (Execute)
            {
                Execute.Run(ssn =>
                {
                    var entity = DocEntityLookupTable.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 pCategories = entity.Categories.ToList();
                    var pDocuments  = entity.Documents.ToList();
                    var pEnum       = entity.Enum;
                    var pName       = entity.Name;
                    if (!DocTools.IsNullOrEmpty(pName))
                    {
                        pName += " (Copy)";
                    }
                    var copy = new DocEntityLookupTable(ssn)
                    {
                        Hash   = Guid.NewGuid()
                        , Enum = pEnum
                        , Name = pName
                    };
                    foreach (var item in pBindings)
                    {
                        entity.Bindings.Add(item);
                    }

                    foreach (var item in pCategories)
                    {
                        entity.Categories.Add(item);
                    }

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

                    copy.SaveChanges(DocConstantPermission.ADD);
                    ret = copy.ToDto();
                });
            }
            return(ret);
        }
コード例 #7
0
        public Division Post(DivisionCopy request)
        {
            Division ret = null;

            using (Execute)
            {
                Execute.Run(ssn =>
                {
                    var entity = DocEntityDivision.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 pClient        = entity.Client;
                    var pDefaultLocale = entity.DefaultLocale;
                    var pDocumentSets  = entity.DocumentSets.ToList();
                    var pName          = entity.Name;
                    if (!DocTools.IsNullOrEmpty(pName))
                    {
                        pName += " (Copy)";
                    }
                    var pRole     = entity.Role;
                    var pSettings = entity.Settings;
                    var pUsers    = entity.Users.ToList();
                    var copy      = new DocEntityDivision(ssn)
                    {
                        Hash            = Guid.NewGuid()
                        , Client        = pClient
                        , DefaultLocale = pDefaultLocale
                        , Name          = pName
                        , Role          = pRole
                        , Settings      = pSettings
                    };
                    foreach (var item in pDocumentSets)
                    {
                        entity.DocumentSets.Add(item);
                    }

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

                    copy.SaveChanges(DocConstantPermission.ADD);
                    ret = copy.ToDto();
                });
            }
            return(ret);
        }
コード例 #8
0
        public WorkflowTask Post(WorkflowTaskCopy request)
        {
            WorkflowTask ret = null;

            using (Execute)
            {
                Execute.Run(ssn =>
                {
                    var entity = DocEntityWorkflowTask.GetWorkflowTask(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 pAssignee    = entity.Assignee;
                    var pData        = entity.Data;
                    var pDescription = entity.Description;
                    if (!DocTools.IsNullOrEmpty(pDescription))
                    {
                        pDescription += " (Copy)";
                    }
                    var pDueDate  = entity.DueDate;
                    var pReporter = entity.Reporter;
                    var pStatus   = entity.Status;
                    var pType     = entity.Type;
                    var pWorkflow = entity.Workflow;
                    #region Custom Before copyWorkflowTask
                    #endregion Custom Before copyWorkflowTask
                    var copy = new DocEntityWorkflowTask(ssn)
                    {
                        Hash          = Guid.NewGuid()
                        , Assignee    = pAssignee
                        , Data        = pData
                        , Description = pDescription
                        , DueDate     = pDueDate
                        , Reporter    = pReporter
                        , Status      = pStatus
                        , Type        = pType
                        , Workflow    = pWorkflow
                    };

                    #region Custom After copyWorkflowTask
                    #endregion Custom After copyWorkflowTask
                    copy.SaveChanges(DocConstantPermission.ADD);
                    ret = copy.ToDto();
                });
            }
            return(ret);
        }
コード例 #9
0
ファイル: RatingService.cs プロジェクト: crfroehlich/codegen
        public Rating Post(RatingCopy request)
        {
            Rating ret = null;

            using (Execute)
            {
                Execute.Run(ssn =>
                {
                    var entity = DocEntityRating.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 pAssignee    = entity.Assignee;
                    var pData        = entity.Data;
                    var pDescription = entity.Description;
                    if (!DocTools.IsNullOrEmpty(pDescription))
                    {
                        pDescription += " (Copy)";
                    }
                    var pDocument       = entity.Document;
                    var pDueDate        = entity.DueDate;
                    var pRating         = entity.Rating;
                    var pReasonRejected = entity.ReasonRejected;
                    var pReporter       = entity.Reporter;
                    var pType           = entity.Type;
                    var pWorkflow       = entity.Workflow;
                    var copy            = new DocEntityRating(ssn)
                    {
                        Hash             = Guid.NewGuid()
                        , Assignee       = pAssignee
                        , Data           = pData
                        , Description    = pDescription
                        , Document       = pDocument
                        , DueDate        = pDueDate
                        , Rating         = pRating
                        , ReasonRejected = pReasonRejected
                        , Reporter       = pReporter
                        , Type           = pType
                        , Workflow       = pWorkflow
                    };

                    copy.SaveChanges(DocConstantPermission.ADD);
                    ret = copy.ToDto();
                });
            }
            return(ret);
        }
コード例 #10
0
        public LookupTableBinding Post(LookupTableBindingCopy request)
        {
            LookupTableBinding ret = null;

            using (Execute)
            {
                Execute.Run(ssn =>
                {
                    var entity = DocEntityLookupTableBinding.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 pBinding   = entity.Binding;
                    var pBoundName = entity.BoundName;
                    if (!DocTools.IsNullOrEmpty(pBoundName))
                    {
                        pBoundName += " (Copy)";
                    }
                    var pLookupTable = entity.LookupTable;
                    var pScope       = entity.Scope;
                    var pSynonyms    = entity.Synonyms.ToList();
                    var pWorkflows   = entity.Workflows.ToList();
                    var copy         = new DocEntityLookupTableBinding(ssn)
                    {
                        Hash          = Guid.NewGuid()
                        , Binding     = pBinding
                        , BoundName   = pBoundName
                        , LookupTable = pLookupTable
                        , Scope       = pScope
                    };
                    foreach (var item in pSynonyms)
                    {
                        entity.Synonyms.Add(item);
                    }

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

                    copy.SaveChanges(DocConstantPermission.ADD);
                    ret = copy.ToDto();
                });
            }
            return(ret);
        }
コード例 #11
0
        public TimeCard Post(TimeCardCopy request)
        {
            TimeCard ret = null;

            using (Execute)
            {
                Execute.Run(ssn =>
                {
                    var entity = DocEntityTimeCard.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 pDescription = entity.Description;
                    if (!DocTools.IsNullOrEmpty(pDescription))
                    {
                        pDescription += " (Copy)";
                    }
                    var pDocument    = entity.Document;
                    var pEnd         = entity.End;
                    var pProject     = entity.Project;
                    var pReferenceId = entity.ReferenceId;
                    var pStart       = entity.Start;
                    var pStatus      = entity.Status;
                    var pUser        = entity.User;
                    var pWorkType    = entity.WorkType;
                    var copy         = new DocEntityTimeCard(ssn)
                    {
                        Hash          = Guid.NewGuid()
                        , Description = pDescription
                        , Document    = pDocument
                        , End         = pEnd
                        , Project     = pProject
                        , ReferenceId = pReferenceId
                        , Start       = pStart
                        , Status      = pStatus
                        , User        = pUser
                        , WorkType    = pWorkType
                    };

                    copy.SaveChanges(DocConstantPermission.ADD);
                    ret = copy.ToDto();
                });
            }
            return(ret);
        }
コード例 #12
0
        public QueueChannel Post(QueueChannelCopy request)
        {
            QueueChannel ret = null;

            using (Execute)
            {
                Execute.Run(ssn =>
                {
                    var entity = DocEntityQueueChannel.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 pAutoDelete     = entity.AutoDelete;
                    var pBackgroundTask = entity.BackgroundTask;
                    var pDescription    = entity.Description;
                    if (!DocTools.IsNullOrEmpty(pDescription))
                    {
                        pDescription += " (Copy)";
                    }
                    var pDurable   = entity.Durable;
                    var pEnabled   = entity.Enabled;
                    var pExclusive = entity.Exclusive;
                    var pName      = entity.Name;
                    if (!DocTools.IsNullOrEmpty(pName))
                    {
                        pName += " (Copy)";
                    }
                    var copy = new DocEntityQueueChannel(ssn)
                    {
                        Hash             = Guid.NewGuid()
                        , AutoDelete     = pAutoDelete
                        , BackgroundTask = pBackgroundTask
                        , Description    = pDescription
                        , Durable        = pDurable
                        , Enabled        = pEnabled
                        , Exclusive      = pExclusive
                        , Name           = pName
                    };

                    copy.SaveChanges(DocConstantPermission.ADD);
                    ret = copy.ToDto();
                });
            }
            return(ret);
        }
コード例 #13
0
        public Intervention Post(InterventionCopy request)
        {
            Intervention ret = null;

            using (Execute)
            {
                Execute.Run(ssn =>
                {
                    var entity = DocEntityIntervention.GetIntervention(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 pDocumentSets = entity.DocumentSets.ToList();
                    var pName         = entity.Name;
                    if (!DocTools.IsNullOrEmpty(pName))
                    {
                        pName += " (Copy)";
                    }
                    var pURI = entity.URI;
                    if (!DocTools.IsNullOrEmpty(pURI))
                    {
                        pURI += " (Copy)";
                    }
                    #region Custom Before copyIntervention
                    #endregion Custom Before copyIntervention
                    var copy = new DocEntityIntervention(ssn)
                    {
                        Hash   = Guid.NewGuid()
                        , Name = pName
                        , URI  = pURI
                    };
                    foreach (var item in pDocumentSets)
                    {
                        entity.DocumentSets.Add(item);
                    }

                    #region Custom After copyIntervention
                    #endregion Custom After copyIntervention
                    copy.SaveChanges(DocConstantPermission.ADD);
                    ret = copy.ToDto();
                });
            }
            return(ret);
        }
コード例 #14
0
        public Attribute Post(AttributeCopy request)
        {
            Attribute ret = null;

            using (Execute)
            {
                Execute.Run(ssn =>
                {
                    var entity = DocEntityAttribute.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 pAttributeName    = entity.AttributeName;
                    var pAttributeType    = entity.AttributeType;
                    var pInterval         = entity.Interval;
                    var pIsCharacteristic = entity.IsCharacteristic;
                    var pIsOutcome        = entity.IsOutcome;
                    var pIsPositive       = entity.IsPositive;
                    var pUniqueKey        = entity.UniqueKey;
                    if (!DocTools.IsNullOrEmpty(pUniqueKey))
                    {
                        pUniqueKey += " (Copy)";
                    }
                    var pValueType = entity.ValueType;
                    var copy       = new DocEntityAttribute(ssn)
                    {
                        Hash               = Guid.NewGuid()
                        , AttributeName    = pAttributeName
                        , AttributeType    = pAttributeType
                        , Interval         = pInterval
                        , IsCharacteristic = pIsCharacteristic
                        , IsOutcome        = pIsOutcome
                        , IsPositive       = pIsPositive
                        , UniqueKey        = pUniqueKey
                        , ValueType        = pValueType
                    };

                    copy.SaveChanges(DocConstantPermission.ADD);
                    ret = copy.ToDto();
                });
            }
            return(ret);
        }
コード例 #15
0
ファイル: HistoryService.cs プロジェクト: crfroehlich/codegen
        public History Post(HistoryCopy request)
        {
            History ret = null;

            using (Execute)
            {
                Execute.Run(ssn =>
                {
                    var entity = DocEntityHistory.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 pApp           = entity.App;
                    var pDocumentSet   = entity.DocumentSet;
                    var pImpersonation = entity.Impersonation;
                    var pPage          = entity.Page;
                    var pURL           = entity.URL;
                    if (!DocTools.IsNullOrEmpty(pURL))
                    {
                        pURL += " (Copy)";
                    }
                    var pUser        = entity.User;
                    var pUserSession = entity.UserSession;
                    var pWorkflow    = entity.Workflow;
                    var copy         = new DocEntityHistory(ssn)
                    {
                        Hash            = Guid.NewGuid()
                        , App           = pApp
                        , DocumentSet   = pDocumentSet
                        , Impersonation = pImpersonation
                        , Page          = pPage
                        , URL           = pURL
                        , User          = pUser
                        , UserSession   = pUserSession
                        , Workflow      = pWorkflow
                    };

                    copy.SaveChanges(DocConstantPermission.ADD);
                    ret = copy.ToDto();
                });
            }
            return(ret);
        }
コード例 #16
0
        public TermSynonym Post(TermSynonymCopy request)
        {
            TermSynonym ret = null;

            using (Execute)
            {
                Execute.Run(ssn =>
                {
                    var entity = DocEntityTermSynonym.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 pApproved  = entity.Approved;
                    var pBindings  = entity.Bindings.ToList();
                    var pMaster    = entity.Master;
                    var pPreferred = entity.Preferred;
                    var pScope     = entity.Scope;
                    var pSynonym   = entity.Synonym;
                    if (!DocTools.IsNullOrEmpty(pSynonym))
                    {
                        pSynonym += " (Copy)";
                    }
                    var copy = new DocEntityTermSynonym(ssn)
                    {
                        Hash        = Guid.NewGuid()
                        , Approved  = pApproved
                        , Master    = pMaster
                        , Preferred = pPreferred
                        , Scope     = pScope
                        , Synonym   = pSynonym
                    };
                    foreach (var item in pBindings)
                    {
                        entity.Bindings.Add(item);
                    }

                    copy.SaveChanges(DocConstantPermission.ADD);
                    ret = copy.ToDto();
                });
            }
            return(ret);
        }
コード例 #17
0
        public Locale Post(LocaleCopy request)
        {
            Locale ret = null;

            using (Execute)
            {
                Execute.Run(ssn =>
                {
                    var entity = DocEntityLocale.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 pCountry = entity.Country;
                    if (!DocTools.IsNullOrEmpty(pCountry))
                    {
                        pCountry += " (Copy)";
                    }
                    var pLanguage = entity.Language;
                    if (!DocTools.IsNullOrEmpty(pLanguage))
                    {
                        pLanguage += " (Copy)";
                    }
                    var pTimeZone = entity.TimeZone;
                    if (!DocTools.IsNullOrEmpty(pTimeZone))
                    {
                        pTimeZone += " (Copy)";
                    }
                    var copy = new DocEntityLocale(ssn)
                    {
                        Hash       = Guid.NewGuid()
                        , Country  = pCountry
                        , Language = pLanguage
                        , TimeZone = pTimeZone
                    };

                    copy.SaveChanges(DocConstantPermission.ADD);
                    ret = copy.ToDto();
                });
            }
            return(ret);
        }
コード例 #18
0
        public LookupCategory Post(LookupCategoryCopy request)
        {
            LookupCategory ret = null;

            using (Execute)
            {
                Execute.Run(ssn =>
                {
                    var entity = DocEntityLookupCategory.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 pCategory = entity.Category;
                    if (!DocTools.IsNullOrEmpty(pCategory))
                    {
                        pCategory += " (Copy)";
                    }
                    var pEnum           = entity.Enum;
                    var pLookups        = entity.Lookups.ToList();
                    var pParentCategory = entity.ParentCategory;
                    var copy            = new DocEntityLookupCategory(ssn)
                    {
                        Hash             = Guid.NewGuid()
                        , Category       = pCategory
                        , Enum           = pEnum
                        , ParentCategory = pParentCategory
                    };
                    foreach (var item in pLookups)
                    {
                        entity.Lookups.Add(item);
                    }

                    copy.SaveChanges(DocConstantPermission.ADD);
                    ret = copy.ToDto();
                });
            }
            return(ret);
        }
コード例 #19
0
        public Interval Post(IntervalCopy request)
        {
            Interval ret = null;

            using (Execute)
            {
                Execute.Run(ssn =>
                {
                    var entity = DocEntityInterval.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 pCalendarDateEnd   = entity.CalendarDateEnd;
                    var pCalendarDateStart = entity.CalendarDateStart;
                    var pCalendarType      = entity.CalendarType;
                    if (!DocTools.IsNullOrEmpty(pCalendarType))
                    {
                        pCalendarType += " (Copy)";
                    }
                    var pFollowUp  = entity.FollowUp;
                    var pTimeOfDay = entity.TimeOfDay;
                    var copy       = new DocEntityInterval(ssn)
                    {
                        Hash = Guid.NewGuid()
                        , CalendarDateEnd   = pCalendarDateEnd
                        , CalendarDateStart = pCalendarDateStart
                        , CalendarType      = pCalendarType
                        , FollowUp          = pFollowUp
                        , TimeOfDay         = pTimeOfDay
                    };

                    copy.SaveChanges(DocConstantPermission.ADD);
                    ret = copy.ToDto();
                });
            }
            return(ret);
        }
コード例 #20
0
        public Glossary Post(GlossaryCopy request)
        {
            Glossary ret = null;

            using (Execute)
            {
                Execute.Run(ssn =>
                {
                    var entity = DocEntityGlossary.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 pDefinition = entity.Definition;
                    var pEnum       = entity.Enum;
                    var pIcon       = entity.Icon;
                    if (!DocTools.IsNullOrEmpty(pIcon))
                    {
                        pIcon += " (Copy)";
                    }
                    var pPage = entity.Page;
                    var pTerm = entity.Term;
                    var copy  = new DocEntityGlossary(ssn)
                    {
                        Hash         = Guid.NewGuid()
                        , Definition = pDefinition
                        , Enum       = pEnum
                        , Icon       = pIcon
                        , Page       = pPage
                        , Term       = pTerm
                    };

                    copy.SaveChanges(DocConstantPermission.ADD);
                    ret = copy.ToDto();
                });
            }
            return(ret);
        }
コード例 #21
0
ファイル: TrialService.cs プロジェクト: crfroehlich/codegen
        public Trial Post(TrialCopy request)
        {
            Trial ret = null;

            using (Execute)
            {
                Execute.Run(ssn =>
                {
                    var entity = DocEntityTrial.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 pDocuments = entity.Documents.ToList();
                    var pName      = entity.Name;
                    if (!DocTools.IsNullOrEmpty(pName))
                    {
                        pName += " (Copy)";
                    }
                    var pParent = entity.Parent;
                    var copy    = new DocEntityTrial(ssn)
                    {
                        Hash     = Guid.NewGuid()
                        , Name   = pName
                        , Parent = pParent
                    };
                    foreach (var item in pDocuments)
                    {
                        entity.Documents.Add(item);
                    }

                    copy.SaveChanges(DocConstantPermission.ADD);
                    ret = copy.ToDto();
                });
            }
            return(ret);
        }
コード例 #22
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);
        }
コード例 #23
0
        public LocaleLookup Post(LocaleLookupCopy request)
        {
            LocaleLookup ret = null;

            using (Execute)
            {
                Execute.Run(ssn =>
                {
                    var entity = DocEntityLocaleLookup.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 pData      = entity.Data;
                    var pIpAddress = entity.IpAddress;
                    if (!DocTools.IsNullOrEmpty(pIpAddress))
                    {
                        pIpAddress += " (Copy)";
                    }
                    var pLocale = entity.Locale;
                    var copy    = new DocEntityLocaleLookup(ssn)
                    {
                        Hash        = Guid.NewGuid()
                        , Data      = pData
                        , IpAddress = pIpAddress
                        , Locale    = pLocale
                    };

                    copy.SaveChanges(DocConstantPermission.ADD);
                    ret = copy.ToDto();
                });
            }
            return(ret);
        }
コード例 #24
0
ファイル: TeamService.cs プロジェクト: crfroehlich/codegen
        private IQueryable <DocEntityTeam> _ExecSearch(TeamSearch request, DocQuery query)
        {
            request = InitSearch <Team, TeamSearch>(request);
            IQueryable <DocEntityTeam> entities = null;

            query.Run(session =>
            {
                entities = query.SelectAll <DocEntityTeam>();
                if (!DocTools.IsNullOrEmpty(request.FullTextSearch))
                {
                    var fts  = new TeamFullTextSearch(request);
                    entities = GetFullTextSearch <DocEntityTeam, TeamFullTextSearch>(fts, entities);
                }

                if (null != request.Ids && request.Ids.Any())
                {
                    entities = entities.Where(en => en.Id.In(request.Ids));
                }

                if (!DocTools.IsNullOrEmpty(request.Updated))
                {
                    entities = entities.Where(e => null != e.Updated && e.Updated.Value.Date == request.Updated.Value.Date);
                }
                if (!DocTools.IsNullOrEmpty(request.UpdatedBefore))
                {
                    entities = entities.Where(e => null != e.Updated && e.Updated <= request.UpdatedBefore);
                }
                if (!DocTools.IsNullOrEmpty(request.UpdatedAfter))
                {
                    entities = entities.Where(e => null != e.Updated && e.Updated >= request.UpdatedAfter);
                }
                if (!DocTools.IsNullOrEmpty(request.Created))
                {
                    entities = entities.Where(e => null != e.Created && e.Created.Value.Date == request.Created.Value.Date);
                }
                if (!DocTools.IsNullOrEmpty(request.CreatedBefore))
                {
                    entities = entities.Where(e => null != e.Created && e.Created <= request.CreatedBefore);
                }
                if (!DocTools.IsNullOrEmpty(request.CreatedAfter))
                {
                    entities = entities.Where(e => null != e.Created && e.Created >= request.CreatedAfter);
                }
                if (true == request.Archived?.Any() && currentUser.HasProperty(DocConstantModelName.TEAM, nameof(Reference.Archived), DocConstantPermission.VIEW))
                {
                    entities = entities.Where(en => en.Archived.In(request.Archived));
                }
                else
                {
                    entities = entities.Where(en => !en.Archived);
                }
                if (true == request.Locked?.Any())
                {
                    entities = entities.Where(en => en.Locked.In(request.Locked));
                }
                if (true == request.AdminRolesIds?.Any())
                {
                    entities = entities.Where(en => en.AdminRoles.Any(r => r.Id.In(request.AdminRolesIds)));
                }
                if (!DocTools.IsNullOrEmpty(request.Description))
                {
                    entities = entities.Where(en => en.Description.Contains(request.Description));
                }
                if (!DocTools.IsNullOrEmpty(request.Descriptions))
                {
                    entities = entities.Where(en => en.Description.In(request.Descriptions));
                }
                if (!DocTools.IsNullOrEmpty(request.Email))
                {
                    entities = entities.Where(en => en.Email.Contains(request.Email));
                }
                if (!DocTools.IsNullOrEmpty(request.Emails))
                {
                    entities = entities.Where(en => en.Email.In(request.Emails));
                }
                if (true == request.IsInternal?.Any())
                {
                    entities = entities.Where(en => en.IsInternal.In(request.IsInternal));
                }
                if (!DocTools.IsNullOrEmpty(request.Name))
                {
                    entities = entities.Where(en => en.Name.Contains(request.Name));
                }
                if (!DocTools.IsNullOrEmpty(request.Names))
                {
                    entities = entities.Where(en => en.Name.In(request.Names));
                }
                if (!DocTools.IsNullOrEmpty(request.Owner) && !DocTools.IsNullOrEmpty(request.Owner.Id))
                {
                    entities = entities.Where(en => en.Owner.Id == request.Owner.Id);
                }
                if (true == request.OwnerIds?.Any())
                {
                    entities = entities.Where(en => en.Owner.Id.In(request.OwnerIds));
                }
                if (true == request.ScopesIds?.Any())
                {
                    entities = entities.Where(en => en.Scopes.Any(r => r.Id.In(request.ScopesIds)));
                }
                if (!DocTools.IsNullOrEmpty(request.Slack))
                {
                    entities = entities.Where(en => en.Slack.Contains(request.Slack));
                }
                if (!DocTools.IsNullOrEmpty(request.Slacks))
                {
                    entities = entities.Where(en => en.Slack.In(request.Slacks));
                }
                if (true == request.UpdatesIds?.Any())
                {
                    entities = entities.Where(en => en.Updates.Any(r => r.Id.In(request.UpdatesIds)));
                }
                if (true == request.UsersIds?.Any())
                {
                    entities = entities.Where(en => en.Users.Any(r => r.Id.In(request.UsersIds)));
                }

                entities = ApplyFilters <DocEntityTeam, TeamSearch>(request, entities);

                if (request.Skip > 0)
                {
                    entities = entities.Skip(request.Skip.Value);
                }
                if (request.Take > 0)
                {
                    entities = entities.Take(request.Take.Value);
                }
                if (true == request?.OrderBy?.Any())
                {
                    entities = entities.OrderBy(request.OrderBy);
                }
                if (true == request?.OrderByDesc?.Any())
                {
                    entities = entities.OrderByDescending(request.OrderByDesc);
                }
            });
            return(entities);
        }
コード例 #25
0
        private IQueryable <DocEntityIntervention> _ExecSearch(InterventionSearch request, DocQuery query)
        {
            request = InitSearch <Intervention, InterventionSearch>(request);
            IQueryable <DocEntityIntervention> entities = null;

            query.Run(session =>
            {
                entities = query.SelectAll <DocEntityIntervention>();
                if (!DocTools.IsNullOrEmpty(request.FullTextSearch))
                {
                    var fts  = new InterventionFullTextSearch(request);
                    entities = GetFullTextSearch <DocEntityIntervention, InterventionFullTextSearch>(fts, entities);
                }

                if (null != request.Ids && request.Ids.Any())
                {
                    entities = entities.Where(en => en.Id.In(request.Ids));
                }

                if (!DocTools.IsNullOrEmpty(request.Updated))
                {
                    entities = entities.Where(e => null != e.Updated && e.Updated.Value.Date == request.Updated.Value.Date);
                }
                if (!DocTools.IsNullOrEmpty(request.UpdatedBefore))
                {
                    entities = entities.Where(e => null != e.Updated && e.Updated <= request.UpdatedBefore);
                }
                if (!DocTools.IsNullOrEmpty(request.UpdatedAfter))
                {
                    entities = entities.Where(e => null != e.Updated && e.Updated >= request.UpdatedAfter);
                }
                if (!DocTools.IsNullOrEmpty(request.Created))
                {
                    entities = entities.Where(e => null != e.Created && e.Created.Value.Date == request.Created.Value.Date);
                }
                if (!DocTools.IsNullOrEmpty(request.CreatedBefore))
                {
                    entities = entities.Where(e => null != e.Created && e.Created <= request.CreatedBefore);
                }
                if (!DocTools.IsNullOrEmpty(request.CreatedAfter))
                {
                    entities = entities.Where(e => null != e.Created && e.Created >= request.CreatedAfter);
                }
                if (true == request.Archived?.Any() && currentUser.HasProperty(DocConstantModelName.INTERVENTION, nameof(Reference.Archived), DocConstantPermission.VIEW))
                {
                    entities = entities.Where(en => en.Archived.In(request.Archived));
                }
                else
                {
                    entities = entities.Where(en => !en.Archived);
                }
                if (true == request.Locked?.Any())
                {
                    entities = entities.Where(en => en.Locked.In(request.Locked));
                }

                if (true == request.DocumentSetsIds?.Any())
                {
                    entities = entities.Where(en => en.DocumentSets.Any(r => r.Id.In(request.DocumentSetsIds)));
                }
                if (!DocTools.IsNullOrEmpty(request.Name))
                {
                    entities = entities.Where(en => en.Name.Contains(request.Name));
                }
                if (!DocTools.IsNullOrEmpty(request.URI))
                {
                    entities = entities.Where(en => en.URI.Contains(request.URI));
                }

                entities = ApplyFilters <DocEntityIntervention, InterventionSearch>(request, entities);

                if (request.Skip > 0)
                {
                    entities = entities.Skip(request.Skip.Value);
                }
                if (request.Take > 0)
                {
                    entities = entities.Take(request.Take.Value);
                }
                if (true == request?.OrderBy?.Any())
                {
                    entities = entities.OrderBy(request.OrderBy);
                }
                if (true == request?.OrderByDesc?.Any())
                {
                    entities = entities.OrderByDescending(request.OrderByDesc);
                }
            });
            return(entities);
        }
コード例 #26
0
        private Intervention _AssignValues(Intervention 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, "Intervention"))
            {
                throw new HttpError(HttpStatusCode.Forbidden, "You do not have ADD permission for this route.");
            }

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

            Intervention ret = null;

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

            //First, assign all the variables, do database lookups and conversions
            var pDocumentSets = request.DocumentSets?.ToList();
            var pName         = request.Name;
            var pURI          = request.URI;

            DocEntityIntervention entity = null;

            if (permission == DocConstantPermission.ADD)
            {
                var now = DateTime.UtcNow;
                entity = new DocEntityIntervention(session)
                {
                    Created = now,
                    Updated = now
                };
            }
            else
            {
                entity = DocEntityIntervention.GetIntervention(request.Id);
                if (null == entity)
                {
                    throw new HttpError(HttpStatusCode.NotFound, $"No record");
                }
            }

            //Special case for Archived
            var pArchived = true == request.Archived;

            if (DocPermissionFactory.IsRequestedHasPermission <bool>(currentUser, request, pArchived, permission, DocConstantModelName.INTERVENTION, nameof(request.Archived)))
            {
                if (DocPermissionFactory.IsRequested(request, pArchived, entity.Archived, nameof(request.Archived)))
                {
                    if (DocResources.Metadata.IsInsertOnly(DocConstantModelName.INTERVENTION, nameof(request.Archived)) && DocConstantPermission.ADD != permission)
                    {
                        throw new HttpError(HttpStatusCode.Forbidden, $"{nameof(request.Archived)} cannot be modified once set.");
                    }
                }
                if (DocTools.IsNullOrEmpty(pArchived) && DocResources.Metadata.IsRequired(DocConstantModelName.INTERVENTION, nameof(request.Archived)))
                {
                    throw new HttpError(HttpStatusCode.BadRequest, $"{nameof(request.Archived)} requires a value.");
                }
                entity.Archived = pArchived;
                if (DocPermissionFactory.IsRequested <bool>(request, pArchived, nameof(request.Archived)) && !request.VisibleFields.Matches(nameof(request.Archived), ignoreSpaces: true))
                {
                    request.VisibleFields.Add(nameof(request.Archived));
                }
            }

            if (DocPermissionFactory.IsRequestedHasPermission <string>(currentUser, request, pName, permission, DocConstantModelName.INTERVENTION, nameof(request.Name)))
            {
                if (DocPermissionFactory.IsRequested(request, pName, entity.Name, nameof(request.Name)))
                {
                    if (DocResources.Metadata.IsInsertOnly(DocConstantModelName.INTERVENTION, nameof(request.Name)) && DocConstantPermission.ADD != permission)
                    {
                        throw new HttpError(HttpStatusCode.Forbidden, $"{nameof(request.Name)} cannot be modified once set.");
                    }
                }
                if (DocTools.IsNullOrEmpty(pName) && DocResources.Metadata.IsRequired(DocConstantModelName.INTERVENTION, nameof(request.Name)))
                {
                    throw new HttpError(HttpStatusCode.BadRequest, $"{nameof(request.Name)} requires a value.");
                }
                entity.Name = pName;
                if (DocPermissionFactory.IsRequested <string>(request, pName, nameof(request.Name)) && !request.VisibleFields.Matches(nameof(request.Name), ignoreSpaces: true))
                {
                    request.VisibleFields.Add(nameof(request.Name));
                }
            }
            if (DocPermissionFactory.IsRequestedHasPermission <string>(currentUser, request, pURI, permission, DocConstantModelName.INTERVENTION, nameof(request.URI)))
            {
                if (DocPermissionFactory.IsRequested(request, pURI, entity.URI, nameof(request.URI)))
                {
                    if (DocResources.Metadata.IsInsertOnly(DocConstantModelName.INTERVENTION, nameof(request.URI)) && DocConstantPermission.ADD != permission)
                    {
                        throw new HttpError(HttpStatusCode.Forbidden, $"{nameof(request.URI)} cannot be modified once set.");
                    }
                }
                if (DocTools.IsNullOrEmpty(pURI) && DocResources.Metadata.IsRequired(DocConstantModelName.INTERVENTION, nameof(request.URI)))
                {
                    throw new HttpError(HttpStatusCode.BadRequest, $"{nameof(request.URI)} requires a value.");
                }
                entity.URI = pURI;
                if (DocPermissionFactory.IsRequested <string>(request, pURI, nameof(request.URI)) && !request.VisibleFields.Matches(nameof(request.URI), ignoreSpaces: true))
                {
                    request.VisibleFields.Add(nameof(request.URI));
                }
            }

            if (request.Locked)
            {
                entity.Locked = request.Locked;
            }

            entity.SaveChanges(permission);

            if (DocPermissionFactory.IsRequestedHasPermission <List <Reference> >(currentUser, request, pDocumentSets, permission, DocConstantModelName.INTERVENTION, nameof(request.DocumentSets)))
            {
                if (true == pDocumentSets?.Any())
                {
                    var requestedDocumentSets = pDocumentSets.Select(p => p.Id).Distinct().ToList();
                    var existsDocumentSets    = Execute.SelectAll <DocEntityDocumentSet>().Where(e => e.Id.In(requestedDocumentSets)).Select(e => e.Id).ToList();
                    if (existsDocumentSets.Count != requestedDocumentSets.Count)
                    {
                        var nonExists = requestedDocumentSets.Where(id => existsDocumentSets.All(eId => eId != id));
                        throw new HttpError(HttpStatusCode.NotFound, $"Cannot patch collection DocumentSets with objects that do not exist. No matching DocumentSets(s) could be found for Ids: {nonExists.ToDelimitedString()}.");
                    }
                    var toAdd = requestedDocumentSets.Where(id => entity.DocumentSets.All(e => e.Id != id)).ToList();
                    toAdd?.ForEach(id =>
                    {
                        var target = DocEntityDocumentSet.GetDocumentSet(id);
                        if (!DocPermissionFactory.HasPermission(entity, currentUser, DocConstantPermission.ADD, targetEntity: target, targetName: nameof(Intervention), columnName: nameof(request.DocumentSets)))
                        {
                            throw new HttpError(HttpStatusCode.Forbidden, "You do not have permission to add {nameof(request.DocumentSets)} to {nameof(Intervention)}");
                        }
                        entity.DocumentSets.Add(target);
                    });
                    var toRemove = entity.DocumentSets.Where(e => requestedDocumentSets.All(id => e.Id != id)).Select(e => e.Id).ToList();
                    toRemove.ForEach(id =>
                    {
                        var target = DocEntityDocumentSet.GetDocumentSet(id);
                        if (!DocPermissionFactory.HasPermission(entity, currentUser, DocConstantPermission.REMOVE, targetEntity: target, targetName: nameof(Intervention), columnName: nameof(request.DocumentSets)))
                        {
                            throw new HttpError(HttpStatusCode.Forbidden, "You do not have permission to remove {nameof(request.DocumentSets)} from {nameof(Intervention)}");
                        }
                        entity.DocumentSets.Remove(target);
                    });
                }
                else
                {
                    var toRemove = entity.DocumentSets.Select(e => e.Id).ToList();
                    toRemove.ForEach(id =>
                    {
                        var target = DocEntityDocumentSet.GetDocumentSet(id);
                        if (!DocPermissionFactory.HasPermission(entity, currentUser, DocConstantPermission.REMOVE, targetEntity: target, targetName: nameof(Intervention), columnName: nameof(request.DocumentSets)))
                        {
                            throw new HttpError(HttpStatusCode.Forbidden, "You do not have permission to remove {nameof(request.DocumentSets)} from {nameof(Intervention)}");
                        }
                        entity.DocumentSets.Remove(target);
                    });
                }
                if (DocPermissionFactory.IsRequested <List <Reference> >(request, pDocumentSets, nameof(request.DocumentSets)) && !request.VisibleFields.Matches(nameof(request.DocumentSets), ignoreSpaces: true))
                {
                    request.VisibleFields.Add(nameof(request.DocumentSets));
                }
            }
            DocPermissionFactory.SetVisibleFields <Intervention>(currentUser, nameof(Intervention), request.VisibleFields);
            ret = entity.ToDto();

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

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

            return(ret);
        }
コード例 #27
0
 public static bool operator ==(DocConstantArmPopulationAge x, DocConstantArmPopulationAge y) => DocTools.AreEqual(DocConvert.ToString(x), DocConvert.ToString(y));
コード例 #28
0
ファイル: TeamService.cs プロジェクト: crfroehlich/codegen
        public Team Post(TeamCopy request)
        {
            Team ret = null;

            using (Execute)
            {
                Execute.Run(ssn =>
                {
                    var entity = DocEntityTeam.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 pAdminRoles  = entity.AdminRoles.ToList();
                    var pDescription = entity.Description;
                    if (!DocTools.IsNullOrEmpty(pDescription))
                    {
                        pDescription += " (Copy)";
                    }
                    var pEmail = entity.Email;
                    if (!DocTools.IsNullOrEmpty(pEmail))
                    {
                        pEmail += " (Copy)";
                    }
                    var pIsInternal = entity.IsInternal;
                    var pName       = entity.Name;
                    if (!DocTools.IsNullOrEmpty(pName))
                    {
                        pName += " (Copy)";
                    }
                    var pOwner    = entity.Owner;
                    var pScopes   = entity.Scopes.ToList();
                    var pSettings = entity.Settings;
                    var pSlack    = entity.Slack;
                    if (!DocTools.IsNullOrEmpty(pSlack))
                    {
                        pSlack += " (Copy)";
                    }
                    var pUpdates = entity.Updates.ToList();
                    var pUsers   = entity.Users.ToList();
                    var copy     = new DocEntityTeam(ssn)
                    {
                        Hash          = Guid.NewGuid()
                        , Description = pDescription
                        , Email       = pEmail
                        , IsInternal  = pIsInternal
                        , Name        = pName
                        , Owner       = pOwner
                        , Settings    = pSettings
                        , Slack       = pSlack
                    };
                    foreach (var item in pAdminRoles)
                    {
                        entity.AdminRoles.Add(item);
                    }

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

                    foreach (var item in pUpdates)
                    {
                        entity.Updates.Add(item);
                    }

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

                    copy.SaveChanges(DocConstantPermission.ADD);
                    ret = copy.ToDto();
                });
            }
            return(ret);
        }
コード例 #29
0
        private IQueryable <DocEntityTimeCard> _ExecSearch(TimeCardSearch request, DocQuery query)
        {
            request = InitSearch <TimeCard, TimeCardSearch>(request);
            IQueryable <DocEntityTimeCard> entities = null;

            query.Run(session =>
            {
                entities = query.SelectAll <DocEntityTimeCard>();
                if (!DocTools.IsNullOrEmpty(request.FullTextSearch))
                {
                    var fts  = new TimeCardFullTextSearch(request);
                    entities = GetFullTextSearch <DocEntityTimeCard, TimeCardFullTextSearch>(fts, entities);
                }

                if (null != request.Ids && request.Ids.Any())
                {
                    entities = entities.Where(en => en.Id.In(request.Ids));
                }

                if (!DocTools.IsNullOrEmpty(request.Updated))
                {
                    entities = entities.Where(e => null != e.Updated && e.Updated.Value.Date == request.Updated.Value.Date);
                }
                if (!DocTools.IsNullOrEmpty(request.UpdatedBefore))
                {
                    entities = entities.Where(e => null != e.Updated && e.Updated <= request.UpdatedBefore);
                }
                if (!DocTools.IsNullOrEmpty(request.UpdatedAfter))
                {
                    entities = entities.Where(e => null != e.Updated && e.Updated >= request.UpdatedAfter);
                }
                if (!DocTools.IsNullOrEmpty(request.Created))
                {
                    entities = entities.Where(e => null != e.Created && e.Created.Value.Date == request.Created.Value.Date);
                }
                if (!DocTools.IsNullOrEmpty(request.CreatedBefore))
                {
                    entities = entities.Where(e => null != e.Created && e.Created <= request.CreatedBefore);
                }
                if (!DocTools.IsNullOrEmpty(request.CreatedAfter))
                {
                    entities = entities.Where(e => null != e.Created && e.Created >= request.CreatedAfter);
                }
                if (true == request.Archived?.Any() && currentUser.HasProperty(DocConstantModelName.TIMECARD, nameof(Reference.Archived), DocConstantPermission.VIEW))
                {
                    entities = entities.Where(en => en.Archived.In(request.Archived));
                }
                else
                {
                    entities = entities.Where(en => !en.Archived);
                }
                if (true == request.Locked?.Any())
                {
                    entities = entities.Where(en => en.Locked.In(request.Locked));
                }
                if (!DocTools.IsNullOrEmpty(request.Description))
                {
                    entities = entities.Where(en => en.Description.Contains(request.Description));
                }
                if (!DocTools.IsNullOrEmpty(request.Descriptions))
                {
                    entities = entities.Where(en => en.Description.In(request.Descriptions));
                }
                if (!DocTools.IsNullOrEmpty(request.Document) && !DocTools.IsNullOrEmpty(request.Document.Id))
                {
                    entities = entities.Where(en => en.Document.Id == request.Document.Id);
                }
                if (true == request.DocumentIds?.Any())
                {
                    entities = entities.Where(en => en.Document.Id.In(request.DocumentIds));
                }
                if (!DocTools.IsNullOrEmpty(request.End))
                {
                    entities = entities.Where(en => request.End.Value.Date == en.End.Date);
                }
                if (!DocTools.IsNullOrEmpty(request.EndBefore))
                {
                    entities = entities.Where(en => en.End <= request.EndBefore);
                }
                if (!DocTools.IsNullOrEmpty(request.EndAfter))
                {
                    entities = entities.Where(en => en.End >= request.EndAfter);
                }
                if (!DocTools.IsNullOrEmpty(request.Project) && !DocTools.IsNullOrEmpty(request.Project.Id))
                {
                    entities = entities.Where(en => en.Project.Id == request.Project.Id);
                }
                if (true == request.ProjectIds?.Any())
                {
                    entities = entities.Where(en => en.Project.Id.In(request.ProjectIds));
                }
                if (request.ReferenceId.HasValue)
                {
                    entities = entities.Where(en => request.ReferenceId.Value == en.ReferenceId);
                }
                if (!DocTools.IsNullOrEmpty(request.Start))
                {
                    entities = entities.Where(en => request.Start.Value.Date == en.Start.Date);
                }
                if (!DocTools.IsNullOrEmpty(request.StartBefore))
                {
                    entities = entities.Where(en => en.Start <= request.StartBefore);
                }
                if (!DocTools.IsNullOrEmpty(request.StartAfter))
                {
                    entities = entities.Where(en => en.Start >= request.StartAfter);
                }
                if (!DocTools.IsNullOrEmpty(request.Status) && !DocTools.IsNullOrEmpty(request.Status.Id))
                {
                    entities = entities.Where(en => en.Status.Id == request.Status.Id);
                }
                if (true == request.StatusIds?.Any())
                {
                    entities = entities.Where(en => en.Status.Id.In(request.StatusIds));
                }
                else if (!DocTools.IsNullOrEmpty(request.Status) && !DocTools.IsNullOrEmpty(request.Status.Name))
                {
                    entities = entities.Where(en => en.Status.Name == request.Status.Name);
                }
                if (true == request.StatusNames?.Any())
                {
                    entities = entities.Where(en => en.Status.Name.In(request.StatusNames));
                }
                if (!DocTools.IsNullOrEmpty(request.User) && !DocTools.IsNullOrEmpty(request.User.Id))
                {
                    entities = entities.Where(en => en.User.Id == request.User.Id);
                }
                if (true == request.UserIds?.Any())
                {
                    entities = entities.Where(en => en.User.Id.In(request.UserIds));
                }
                if (!DocTools.IsNullOrEmpty(request.WorkType) && !DocTools.IsNullOrEmpty(request.WorkType.Id))
                {
                    entities = entities.Where(en => en.WorkType.Id == request.WorkType.Id);
                }
                if (true == request.WorkTypeIds?.Any())
                {
                    entities = entities.Where(en => en.WorkType.Id.In(request.WorkTypeIds));
                }
                else if (!DocTools.IsNullOrEmpty(request.WorkType) && !DocTools.IsNullOrEmpty(request.WorkType.Name))
                {
                    entities = entities.Where(en => en.WorkType.Name == request.WorkType.Name);
                }
                if (true == request.WorkTypeNames?.Any())
                {
                    entities = entities.Where(en => en.WorkType.Name.In(request.WorkTypeNames));
                }

                entities = ApplyFilters <DocEntityTimeCard, TimeCardSearch>(request, entities);

                if (request.Skip > 0)
                {
                    entities = entities.Skip(request.Skip.Value);
                }
                if (request.Take > 0)
                {
                    entities = entities.Take(request.Take.Value);
                }
                if (true == request?.OrderBy?.Any())
                {
                    entities = entities.OrderBy(request.OrderBy);
                }
                if (true == request?.OrderByDesc?.Any())
                {
                    entities = entities.OrderByDescending(request.OrderByDesc);
                }
            });
            return(entities);
        }
コード例 #30
0
 public static bool operator ==(DocConstantDatabaseType x, DocConstantDatabaseType y) => DocTools.AreEqual(DocConvert.ToString(x), DocConvert.ToString(y));