コード例 #1
0
        public async Task <IActionResult> Post([FromBody] IssueCreateDto item, CancellationToken ct)
        {
            try
            {
                // map dto to model
                var toAdd = Mapper.Map <Issue>(item);

                // create self link and open timestamp
                toAdd.SelfLink       = $"{Request.Path}";
                toAdd.DateTimeOpened = DateTime.UtcNow;

                // add new issue to the repository
                var data = await _issueRepository.AddBug(toAdd, ct);

                // map model to response dto
                var result = Mapper.Map <IssueDto>(toAdd);

                // return created response
                return(Created($"/api/bugs/{data}", new SuccessResult {
                    Results = new[] { result }, Status = "Successful"
                }));
            }
            catch (ArgumentException ex)
            {
                return(BadRequest(ex.Message));
            }
        }