Пример #1
0
        private bool IsDifferentRolesOrStatusOrLocked(dto.Agent self, dto.Agent requestAgent)
        {
            if (self.Status != requestAgent.Status || requestAgent.Locked != self.Locked)
            {
                return(true);
            }
            if ((self.AgentRoles == null || self.AgentRoles.Length == 0) && (requestAgent.AgentRoles == null || requestAgent.AgentRoles.Length == 0))
            {
                return(false);
            }
            var sorted1 = self.AgentRoles.OrderBy(o => o.RoleCode).Select(s => s.RoleCode);
            var sorted2 = requestAgent.AgentRoles.OrderBy(o => o.RoleCode).Select(s => s.RoleCode);

            return(!sorted1.SequenceEqual(sorted2));
        }
Пример #2
0
        public async Task <dto.Agent> UpdateAgent(dto.Agent agent)
        {
            // Disallow self to update status/role/lock
            if (agent.AgentID == await _sessionBag.AgentId())
            {
                var self = await GetAgent(agent.AgentID);

                if (IsDifferentRolesOrStatusOrLocked(agent, self.Agent))
                {
                    throw new dto.ResponseErrorException(dto.Enumerations.ResponseErrorCode.AgentUpdateNotAllowed, "Agent update operation not allowed. ");
                }
            }

            var signature = await _sessionBag.Signature();

            var mappedAgent = Mapper.Map <Agent>(agent);

            mappedAgent.AgentIdentifier = new AgentIdentifier
            {
                AgentName        = agent.LoginName,
                OrganizationCode = await _sessionBag.OrganizationCode(),
                State            = nskCommonEnum.MessageState.Clean
            };
            var request = new CommitAgentRequestData {
                Agent = mappedAgent
            };

            SetAgentProperties(request);
            request.Agent.State      = nskCommonEnum.MessageState.Modified;
            request.Agent.AgentRoles = await SetAgentRoleCode(agent.AgentID, request.Agent.AgentRoles);
            await CommitAgent(request, signature);

            var getAgent = await GetAgent(agent.AgentID);

            return(getAgent.Agent);
        }