public async Task <IActionResult> PostAsync([FromBody] CreateToDoListModel model, CancellationToken cancellationToken = default)
        {
            var id = await this.service.AddAsync <CreateToDoListModel, ToDoList, int>(model, cancellationToken);

            return(this.CreatedAtAction("GetAsync", new IdModel <int> {
                Id = id
            }));
        }
Example #2
0
        public async Task <IActionResult> PostAsync([FromBody] CreateToDoListModel model, CancellationToken cancellationToken = default)
        {
            var request = new CreateEntityFromModelCommand <CreateToDoListModel, 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.CreatedAtAction("GetAsync", new IdModel <int> {
                Id = result.Value
            }));
        }
Example #3
0
        public void CreateToDoList(CreateToDoListModel model)
        {
            Guid creatorId;

            if (!Guid.TryParse(model.UserId, out creatorId))
            {
                throw new ArgumentException("Invalid creator id");
            }

            User currentUser = this.GetCurrentUser();

            if (currentUser.Id != creatorId)
            {
                throw new ArgumentException("Invalid creator id");
            }

            ToDoList toDo = new ToDoList(creatorId, model.Content);

            Task3Repo.AddToDo(toDo);
        }
Example #4
0
        public async Task <IActionResult> CreateToDoList(CreateToDoListModel createToDoList, ApiVersion version)
        {
            long userId = long.Parse(HttpContext.Items["UserId"].ToString());

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

            CreateToDoListDto createToDoListDto = _mapper.Map <CreateToDoListDto>(createToDoList);
            ToDoListDto       createdToDoList   = await _toDoListContract.CreateToDoList(createToDoListDto);

            return(CreatedAtAction(nameof(GetToDoListById), new { createdToDoList.ToDoListId, version = $"{version}" }, createdToDoList));
        }
Example #5
0
        public IActionResult CreateToDoList(CreateToDoListModel inputModel)
        {
            this.task3Service.CreateToDoList(inputModel);

            return(LocalRedirect("/Task3/Login"));
        }