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

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

            LocaleLookup ret = null;

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

            //First, assign all the variables, do database lookups and conversions
            var pData = (DocTools.IsNullOrEmpty(request.Data)) ? null : DocSerialize <IpData> .ToString(request.Data);

            var pIpAddress = request.IpAddress;
            var pLocale    = DocEntityLocale.Get(request.Locale?.Id, true, Execute) ?? DocEntityLocale.Get(request.LocaleId, true, Execute);
            var pArchived  = true == request.Archived;
            var pLocked    = request.Locked;

            var entity = InitEntity <DocEntityLocaleLookup, LocaleLookup>(request, permission, session);

            if (AllowPatchValue <LocaleLookup, bool>(request, DocConstantModelName.LOCALELOOKUP, pArchived, permission, nameof(request.Archived), pArchived != entity.Archived))
            {
                entity.Archived = pArchived;
            }
            if (AllowPatchValue <LocaleLookup, string>(request, DocConstantModelName.LOCALELOOKUP, pData, permission, nameof(request.Data), pData != entity.Data))
            {
                entity.Data = pData;
            }
            if (AllowPatchValue <LocaleLookup, string>(request, DocConstantModelName.LOCALELOOKUP, pIpAddress, permission, nameof(request.IpAddress), pIpAddress != entity.IpAddress))
            {
                entity.IpAddress = pIpAddress;
            }
            if (AllowPatchValue <LocaleLookup, DocEntityLocale>(request, DocConstantModelName.LOCALELOOKUP, pLocale, permission, nameof(request.Locale), pLocale != entity.Locale))
            {
                entity.Locale = pLocale;
            }
            if (request.Locked && AllowPatchValue <LocaleLookup, bool>(request, DocConstantModelName.LOCALELOOKUP, pArchived, permission, nameof(request.Locked), pLocked != entity.Locked))
            {
                entity.Archived = pArchived;
            }
            entity.SaveChanges(permission);

            var idsToInvalidate = new List <int>();

            if (idsToInvalidate.Any())
            {
                idsToInvalidate.Add(entity.Id);
                DocCacheClient.RemoveByEntityIds(idsToInvalidate);
                DocCacheClient.RemoveSearch(DocConstantModelName.LOCALELOOKUP);
            }

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

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

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

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

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

            LookupTableBinding ret = null;

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

            //First, assign all the variables, do database lookups and conversions
            var pBinding = (DocTools.IsNullOrEmpty(request.Binding)) ? null : DocSerialize <Bindings> .ToString(request.Binding);

            var pBoundName = request.BoundName;
            DocEntityLookupTable pLookupTable = GetLookup(DocConstantLookupTable.ATTRIBUTENAME, request.LookupTable?.Name, request.LookupTable?.Id);
            var pScope     = DocEntityScope.Get(request.Scope?.Id, true, Execute) ?? DocEntityScope.Get(request.ScopeId, true, Execute);
            var pSynonyms  = GetVariable <Reference>(request, nameof(request.Synonyms), request.Synonyms?.ToList(), request.SynonymsIds?.ToList());
            var pWorkflows = GetVariable <Reference>(request, nameof(request.Workflows), request.Workflows?.ToList(), request.WorkflowsIds?.ToList());
            var pArchived  = true == request.Archived;
            var pLocked    = request.Locked;

            var entity = InitEntity <DocEntityLookupTableBinding, LookupTableBinding>(request, permission, session);

            if (AllowPatchValue <LookupTableBinding, bool>(request, DocConstantModelName.LOOKUPTABLEBINDING, pArchived, permission, nameof(request.Archived), pArchived != entity.Archived))
            {
                entity.Archived = pArchived;
            }
            if (AllowPatchValue <LookupTableBinding, string>(request, DocConstantModelName.LOOKUPTABLEBINDING, pBinding, permission, nameof(request.Binding), pBinding != entity.Binding))
            {
                entity.Binding = pBinding;
            }
            if (AllowPatchValue <LookupTableBinding, string>(request, DocConstantModelName.LOOKUPTABLEBINDING, pBoundName, permission, nameof(request.BoundName), pBoundName != entity.BoundName))
            {
                entity.BoundName = pBoundName;
            }
            if (AllowPatchValue <LookupTableBinding, DocEntityLookupTable>(request, DocConstantModelName.LOOKUPTABLEBINDING, pLookupTable, permission, nameof(request.LookupTable), pLookupTable != entity.LookupTable))
            {
                entity.LookupTable = pLookupTable;
            }
            if (AllowPatchValue <LookupTableBinding, DocEntityScope>(request, DocConstantModelName.LOOKUPTABLEBINDING, pScope, permission, nameof(request.Scope), pScope != entity.Scope))
            {
                entity.Scope = pScope;
            }
            if (request.Locked && AllowPatchValue <LookupTableBinding, bool>(request, DocConstantModelName.LOOKUPTABLEBINDING, pArchived, permission, nameof(request.Locked), pLocked != entity.Locked))
            {
                entity.Archived = pArchived;
            }
            entity.SaveChanges(permission);

            var idsToInvalidate = new List <int>();

            idsToInvalidate.AddRange(PatchCollection <LookupTableBinding, DocEntityLookupTableBinding, Reference, DocEntityTermSynonym>(request, entity, pSynonyms, permission, nameof(request.Synonyms)));
            idsToInvalidate.AddRange(PatchCollection <LookupTableBinding, DocEntityLookupTableBinding, Reference, DocEntityWorkflow>(request, entity, pWorkflows, permission, nameof(request.Workflows)));
            if (idsToInvalidate.Any())
            {
                idsToInvalidate.Add(entity.Id);
                DocCacheClient.RemoveByEntityIds(idsToInvalidate);
                DocCacheClient.RemoveSearch(DocConstantModelName.LOOKUPTABLEBINDING);
            }

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

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

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

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

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

            Division ret = null;

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

            //First, assign all the variables, do database lookups and conversions
            var pClient        = DocEntityClient.Get(request.Client?.Id, true, Execute) ?? DocEntityClient.Get(request.ClientId, true, Execute);
            var pDefaultLocale = DocEntityLocale.Get(request.DefaultLocale?.Id, true, Execute) ?? DocEntityLocale.Get(request.DefaultLocaleId, true, Execute);
            var pDocumentSets  = GetVariable <Reference>(request, nameof(request.DocumentSets), request.DocumentSets?.ToList(), request.DocumentSetsIds?.ToList());
            var pName          = request.Name;
            var pRole          = DocEntityRole.Get(request.Role?.Id, true, Execute) ?? DocEntityRole.Get(request.RoleId, true, Execute);
            var pSettings      = (DocTools.IsNullOrEmpty(request.Settings)) ? null : DocSerialize <DivisionSettings> .ToString(request.Settings);

            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 <DocEntityDivision, Division>(request, permission, session);

            if (AllowPatchValue <Division, bool>(request, DocConstantModelName.DIVISION, pArchived, permission, nameof(request.Archived), pArchived != entity.Archived))
            {
                entity.Archived = pArchived;
            }
            if (AllowPatchValue <Division, DocEntityClient>(request, DocConstantModelName.DIVISION, pClient, permission, nameof(request.Client), pClient != entity.Client))
            {
                entity.Client = pClient;
            }
            if (AllowPatchValue <Division, DocEntityLocale>(request, DocConstantModelName.DIVISION, pDefaultLocale, permission, nameof(request.DefaultLocale), pDefaultLocale != entity.DefaultLocale))
            {
                entity.DefaultLocale = pDefaultLocale;
            }
            if (AllowPatchValue <Division, string>(request, DocConstantModelName.DIVISION, pName, permission, nameof(request.Name), pName != entity.Name))
            {
                entity.Name = pName;
            }
            if (AllowPatchValue <Division, DocEntityRole>(request, DocConstantModelName.DIVISION, pRole, permission, nameof(request.Role), pRole != entity.Role))
            {
                entity.Role = pRole;
            }
            if (AllowPatchValue <Division, string>(request, DocConstantModelName.DIVISION, pSettings, permission, nameof(request.Settings), pSettings != entity.Settings))
            {
                entity.Settings = pSettings;
            }
            if (request.Locked && AllowPatchValue <Division, bool>(request, DocConstantModelName.DIVISION, pArchived, permission, nameof(request.Locked), pLocked != entity.Locked))
            {
                entity.Archived = pArchived;
            }
            entity.SaveChanges(permission);

            var idsToInvalidate = new List <int>();

            idsToInvalidate.AddRange(PatchCollection <Division, DocEntityDivision, Reference, DocEntityDocumentSet>(request, entity, pDocumentSets, permission, nameof(request.DocumentSets)));
            idsToInvalidate.AddRange(PatchCollection <Division, DocEntityDivision, Reference, DocEntityUser>(request, entity, pUsers, permission, nameof(request.Users)));
            if (idsToInvalidate.Any())
            {
                idsToInvalidate.Add(entity.Id);
                DocCacheClient.RemoveByEntityIds(idsToInvalidate);
                DocCacheClient.RemoveSearch(DocConstantModelName.DIVISION);
            }

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

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

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

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

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

            User ret = null;

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

            //First, assign all the variables, do database lookups and conversions
            var pClientDepartment = request.ClientDepartment;
            var pDivision         = DocEntityDivision.Get(request.Division?.Id, true, Execute) ?? DocEntityDivision.Get(request.DivisionId, true, Execute);
            var pDocumentSets     = GetVariable <Reference>(request, nameof(request.DocumentSets), request.DocumentSets?.ToList(), request.DocumentSetsIds?.ToList());
            var pEmail            = request.Email;
            var pExpireDate       = request.ExpireDate;
            var pFailedLoginCount = request.FailedLoginCount;
            var pFirstName        = request.FirstName;
            var pGravatar         = request.Gravatar;
            var pHistory          = GetVariable <Reference>(request, nameof(request.History), request.History?.ToList(), request.HistoryIds?.ToList());
            var pImpersonated     = GetVariable <Reference>(request, nameof(request.Impersonated), request.Impersonated?.ToList(), request.ImpersonatedIds?.ToList());
            var pImpersonating    = GetVariable <Reference>(request, nameof(request.Impersonating), request.Impersonating?.ToList(), request.ImpersonatingIds?.ToList());
            var pIsSystemUser     = request.IsSystemUser;
            var pJobTitle         = request.JobTitle;
            var pLastLogin        = request.LastLogin;
            var pLastName         = request.LastName;
            var pLegacyUsername   = request.LegacyUsername;
            var pLocale           = DocEntityLocale.Get(request.Locale?.Id, true, Execute) ?? DocEntityLocale.Get(request.LocaleId, true, Execute);
            var pLoginCount       = request.LoginCount;
            var pName             = request.Name;
            var pRoles            = GetVariable <Role>(request, nameof(request.Roles), request.Roles?.ToList(), request.RolesIds?.ToList());
            var pScopes           = GetVariable <Reference>(request, nameof(request.Scopes), request.Scopes?.ToList(), request.ScopesIds?.ToList());
            var pSessions         = GetVariable <Reference>(request, nameof(request.Sessions), request.Sessions?.ToList(), request.SessionsIds?.ToList());
            var pSettings         = (DocTools.IsNullOrEmpty(request.Settings)) ? null : DocSerialize <JsonObject> .ToString(request.Settings);

            var pSlack     = request.Slack;
            var pStartDate = request.StartDate;
            var pStatus    = request.Status;
            var pTeams     = GetVariable <Reference>(request, nameof(request.Teams), request.Teams?.ToList(), request.TeamsIds?.ToList());
            var pTimeCards = GetVariable <Reference>(request, nameof(request.TimeCards), request.TimeCards?.ToList(), request.TimeCardsIds?.ToList());
            var pUpdates   = GetVariable <Reference>(request, nameof(request.Updates), request.Updates?.ToList(), request.UpdatesIds?.ToList());
            var pUserType  = DocEntityUserType.Get(request.UserType?.Id, true, Execute) ?? DocEntityUserType.Get(request.UserTypeId, true, Execute);
            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 <DocEntityUser, User>(request, permission, session);

            if (AllowPatchValue <User, bool>(request, DocConstantModelName.USER, pArchived, permission, nameof(request.Archived), pArchived != entity.Archived))
            {
                entity.Archived = pArchived;
            }
            if (AllowPatchValue <User, string>(request, DocConstantModelName.USER, pClientDepartment, permission, nameof(request.ClientDepartment), pClientDepartment != entity.ClientDepartment))
            {
                entity.ClientDepartment = pClientDepartment;
            }
            if (AllowPatchValue <User, DocEntityDivision>(request, DocConstantModelName.USER, pDivision, permission, nameof(request.Division), pDivision != entity.Division))
            {
                entity.Division = pDivision;
            }
            if (AllowPatchValue <User, string>(request, DocConstantModelName.USER, pEmail, permission, nameof(request.Email), pEmail != entity.Email))
            {
                entity.Email = pEmail;
            }
            if (AllowPatchValue <User, DateTime?>(request, DocConstantModelName.USER, pExpireDate, permission, nameof(request.ExpireDate), pExpireDate != entity.ExpireDate))
            {
                entity.ExpireDate = pExpireDate;
            }
            if (AllowPatchValue <User, int?>(request, DocConstantModelName.USER, pFailedLoginCount, permission, nameof(request.FailedLoginCount), pFailedLoginCount != entity.FailedLoginCount))
            {
                if (null != pFailedLoginCount)
                {
                    entity.FailedLoginCount = (int)pFailedLoginCount;
                }
            }
            if (AllowPatchValue <User, string>(request, DocConstantModelName.USER, pFirstName, permission, nameof(request.FirstName), pFirstName != entity.FirstName))
            {
                entity.FirstName = pFirstName;
            }
            if (AllowPatchValue <User, string>(request, DocConstantModelName.USER, pGravatar, permission, nameof(request.Gravatar), pGravatar != entity.Gravatar))
            {
                entity.Gravatar = pGravatar;
            }
            if (AllowPatchValue <User, string>(request, DocConstantModelName.USER, pJobTitle, permission, nameof(request.JobTitle), pJobTitle != entity.JobTitle))
            {
                entity.JobTitle = pJobTitle;
            }
            if (AllowPatchValue <User, DateTime?>(request, DocConstantModelName.USER, pLastLogin, permission, nameof(request.LastLogin), pLastLogin != entity.LastLogin))
            {
                entity.LastLogin = pLastLogin;
            }
            if (AllowPatchValue <User, string>(request, DocConstantModelName.USER, pLastName, permission, nameof(request.LastName), pLastName != entity.LastName))
            {
                entity.LastName = pLastName;
            }
            if (AllowPatchValue <User, string>(request, DocConstantModelName.USER, pLegacyUsername, permission, nameof(request.LegacyUsername), pLegacyUsername != entity.LegacyUsername))
            {
                entity.LegacyUsername = pLegacyUsername;
            }
            if (AllowPatchValue <User, DocEntityLocale>(request, DocConstantModelName.USER, pLocale, permission, nameof(request.Locale), pLocale != entity.Locale))
            {
                entity.Locale = pLocale;
            }
            if (AllowPatchValue <User, int?>(request, DocConstantModelName.USER, pLoginCount, permission, nameof(request.LoginCount), pLoginCount != entity.LoginCount))
            {
                if (null != pLoginCount)
                {
                    entity.LoginCount = (int)pLoginCount;
                }
            }
            if (AllowPatchValue <User, string>(request, DocConstantModelName.USER, pName, permission, nameof(request.Name), pName != entity.Name))
            {
                entity.Name = pName;
            }
            if (AllowPatchValue <User, string>(request, DocConstantModelName.USER, pSettings, permission, nameof(request.Settings), pSettings != entity.Settings))
            {
                entity.Settings = pSettings;
            }
            if (AllowPatchValue <User, string>(request, DocConstantModelName.USER, pSlack, permission, nameof(request.Slack), pSlack != entity.Slack))
            {
                entity.Slack = pSlack;
            }
            if (AllowPatchValue <User, DateTime?>(request, DocConstantModelName.USER, pStartDate, permission, nameof(request.StartDate), pStartDate != entity.StartDate))
            {
                entity.StartDate = pStartDate;
            }
            if (AllowPatchValue <User, StatusEnm?>(request, DocConstantModelName.USER, pStatus, permission, nameof(request.Status), pStatus != entity.Status))
            {
                if (null != pStatus)
                {
                    entity.Status = pStatus.Value;
                }
            }
            if (AllowPatchValue <User, DocEntityUserType>(request, DocConstantModelName.USER, pUserType, permission, nameof(request.UserType), pUserType != entity.UserType))
            {
                entity.UserType = pUserType;
            }
            if (request.Locked && AllowPatchValue <User, bool>(request, DocConstantModelName.USER, pArchived, permission, nameof(request.Locked), pLocked != entity.Locked))
            {
                entity.Archived = pArchived;
            }
            entity.SaveChanges(permission);

            var idsToInvalidate = new List <int>();

            idsToInvalidate.AddRange(PatchCollection <User, DocEntityUser, Reference, DocEntityDocumentSet>(request, entity, pDocumentSets, permission, nameof(request.DocumentSets)));
            idsToInvalidate.AddRange(PatchCollection <User, DocEntityUser, Reference, DocEntityHistory>(request, entity, pHistory, permission, nameof(request.History)));
            idsToInvalidate.AddRange(PatchCollection <User, DocEntityUser, Reference, DocEntityImpersonation>(request, entity, pImpersonated, permission, nameof(request.Impersonated)));
            idsToInvalidate.AddRange(PatchCollection <User, DocEntityUser, Reference, DocEntityImpersonation>(request, entity, pImpersonating, permission, nameof(request.Impersonating)));
            idsToInvalidate.AddRange(PatchCollection <User, DocEntityUser, Role, DocEntityRole>(request, entity, pRoles, permission, nameof(request.Roles)));
            idsToInvalidate.AddRange(PatchCollection <User, DocEntityUser, Reference, DocEntityScope>(request, entity, pScopes, permission, nameof(request.Scopes)));
            idsToInvalidate.AddRange(PatchCollection <User, DocEntityUser, Reference, DocEntityUserSession>(request, entity, pSessions, permission, nameof(request.Sessions)));
            idsToInvalidate.AddRange(PatchCollection <User, DocEntityUser, Reference, DocEntityTeam>(request, entity, pTeams, permission, nameof(request.Teams)));
            idsToInvalidate.AddRange(PatchCollection <User, DocEntityUser, Reference, DocEntityTimeCard>(request, entity, pTimeCards, permission, nameof(request.TimeCards)));
            idsToInvalidate.AddRange(PatchCollection <User, DocEntityUser, Reference, DocEntityUpdate>(request, entity, pUpdates, permission, nameof(request.Updates)));
            idsToInvalidate.AddRange(PatchCollection <User, DocEntityUser, Reference, DocEntityWorkflow>(request, entity, pWorkflows, permission, nameof(request.Workflows)));
            if (idsToInvalidate.Any())
            {
                idsToInvalidate.Add(entity.Id);
                DocCacheClient.RemoveByEntityIds(idsToInvalidate);
                DocCacheClient.RemoveSearch(DocConstantModelName.USER);
            }

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

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

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

            return(ret);
        }