Exemplo n.º 1
0
        public async Task <IActionResult> Post([FromBody] ClientForCreationDto clientForCreation)
        {
            var client = AutoMapper.Mapper.Map <Client>(clientForCreation);

            var hrResponse = await _hrService.PostClientAsync(clientForCreation);

            if (hrResponse.Token == null)
            {
                return(BadRequest("Could not create account"));
            }

            var clientId = TokenParser.GetClientIdFromToken(hrResponse.Token);

            client.Id = clientId;

            _clientRepository.Add(client);
            if (!_clientRepository.Save())
            {
                return(BadRequest("Could not create client"));
            }

            var result = AutoMapper.Mapper.Map <ClientWithTicketsAndReviewsDto>(client);

            return(CreatedAtRoute("GetClient", new { id = client.Id }, result));
        }
Exemplo n.º 2
0
        public void Add <T>(T item) where T : class, new()
        {
            int curRetry = 0;

            do
            {
                try
                {
                    curRetry++;
                    _repository.Add(item);
                    break;
                }
                catch (Exception ex)
                {
                    Trace.WriteLine(ex.Message);
                    if (curRetry >= retryCount)
                    {
                        throw new Exception(ex.Message);
                    }
                }
            }while (true);
        }
        public IActionResult Post([FromBody] CommentForCreationDto commentForCreation, [FromQuery] int agentId = -1, [FromQuery] int clientId = -1)
        {
            if (clientId == -1 && agentId == -1)
            {
                return(BadRequest("ClientId or AgentId is required"));
            }

            var comment = AutoMapper.Mapper.Map <Comment>(commentForCreation);

            comment.ClientId = clientId;
            comment.AgentId  = agentId;
            //comment.DateCreated = DateTime.Now.ToString();

            _commentRepository.Add(comment);
            if (!_commentRepository.Save())
            {
                return(BadRequest("Could not create comment"));
            }

            var result = AutoMapper.Mapper.Map <CommentWithTicketsDto>(comment);

            return(CreatedAtRoute("GetComment", new { id = comment.Id }, result));
        }