public void Delete(Team request) { using (Execute) { Execute.Run(ssn => { if (!(request?.Id > 0)) { throw new HttpError(HttpStatusCode.NotFound, $"No Id provided for delete."); } var en = DocEntityTeam.Get(request?.Id); if (null == en) { throw new HttpError(HttpStatusCode.NotFound, $"No Team could be found for Id {request?.Id}."); } if (en.IsRemoved) { return; } if (!DocPermissionFactory.HasPermission(en, currentUser, DocConstantPermission.DELETE)) { throw new HttpError(HttpStatusCode.Forbidden, "You do not have DELETE permission for this route."); } en.Remove(); DocCacheClient.RemoveSearch(DocConstantModelName.TEAM); DocCacheClient.RemoveById(request.Id); }); } }
private Team GetTeam(Team request) { var id = request?.Id; Team ret = null; var query = DocQuery.ActiveQuery ?? Execute; DocPermissionFactory.SetSelect <Team>(currentUser, "Team", request.Select); DocEntityTeam entity = null; if (id.HasValue) { entity = DocEntityTeam.Get(id.Value); } if (null == entity) { throw new HttpError(HttpStatusCode.NotFound, $"No Team found for Id {id.Value}"); } if (!DocPermissionFactory.HasPermission(entity, currentUser, DocConstantPermission.VIEW)) { throw new HttpError(HttpStatusCode.Forbidden, "You do not have VIEW permission for this route."); } ret = entity?.ToDto(); return(ret); }
public 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 DiseaseStateSet _AssignValues(DiseaseStateSet request, DocConstantPermission permission, Session session) { if (permission != DocConstantPermission.ADD && (request == null || request.Id <= 0)) { throw new HttpError(HttpStatusCode.NotFound, $"No record"); } if (permission == DocConstantPermission.ADD && !DocPermissionFactory.HasPermissionTryAdd(currentUser, "DiseaseStateSet")) { throw new HttpError(HttpStatusCode.Forbidden, "You do not have ADD permission for this route."); } request.Select = request.Select ?? new List <string>(); DiseaseStateSet ret = null; request = _InitAssignValues <DiseaseStateSet>(request, permission, session); //In case init assign handles create for us, return it if (permission == DocConstantPermission.ADD && request.Id > 0) { return(request); } var cacheKey = GetApiCacheKey <DiseaseStateSet>(DocConstantModelName.DISEASESTATESET, nameof(DiseaseStateSet), request); //First, assign all the variables, do database lookups and conversions var pClients = GetVariable <Reference>(request, nameof(request.Clients), request.Clients?.ToList(), request.ClientsIds?.ToList()); var pConfidential = request.Confidential; var pDivisions = GetVariable <Reference>(request, nameof(request.Divisions), request.Divisions?.ToList(), request.DivisionsIds?.ToList()); var pDocuments = GetVariable <Reference>(request, nameof(request.Documents), request.Documents?.ToList(), request.DocumentsIds?.ToList()); var pDocumentSets = GetVariable <Reference>(request, nameof(request.DocumentSets), request.DocumentSets?.ToList(), request.DocumentSetsIds?.ToList()); var pHistories = GetVariable <Reference>(request, nameof(request.Histories), request.Histories?.ToList(), request.HistoriesIds?.ToList()); var pLegacyDocumentSetId = request.LegacyDocumentSetId; var pName = request.Name; var pOwner = DocEntityDocumentSet.Get(request.Owner?.Id, true, Execute) ?? DocEntityDocumentSet.Get(request.OwnerId, true, Execute); var pProjectTeam = DocEntityTeam.Get(request.ProjectTeam?.Id, true, Execute) ?? DocEntityTeam.Get(request.ProjectTeamId, true, Execute); var pScopes = GetVariable <Reference>(request, nameof(request.Scopes), request.Scopes?.ToList(), request.ScopesIds?.ToList()); var pSettings = request.Settings; var pStats = GetVariable <Reference>(request, nameof(request.Stats), request.Stats?.ToList(), request.StatsIds?.ToList()); var pType = request.Type; var pUsers = GetVariable <Reference>(request, nameof(request.Users), request.Users?.ToList(), request.UsersIds?.ToList()); var pArchived = true == request.Archived; var pLocked = request.Locked; var entity = InitEntity <DocEntityDiseaseStateSet, DiseaseStateSet>(request, permission, session); if (AllowPatchValue <DiseaseStateSet, bool>(request, DocConstantModelName.DISEASESTATESET, pArchived, permission, nameof(request.Archived), pArchived != entity.Archived)) { entity.Archived = pArchived; } if (AllowPatchValue <DiseaseStateSet, bool>(request, DocConstantModelName.DISEASESTATESET, pConfidential, permission, nameof(request.Confidential), pConfidential != entity.Confidential)) { entity.Confidential = pConfidential; } if (AllowPatchValue <DiseaseStateSet, int?>(request, DocConstantModelName.DISEASESTATESET, pLegacyDocumentSetId, permission, nameof(request.LegacyDocumentSetId), pLegacyDocumentSetId != entity.LegacyDocumentSetId)) { entity.LegacyDocumentSetId = pLegacyDocumentSetId; } if (AllowPatchValue <DiseaseStateSet, string>(request, DocConstantModelName.DISEASESTATESET, pName, permission, nameof(request.Name), pName != entity.Name)) { entity.Name = pName; } if (AllowPatchValue <DiseaseStateSet, DocEntityDocumentSet>(request, DocConstantModelName.DISEASESTATESET, pOwner, permission, nameof(request.Owner), pOwner != entity.Owner)) { entity.Owner = pOwner; } if (AllowPatchValue <DiseaseStateSet, DocEntityTeam>(request, DocConstantModelName.DISEASESTATESET, pProjectTeam, permission, nameof(request.ProjectTeam), pProjectTeam != entity.ProjectTeam)) { entity.ProjectTeam = pProjectTeam; } if (AllowPatchValue <DiseaseStateSet, string>(request, DocConstantModelName.DISEASESTATESET, pSettings, permission, nameof(request.Settings), pSettings != entity.Settings)) { entity.Settings = pSettings; } if (AllowPatchValue <DiseaseStateSet, DocumentSetTypeEnm?>(request, DocConstantModelName.DISEASESTATESET, pType, permission, nameof(request.Type), pType != entity.Type)) { if (null != pType) { entity.Type = pType.Value; } } if (request.Locked && AllowPatchValue <DiseaseStateSet, bool>(request, DocConstantModelName.DISEASESTATESET, pArchived, permission, nameof(request.Locked), pLocked != entity.Locked)) { entity.Archived = pArchived; } entity.SaveChanges(permission); var idsToInvalidate = new List <int>(); idsToInvalidate.AddRange(PatchCollection <DiseaseStateSet, DocEntityDiseaseStateSet, Reference, DocEntityClient>(request, entity, pClients, permission, nameof(request.Clients))); idsToInvalidate.AddRange(PatchCollection <DiseaseStateSet, DocEntityDiseaseStateSet, Reference, DocEntityDivision>(request, entity, pDivisions, permission, nameof(request.Divisions))); idsToInvalidate.AddRange(PatchCollection <DiseaseStateSet, DocEntityDiseaseStateSet, Reference, DocEntityDocument>(request, entity, pDocuments, permission, nameof(request.Documents))); idsToInvalidate.AddRange(PatchCollection <DiseaseStateSet, DocEntityDiseaseStateSet, Reference, DocEntityDocumentSet>(request, entity, pDocumentSets, permission, nameof(request.DocumentSets))); idsToInvalidate.AddRange(PatchCollection <DiseaseStateSet, DocEntityDiseaseStateSet, Reference, DocEntityDocumentSetHistory>(request, entity, pHistories, permission, nameof(request.Histories))); idsToInvalidate.AddRange(PatchCollection <DiseaseStateSet, DocEntityDiseaseStateSet, Reference, DocEntityScope>(request, entity, pScopes, permission, nameof(request.Scopes))); idsToInvalidate.AddRange(PatchCollection <DiseaseStateSet, DocEntityDiseaseStateSet, Reference, DocEntityStatsStudySet>(request, entity, pStats, permission, nameof(request.Stats))); idsToInvalidate.AddRange(PatchCollection <DiseaseStateSet, DocEntityDiseaseStateSet, Reference, DocEntityUser>(request, entity, pUsers, permission, nameof(request.Users))); if (idsToInvalidate.Any()) { idsToInvalidate.Add(entity.Id); DocCacheClient.RemoveByEntityIds(idsToInvalidate); DocCacheClient.RemoveSearch(DocConstantModelName.DISEASESTATESET); } entity.SaveChanges(permission); DocPermissionFactory.SetSelect <DiseaseStateSet>(currentUser, nameof(DiseaseStateSet), request.Select); ret = entity.ToDto(); var cacheExpires = DocResources.Metadata.GetCacheExpiration(DocConstantModelName.DISEASESTATESET); DocCacheClient.Set(key: cacheKey, value: ret, entityId: request.Id, entityType: DocConstantModelName.DISEASESTATESET, cacheExpires); return(ret); }
private Role _AssignValues(Role 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, "Role")) { throw new HttpError(HttpStatusCode.Forbidden, "You do not have ADD permission for this route."); } request.Select = request.Select ?? new List <string>(); Role ret = null; request = _InitAssignValues <Role>(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 <Role>(DocConstantModelName.ROLE, nameof(Role), request); //First, assign all the variables, do database lookups and conversions var pAdminTeam = DocEntityTeam.Get(request.AdminTeam?.Id, true, Execute) ?? DocEntityTeam.Get(request.AdminTeamId, true, Execute); var pApps = GetVariable <Reference>(request, nameof(request.Apps), request.Apps?.ToList(), request.AppsIds?.ToList()); var pDescription = request.Description; var pFeatures = request.Features; var pFeatureSets = GetVariable <Reference>(request, nameof(request.FeatureSets), request.FeatureSets?.ToList(), request.FeatureSetsIds?.ToList()); var pIsInternal = request.IsInternal; var pIsSuperAdmin = request.IsSuperAdmin; var pName = request.Name; var pPages = GetVariable <Reference>(request, nameof(request.Pages), request.Pages?.ToList(), request.PagesIds?.ToList()); var pPermissions = request.Permissions; 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 <DocEntityRole, Role>(request, permission, session); if (AllowPatchValue <Role, bool>(request, DocConstantModelName.ROLE, pArchived, permission, nameof(request.Archived), pArchived != entity.Archived)) { entity.Archived = pArchived; } if (AllowPatchValue <Role, DocEntityTeam>(request, DocConstantModelName.ROLE, pAdminTeam, permission, nameof(request.AdminTeam), pAdminTeam != entity.AdminTeam)) { entity.AdminTeam = pAdminTeam; } if (AllowPatchValue <Role, string>(request, DocConstantModelName.ROLE, pDescription, permission, nameof(request.Description), pDescription != entity.Description)) { entity.Description = pDescription; } if (AllowPatchValue <Role, string>(request, DocConstantModelName.ROLE, pFeatures, permission, nameof(request.Features), pFeatures != entity.Features)) { entity.Features = pFeatures; } if (AllowPatchValue <Role, bool>(request, DocConstantModelName.ROLE, pIsInternal, permission, nameof(request.IsInternal), pIsInternal != entity.IsInternal)) { entity.IsInternal = pIsInternal; } if (AllowPatchValue <Role, string>(request, DocConstantModelName.ROLE, pName, permission, nameof(request.Name), pName != entity.Name)) { entity.Name = pName; } if (AllowPatchValue <Role, string>(request, DocConstantModelName.ROLE, pPermissions, permission, nameof(request.Permissions), pPermissions != entity.Permissions)) { entity.Permissions = pPermissions; } if (request.Locked && AllowPatchValue <Role, bool>(request, DocConstantModelName.ROLE, pArchived, permission, nameof(request.Locked), pLocked != entity.Locked)) { entity.Archived = pArchived; } entity.SaveChanges(permission); var idsToInvalidate = new List <int>(); idsToInvalidate.AddRange(PatchCollection <Role, DocEntityRole, Reference, DocEntityApp>(request, entity, pApps, permission, nameof(request.Apps))); idsToInvalidate.AddRange(PatchCollection <Role, DocEntityRole, Reference, DocEntityFeatureSet>(request, entity, pFeatureSets, permission, nameof(request.FeatureSets))); idsToInvalidate.AddRange(PatchCollection <Role, DocEntityRole, Reference, DocEntityPage>(request, entity, pPages, permission, nameof(request.Pages))); idsToInvalidate.AddRange(PatchCollection <Role, DocEntityRole, Reference, DocEntityUser>(request, entity, pUsers, permission, nameof(request.Users))); if (idsToInvalidate.Any()) { idsToInvalidate.Add(entity.Id); DocCacheClient.RemoveByEntityIds(idsToInvalidate); DocCacheClient.RemoveSearch(DocConstantModelName.ROLE); } entity.SaveChanges(permission); DocPermissionFactory.SetSelect <Role>(currentUser, nameof(Role), request.Select); ret = entity.ToDto(); var cacheExpires = DocResources.Metadata.GetCacheExpiration(DocConstantModelName.ROLE); DocCacheClient.Set(key: cacheKey, value: ret, entityId: request.Id, entityType: DocConstantModelName.ROLE, cacheExpires); return(ret); }
private Scope _AssignValues(Scope request, DocConstantPermission permission, Session session) { if (permission != DocConstantPermission.ADD && (request == null || request.Id <= 0)) { throw new HttpError(HttpStatusCode.NotFound, $"No record"); } if (permission == DocConstantPermission.ADD && !DocPermissionFactory.HasPermissionTryAdd(currentUser, "Scope")) { throw new HttpError(HttpStatusCode.Forbidden, "You do not have ADD permission for this route."); } request.Select = request.Select ?? new List <string>(); Scope ret = null; request = _InitAssignValues <Scope>(request, permission, session); //In case init assign handles create for us, return it if (permission == DocConstantPermission.ADD && request.Id > 0) { return(request); } var cacheKey = GetApiCacheKey <Scope>(DocConstantModelName.SCOPE, nameof(Scope), request); //First, assign all the variables, do database lookups and conversions var pApp = DocEntityApp.Get(request.App?.Id, true, Execute) ?? DocEntityApp.Get(request.AppId, true, Execute); var pBindings = GetVariable <Reference>(request, nameof(request.Bindings), request.Bindings?.ToList(), request.BindingsIds?.ToList()); var pBroadcasts = GetVariable <Reference>(request, nameof(request.Broadcasts), request.Broadcasts?.ToList(), request.BroadcastsIds?.ToList()); var pClient = DocEntityClient.Get(request.Client?.Id, true, Execute) ?? DocEntityClient.Get(request.ClientId, true, Execute); var pDelete = request.Delete; var pDocumentSet = DocEntityDocumentSet.Get(request.DocumentSet?.Id, true, Execute) ?? DocEntityDocumentSet.Get(request.DocumentSetId, true, Execute); var pEdit = request.Edit; var pHelp = GetVariable <Reference>(request, nameof(request.Help), request.Help?.ToList(), request.HelpIds?.ToList()); var pIsGlobal = request.IsGlobal; var pScopedComments = GetVariable <Reference>(request, nameof(request.ScopedComments), request.ScopedComments?.ToList(), request.ScopedCommentsIds?.ToList()); var pScopedFiles = GetVariable <Reference>(request, nameof(request.ScopedFiles), request.ScopedFiles?.ToList(), request.ScopedFilesIds?.ToList()); var pScopedTags = GetVariable <Reference>(request, nameof(request.ScopedTags), request.ScopedTags?.ToList(), request.ScopedTagsIds?.ToList()); var pSynonyms = GetVariable <Reference>(request, nameof(request.Synonyms), request.Synonyms?.ToList(), request.SynonymsIds?.ToList()); var pTeam = DocEntityTeam.Get(request.Team?.Id, true, Execute) ?? DocEntityTeam.Get(request.TeamId, true, Execute); var pType = request.Type; var pUser = DocEntityUser.Get(request.User?.Id, true, Execute) ?? DocEntityUser.Get(request.UserId, true, Execute); var pVariableRules = GetVariable <Reference>(request, nameof(request.VariableRules), request.VariableRules?.ToList(), request.VariableRulesIds?.ToList()); var pView = request.View; var pWorkflows = GetVariable <Reference>(request, nameof(request.Workflows), request.Workflows?.ToList(), request.WorkflowsIds?.ToList()); var pArchived = true == request.Archived; var pLocked = request.Locked; var entity = InitEntity <DocEntityScope, Scope>(request, permission, session); if (AllowPatchValue <Scope, bool>(request, DocConstantModelName.SCOPE, pArchived, permission, nameof(request.Archived), pArchived != entity.Archived)) { entity.Archived = pArchived; } if (AllowPatchValue <Scope, DocEntityApp>(request, DocConstantModelName.SCOPE, pApp, permission, nameof(request.App), pApp != entity.App)) { entity.App = pApp; } if (AllowPatchValue <Scope, DocEntityClient>(request, DocConstantModelName.SCOPE, pClient, permission, nameof(request.Client), pClient != entity.Client)) { entity.Client = pClient; } if (AllowPatchValue <Scope, bool>(request, DocConstantModelName.SCOPE, pDelete, permission, nameof(request.Delete), pDelete != entity.Delete)) { entity.Delete = pDelete; } if (AllowPatchValue <Scope, DocEntityDocumentSet>(request, DocConstantModelName.SCOPE, pDocumentSet, permission, nameof(request.DocumentSet), pDocumentSet != entity.DocumentSet)) { entity.DocumentSet = pDocumentSet; } if (AllowPatchValue <Scope, bool>(request, DocConstantModelName.SCOPE, pEdit, permission, nameof(request.Edit), pEdit != entity.Edit)) { entity.Edit = pEdit; } if (AllowPatchValue <Scope, bool>(request, DocConstantModelName.SCOPE, pIsGlobal, permission, nameof(request.IsGlobal), pIsGlobal != entity.IsGlobal)) { entity.IsGlobal = pIsGlobal; } if (AllowPatchValue <Scope, DocEntityTeam>(request, DocConstantModelName.SCOPE, pTeam, permission, nameof(request.Team), pTeam != entity.Team)) { entity.Team = pTeam; } if (AllowPatchValue <Scope, ScopeEnm?>(request, DocConstantModelName.SCOPE, pType, permission, nameof(request.Type), pType != entity.Type)) { if (null != pType) { entity.Type = pType.Value; } } if (AllowPatchValue <Scope, DocEntityUser>(request, DocConstantModelName.SCOPE, pUser, permission, nameof(request.User), pUser != entity.User)) { entity.User = pUser; } if (AllowPatchValue <Scope, bool>(request, DocConstantModelName.SCOPE, pView, permission, nameof(request.View), pView != entity.View)) { entity.View = pView; } if (request.Locked && AllowPatchValue <Scope, bool>(request, DocConstantModelName.SCOPE, pArchived, permission, nameof(request.Locked), pLocked != entity.Locked)) { entity.Archived = pArchived; } entity.SaveChanges(permission); var idsToInvalidate = new List <int>(); idsToInvalidate.AddRange(PatchCollection <Scope, DocEntityScope, Reference, DocEntityLookupTableBinding>(request, entity, pBindings, permission, nameof(request.Bindings))); idsToInvalidate.AddRange(PatchCollection <Scope, DocEntityScope, Reference, DocEntityBroadcast>(request, entity, pBroadcasts, permission, nameof(request.Broadcasts))); idsToInvalidate.AddRange(PatchCollection <Scope, DocEntityScope, Reference, DocEntityHelp>(request, entity, pHelp, permission, nameof(request.Help))); idsToInvalidate.AddRange(PatchCollection <Scope, DocEntityScope, Reference, DocEntityComment>(request, entity, pScopedComments, permission, nameof(request.ScopedComments))); idsToInvalidate.AddRange(PatchCollection <Scope, DocEntityScope, Reference, DocEntityFile>(request, entity, pScopedFiles, permission, nameof(request.ScopedFiles))); idsToInvalidate.AddRange(PatchCollection <Scope, DocEntityScope, Reference, DocEntityTag>(request, entity, pScopedTags, permission, nameof(request.ScopedTags))); idsToInvalidate.AddRange(PatchCollection <Scope, DocEntityScope, Reference, DocEntityTermSynonym>(request, entity, pSynonyms, permission, nameof(request.Synonyms))); idsToInvalidate.AddRange(PatchCollection <Scope, DocEntityScope, Reference, DocEntityVariableRule>(request, entity, pVariableRules, permission, nameof(request.VariableRules))); idsToInvalidate.AddRange(PatchCollection <Scope, DocEntityScope, Reference, DocEntityWorkflow>(request, entity, pWorkflows, permission, nameof(request.Workflows))); if (idsToInvalidate.Any()) { idsToInvalidate.Add(entity.Id); DocCacheClient.RemoveByEntityIds(idsToInvalidate); DocCacheClient.RemoveSearch(DocConstantModelName.SCOPE); } entity.SaveChanges(permission); DocPermissionFactory.SetSelect <Scope>(currentUser, nameof(Scope), request.Select); ret = entity.ToDto(); var cacheExpires = DocResources.Metadata.GetCacheExpiration(DocConstantModelName.SCOPE); DocCacheClient.Set(key: cacheKey, value: ret, entityId: request.Id, entityType: DocConstantModelName.SCOPE, cacheExpires); return(ret); }
private Update _AssignValues(Update 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, "Update")) { throw new HttpError(HttpStatusCode.Forbidden, "You do not have ADD permission for this route."); } request.Select = request.Select ?? new List <string>(); Update ret = null; request = _InitAssignValues <Update>(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 <Update>(DocConstantModelName.UPDATE, nameof(Update), request); //First, assign all the variables, do database lookups and conversions var pBody = request.Body; var pDeliveryStatus = request.DeliveryStatus; var pEmailAttempts = request.EmailAttempts; var pEmailSent = request.EmailSent; var pEvents = GetVariable <Reference>(request, nameof(request.Events), request.Events?.ToList(), request.EventsIds?.ToList()); var pLink = request.Link; var pPriority = request.Priority; var pRead = request.Read; var pSlackSent = request.SlackSent; var pSubject = request.Subject; var pTeam = DocEntityTeam.Get(request.Team?.Id, true, Execute) ?? DocEntityTeam.Get(request.TeamId, true, Execute); var pUser = DocEntityUser.Get(request.User?.Id, true, Execute) ?? DocEntityUser.Get(request.UserId, true, Execute); var pArchived = true == request.Archived; var pLocked = request.Locked; var entity = InitEntity <DocEntityUpdate, Update>(request, permission, session); if (AllowPatchValue <Update, bool>(request, DocConstantModelName.UPDATE, pArchived, permission, nameof(request.Archived), pArchived != entity.Archived)) { entity.Archived = pArchived; } if (AllowPatchValue <Update, string>(request, DocConstantModelName.UPDATE, pBody, permission, nameof(request.Body), pBody != entity.Body)) { entity.Body = pBody; } if (AllowPatchValue <Update, string>(request, DocConstantModelName.UPDATE, pDeliveryStatus, permission, nameof(request.DeliveryStatus), pDeliveryStatus != entity.DeliveryStatus)) { entity.DeliveryStatus = pDeliveryStatus; } if (AllowPatchValue <Update, int?>(request, DocConstantModelName.UPDATE, pEmailAttempts, permission, nameof(request.EmailAttempts), pEmailAttempts != entity.EmailAttempts)) { if (null != pEmailAttempts) { entity.EmailAttempts = (int)pEmailAttempts; } } if (AllowPatchValue <Update, DateTime?>(request, DocConstantModelName.UPDATE, pEmailSent, permission, nameof(request.EmailSent), pEmailSent != entity.EmailSent)) { entity.EmailSent = pEmailSent; } if (AllowPatchValue <Update, string>(request, DocConstantModelName.UPDATE, pLink, permission, nameof(request.Link), pLink != entity.Link)) { entity.Link = pLink; } if (AllowPatchValue <Update, int?>(request, DocConstantModelName.UPDATE, pPriority, permission, nameof(request.Priority), pPriority != entity.Priority)) { if (null != pPriority) { entity.Priority = (int)pPriority; } } if (AllowPatchValue <Update, DateTime?>(request, DocConstantModelName.UPDATE, pRead, permission, nameof(request.Read), pRead != entity.Read)) { entity.Read = pRead; } if (AllowPatchValue <Update, DateTime?>(request, DocConstantModelName.UPDATE, pSlackSent, permission, nameof(request.SlackSent), pSlackSent != entity.SlackSent)) { entity.SlackSent = pSlackSent; } if (AllowPatchValue <Update, string>(request, DocConstantModelName.UPDATE, pSubject, permission, nameof(request.Subject), pSubject != entity.Subject)) { entity.Subject = pSubject; } if (AllowPatchValue <Update, DocEntityTeam>(request, DocConstantModelName.UPDATE, pTeam, permission, nameof(request.Team), pTeam != entity.Team)) { entity.Team = pTeam; } if (AllowPatchValue <Update, DocEntityUser>(request, DocConstantModelName.UPDATE, pUser, permission, nameof(request.User), pUser != entity.User)) { entity.User = pUser; } if (request.Locked && AllowPatchValue <Update, bool>(request, DocConstantModelName.UPDATE, pArchived, permission, nameof(request.Locked), pLocked != entity.Locked)) { entity.Archived = pArchived; } entity.SaveChanges(permission); var idsToInvalidate = new List <int>(); idsToInvalidate.AddRange(PatchCollection <Update, DocEntityUpdate, Reference, DocEntityEvent>(request, entity, pEvents, permission, nameof(request.Events))); if (idsToInvalidate.Any()) { idsToInvalidate.Add(entity.Id); DocCacheClient.RemoveByEntityIds(idsToInvalidate); DocCacheClient.RemoveSearch(DocConstantModelName.UPDATE); } entity.SaveChanges(permission); DocPermissionFactory.SetSelect <Update>(currentUser, nameof(Update), request.Select); ret = entity.ToDto(); var cacheExpires = DocResources.Metadata.GetCacheExpiration(DocConstantModelName.UPDATE); DocCacheClient.Set(key: cacheKey, value: ret, entityId: request.Id, entityType: DocConstantModelName.UPDATE, cacheExpires); return(ret); }