Beispiel #1
0
        public async Task <OperationResult> RegisterAgentAsync(AgentModel agent, CancellationToken token = default)
        {
            ValidateAgent(agent);

            var agentDTO = _mapper.Map <AgentModel, Agent>(agent);

            await _unitOfWork.Agents.SaveAsync(agentDTO, token);

            _unitOfWork.Commit();

            return(OperationResult.Success());
        }
Beispiel #2
0
        private void ValidateAgent(AgentModel agent)
        {
            if (agent == null)
            {
                throw new ArgumentException(nameof(agent));
            }

            if (string.IsNullOrWhiteSpace(agent.FirstName))
            {
                throw new ArgumentNullException(nameof(agent.FirstName));
            }

            if (string.IsNullOrWhiteSpace(agent.LastName))
            {
                throw new ArgumentNullException(nameof(agent.LastName));
            }

            if (string.IsNullOrWhiteSpace(agent.PersonalId) || agent.PersonalId.Length != 11)
            {
                throw new ArgumentException(nameof(agent.PersonalId));
            }
        }