Exemple #1
0
        public async Task <IActionResult> Create([FromBody] TodoItemCreateRequest request)
        {
            if (request == null || string.IsNullOrWhiteSpace(request.Description))
            {
                return(BadRequest(new ErrorDetailsResponse
                {
                    Error = "Invalid request with the given parameters"
                }));
            }

            try
            {
                _logger.LogDebug("Creating a todo item '{description}'", request.Description);
                bool result = await _todoService.CreateAsync(request);

                if (result)
                {
                    _logger.LogDebug("Todo item '{description}' created successfully", request.Description);
                    return(StatusCode(StatusCodes.Status201Created));
                }
                _logger.LogWarning("Didn't get an expected response from service.");
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, "An unexpected error has occurred");
            }
            return(StatusCode(StatusCodes.Status500InternalServerError, new ErrorDetailsResponse
            {
                Error = "An unexpected error has occurred"
            }));
        }
Exemple #2
0
        public async Task <IActionResult> Create(TodoItem item)
        {
            if (item is null)
            {
                throw new ArgumentNullException(nameof(item));
            }

            item = await _todoService.CreateAsync(item);

            return(CreatedAtRoute(nameof(GetTodo), new { id = item.Id }, item));
        }
 public async Task AddTodo(TodoViewModel todoViewModel)
 {
     await todoService.CreateAsync(mapper.Map <Todo>(todoViewModel));
 }
Exemple #4
0
        public async Task <IActionResult> Create(TodoItemDto itemdto)
        {
            Todoitem item = _mapper.Map <Todoitem>(itemdto);

            return(Ok(await _service.CreateAsync(item)));
        }