Exemplo n.º 1
0
        public async Task <ToDoRestModel> CreateAsync(ToDoRestModel toDo)
        {
            var response = await _httpService.PostAsync <ToDoRestModel, ToDoRestModel>(URL, toDo);

            if (!response.IsSuccess)
            {
                throw new ApplicationException(await response.GetBodyAsync());
            }

            return(response.Response);
        }
Exemplo n.º 2
0
        public async Task <ToDoRestModel> UpdateAsync(ToDoRestModel toDo)
        {
            var uri      = $"{URL}/{toDo.Id}";
            var response = await _httpService.UpdateAsync(uri, toDo);


            if (!response.IsSuccess)
            {
                throw new ApplicationException(await response.GetBodyAsync());
            }

            return(response.Response);
        }
Exemplo n.º 3
0
        public async Task <IActionResult> Put(string id, ToDoRestModel toDoViewModel)
        {
            if (id != toDoViewModel.Id)
            {
                return(BadRequest());
            }

            string userId = User.FindFirst(ClaimTypes.NameIdentifier).Value;
            var    todo   = await _toDoService.UpdateAsync(_mapper.Map <ToDo>(toDoViewModel), userId);

            if (todo == null)
            {
                return(NotFound());
            }

            return(Ok(_mapper.Map <ToDoRestModel>(todo)));
        }
Exemplo n.º 4
0
        public async Task <IActionResult> Post(ToDoRestModel toDoViewModel)
        {
            var todo = await _toDoService.CreateAsync(_mapper.Map <ToDo>(toDoViewModel), User.FindFirst(ClaimTypes.NameIdentifier).Value);

            return(CreatedAtAction("GET", todo.Id.ToString(), _mapper.Map <ToDoRestModel>(todo)));
        }