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); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
private IQueryable <DocEntityDateTime> _ExecSearch(DateTimeSearch request, DocQuery query) { request = InitSearch <DateTimeDto, DateTimeSearch>(request); IQueryable <DocEntityDateTime> entities = null; query.Run(session => { entities = query.SelectAll <DocEntityDateTime>(); if (!DocTools.IsNullOrEmpty(request.FullTextSearch)) { var fts = new DateTimeFullTextSearch(request); entities = GetFullTextSearch <DocEntityDateTime, DateTimeFullTextSearch>(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.DATETIME, 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 (request.DateDay.HasValue) { entities = entities.Where(en => request.DateDay.Value == en.DateDay); } if (request.DateMonth.HasValue) { entities = entities.Where(en => request.DateMonth.Value == en.DateMonth); } if (!DocTools.IsNullOrEmpty(request.DateTime)) { entities = entities.Where(en => null != en.DateTime && request.DateTime.Value.Date == en.DateTime.Value.Date); } if (!DocTools.IsNullOrEmpty(request.DateTimeBefore)) { entities = entities.Where(en => en.DateTime <= request.DateTimeBefore); } if (!DocTools.IsNullOrEmpty(request.DateTimeAfter)) { entities = entities.Where(en => en.DateTime >= request.DateTimeAfter); } if (request.DateYear.HasValue) { entities = entities.Where(en => request.DateYear.Value == en.DateYear); } entities = ApplyFilters <DocEntityDateTime, DateTimeSearch>(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); }
private IQueryable <DocEntityValueType> _ExecSearch(ValueTypeSearch request, DocQuery query) { request = InitSearch <ValueType, ValueTypeSearch>(request); IQueryable <DocEntityValueType> entities = null; query.Run(session => { entities = query.SelectAll <DocEntityValueType>(); if (!DocTools.IsNullOrEmpty(request.FullTextSearch)) { var fts = new ValueTypeFullTextSearch(request); entities = GetFullTextSearch <DocEntityValueType, ValueTypeFullTextSearch>(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.VALUETYPE, 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.FieldType) && !DocTools.IsNullOrEmpty(request.FieldType.Id)) { entities = entities.Where(en => en.FieldType.Id == request.FieldType.Id); } if (true == request.FieldTypeIds?.Any()) { entities = entities.Where(en => en.FieldType.Id.In(request.FieldTypeIds)); } else if (!DocTools.IsNullOrEmpty(request.FieldType) && !DocTools.IsNullOrEmpty(request.FieldType.Name)) { entities = entities.Where(en => en.FieldType.Name == request.FieldType.Name); } if (true == request.FieldTypeNames?.Any()) { entities = entities.Where(en => en.FieldType.Name.In(request.FieldTypeNames)); } if (!DocTools.IsNullOrEmpty(request.Name) && !DocTools.IsNullOrEmpty(request.Name.Id)) { entities = entities.Where(en => en.Name.Id == request.Name.Id); } if (true == request.NameIds?.Any()) { entities = entities.Where(en => en.Name.Id.In(request.NameIds)); } else if (!DocTools.IsNullOrEmpty(request.Name) && !DocTools.IsNullOrEmpty(request.Name.Name)) { entities = entities.Where(en => en.Name.Name == request.Name.Name); } if (true == request.NameNames?.Any()) { entities = entities.Where(en => en.Name.Name.In(request.NameNames)); } entities = ApplyFilters <DocEntityValueType, ValueTypeSearch>(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); }
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); }
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); }
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); }
private Team _AssignValues(Team 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, "Team")) { throw new HttpError(HttpStatusCode.Forbidden, "You do not have ADD permission for this route."); } request.Select = request.Select ?? new List <string>(); Team ret = null; request = _InitAssignValues <Team>(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 <Team>(DocConstantModelName.TEAM, nameof(Team), request); //First, assign all the variables, do database lookups and conversions var pAdminRoles = GetVariable <Reference>(request, nameof(request.AdminRoles), request.AdminRoles?.ToList(), request.AdminRolesIds?.ToList()); var pDescription = request.Description; var pEmail = request.Email; var pIsInternal = request.IsInternal; var pName = request.Name; var pOwner = DocEntityUser.Get(request.Owner?.Id, true, Execute) ?? DocEntityUser.Get(request.OwnerId, true, Execute); var pScopes = GetVariable <Reference>(request, nameof(request.Scopes), request.Scopes?.ToList(), request.ScopesIds?.ToList()); var pSettings = (DocTools.IsNullOrEmpty(request.Settings)) ? null : DocSerialize <TeamSettings> .ToString(request.Settings); var pSlack = request.Slack; var pUpdates = GetVariable <Reference>(request, nameof(request.Updates), request.Updates?.ToList(), request.UpdatesIds?.ToList()); var pUsers = GetVariable <Reference>(request, nameof(request.Users), request.Users?.ToList(), request.UsersIds?.ToList()); var pArchived = true == request.Archived; var pLocked = request.Locked; var entity = InitEntity <DocEntityTeam, Team>(request, permission, session); if (AllowPatchValue <Team, bool>(request, DocConstantModelName.TEAM, pArchived, permission, nameof(request.Archived), pArchived != entity.Archived)) { entity.Archived = pArchived; } if (AllowPatchValue <Team, string>(request, DocConstantModelName.TEAM, pDescription, permission, nameof(request.Description), pDescription != entity.Description)) { entity.Description = pDescription; } if (AllowPatchValue <Team, string>(request, DocConstantModelName.TEAM, pEmail, permission, nameof(request.Email), pEmail != entity.Email)) { entity.Email = pEmail; } if (AllowPatchValue <Team, bool>(request, DocConstantModelName.TEAM, pIsInternal, permission, nameof(request.IsInternal), pIsInternal != entity.IsInternal)) { entity.IsInternal = pIsInternal; } if (AllowPatchValue <Team, string>(request, DocConstantModelName.TEAM, pName, permission, nameof(request.Name), pName != entity.Name)) { entity.Name = pName; } if (AllowPatchValue <Team, DocEntityUser>(request, DocConstantModelName.TEAM, pOwner, permission, nameof(request.Owner), pOwner != entity.Owner)) { entity.Owner = pOwner; } if (AllowPatchValue <Team, string>(request, DocConstantModelName.TEAM, pSettings, permission, nameof(request.Settings), pSettings != entity.Settings)) { entity.Settings = pSettings; } if (AllowPatchValue <Team, string>(request, DocConstantModelName.TEAM, pSlack, permission, nameof(request.Slack), pSlack != entity.Slack)) { entity.Slack = pSlack; } if (request.Locked && AllowPatchValue <Team, bool>(request, DocConstantModelName.TEAM, pArchived, permission, nameof(request.Locked), pLocked != entity.Locked)) { entity.Archived = pArchived; } entity.SaveChanges(permission); var idsToInvalidate = new List <int>(); idsToInvalidate.AddRange(PatchCollection <Team, DocEntityTeam, Reference, DocEntityRole>(request, entity, pAdminRoles, permission, nameof(request.AdminRoles))); idsToInvalidate.AddRange(PatchCollection <Team, DocEntityTeam, Reference, DocEntityScope>(request, entity, pScopes, permission, nameof(request.Scopes))); idsToInvalidate.AddRange(PatchCollection <Team, DocEntityTeam, Reference, DocEntityUpdate>(request, entity, pUpdates, permission, nameof(request.Updates))); idsToInvalidate.AddRange(PatchCollection <Team, DocEntityTeam, Reference, DocEntityUser>(request, entity, pUsers, permission, nameof(request.Users))); if (idsToInvalidate.Any()) { idsToInvalidate.Add(entity.Id); DocCacheClient.RemoveByEntityIds(idsToInvalidate); DocCacheClient.RemoveSearch(DocConstantModelName.TEAM); } entity.SaveChanges(permission); DocPermissionFactory.SetSelect <Team>(currentUser, nameof(Team), request.Select); ret = entity.ToDto(); var cacheExpires = DocResources.Metadata.GetCacheExpiration(DocConstantModelName.TEAM); DocCacheClient.Set(key: cacheKey, value: ret, entityId: request.Id, entityType: DocConstantModelName.TEAM, cacheExpires); return(ret); }