Exemplo n.º 1
0
        public async Task <IActionResult> PutAsync(int id, [FromBody] UpdateToDoListModel model, CancellationToken cancellationToken = default)
        {
            if (id != model.Id)
            {
                return(this.BadRequest("ToDoList ID is different in the route and the model"));
            }

            var updated = await this.service.UpdateAsync <UpdateToDoListModel, ToDoList, int>(model, cancellationToken);

            return(updated.ToActionResult());
        }
Exemplo n.º 2
0
        public async Task <IActionResult> PutAsync(int id, [FromBody] UpdateToDoListModel model, CancellationToken cancellationToken = default)
        {
            if (id != model.Id)
            {
                return(this.BadRequest("ToDoList ID is different in the route and the model"));
            }

            var request = new UpdateEntityFromModelCommand <UpdateToDoListModel, ToDoList, int, EntityDbContext>(model);
            var result  = await mediator.HandleAsync(request, cancellationToken);

            if (!result.IsSuccess)
            {
                var problemDetails = new ProblemDetails();
                problemDetails.Extensions.Add(nameof(Reason), result.Reasons);

                return(new BadRequestObjectResult(problemDetails));
            }

            return(this.Ok(new IdModel <int> {
                Id = result.Value
            }));
        }
Exemplo n.º 3
0
        public async Task <IActionResult> PutToDoList(UpdateToDoListModel listToUpdate)
        {
            long userId = long.Parse(HttpContext.Items["UserId"].ToString());

            if (null == listToUpdate || string.IsNullOrWhiteSpace(listToUpdate.Description))
            {
                return(BadRequest(new ApiResponse <string>
                {
                    IsSuccess = false,
                    Result = "Not Updated.",
                    Message = "Please enter correct values. Description should not be empty."
                }));
            }

            UpdateToDoListDto listToUpdateDto    = _mapper.Map <UpdateToDoListDto>(listToUpdate);
            ToDoListDto       updatedToDoListDto = await _toDoListContract.UpdateToDoList(listToUpdateDto);

            ToDoListModel updatedToDoList = _mapper.Map <ToDoListModel>(updatedToDoListDto);

            if (updatedToDoList != null)
            {
                return(Ok(
                           new ApiResponse <ToDoListModel>
                {
                    IsSuccess = true,
                    Result = updatedToDoList,
                    Message = "ToDoList with Id = " + updatedToDoList.ToDoListId + " is updated on " + updatedToDoList.UpdationDate + " by UserId = " + userId + "."
                }));
            }
            return(NotFound(
                       new ApiResponse <object>
            {
                IsSuccess = false,
                Result = "Item to be updated not found.",
                Message = "No data exist for ToDoListId = " + listToUpdate.ToDoListId
            }));
        }