コード例 #1
0
        public override async Task <Empty> AddToDo(AddToDoRequest request, ServerCallContext context)
        {
            var command = new CreateToDoCommand(request.Id, request.Description, request.Username);
            await _mediator.Send(command);

            return(new Empty());
        }
コード例 #2
0
 public void Handle(CreateToDoCommand message)
 {
     ExecuteDomainCreate(message.AggregateId, aggregate =>
     {
         aggregate.Create(message.Title, message.Description, message.UserId);
     });
 }
コード例 #3
0
        public async Task <IActionResult> CreateToDo(CreateToDoCommand command)
        {
            command.Username = User.Identity.Name;
            await _mediator.Send(command);

            return(Ok());
        }
コード例 #4
0
        public async Task <ActionResult> CreateToDo(CreateToDoCommand command)
        {
            command.UserId         = User.GetUserId();
            command.OrganizationId = User.GetOrganizationId();

            return(await this.SendCreateCommand(command, nameof(GetToDo)));
        }
コード例 #5
0
        public async Task <ActionResult <int> > CreateToDo([FromBody] CreateToDoCommand command)
        {
            var result = await _mediator.Send(command);

            if (result.IsBadRequest)
            {
                return(BadRequest(result.ValidationFailures));
            }

            return(StatusCode(201, result.Content));
        }
コード例 #6
0
        public async Task <IActionResult> ToDoList()
        {
            ViewBag.UserInformation = $"Hello {ViewBag.UserName}, here is your todo list:";

            var model = new UserViewModel();

            var command = new CreateToDoCommand();

            await _endpointInstance.Send(command).ConfigureAwait(false);

            return(View(model));
        }
コード例 #7
0
        public async Task <ActionResult> PostTodo(
            [FromBody] CreateToDoCommand command,
            [FromServices] HandlerCreateToDoItem handler
            )
        {
            command.User = "******";
            var result = (CommandResult)handler.Handle(command);

            if (!result.Success)
            {
                return(BadRequest(result));
            }

            return(Ok(result));
        }
コード例 #8
0
        public async Task <IActionResult> PostAsync(CreateToDoCommand command)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            await _itemToDoRepository.AddAsync(new ItemTodo
            {
                Id   = Guid.NewGuid(),
                Name = command.Name
            });

            return(Ok(command));
        }
コード例 #9
0
        public async Task <IActionResult> Add(ToDoViewModel model)
        {
            //TODO: AutoMapper
            var command = new CreateToDoCommand
            {
                Id          = Guid.NewGuid(),
                Title       = model.Title,
                UserId      = model.UserId,
                Description = model.Description
            };

            await _endpointInstance.Send(command).ConfigureAwait(false);

            return(RedirectToAction("ToDoList", "Home", new { userId = model.UserId }));
        }
コード例 #10
0
        public async Task <ToDo.Domain.ToDo> Create([FromBody] CreateToDoCommand command)
        {
            var toDo = new ToDo.Domain.ToDo
            {
                UserId  = command.UserId,
                DueDate = command.DueDate,
                Note    = command.Note,
                Title   = command.Title
            };

            _toDoContext.ToDo.Add(toDo);
            await _toDoContext.SaveChangesAsync();

            return(toDo);
        }
コード例 #11
0
        public async Task ToDo_CreateCommand_With_Null_ToDo()
        {
            //arrange
            var createToDoCommand = new CreateToDoCommand
            {
                ToDoModel = null,
            };

            _ = _argumentValidator.Setup(x => x.Validate(It.IsAny <object>())).Throws <ArgumentNullException>();
            //act
            var         _commandHandler = new CreateNewToDoCommandHandler(_toDoReposiotry.Object, _argumentValidator.Object);
            Func <Task> act             = async() => await _commandHandler.HandleAsync(createToDoCommand);

            //assert
            await act.Should().ThrowAsync <ArgumentNullException>().WithMessage("Value cannot be null.");
        }
コード例 #12
0
        public async Task <IActionResult> Login(string userName, string password)
        {
            var command = new CreateToDoCommand();

            await _endpointInstance.Send(command).ConfigureAwait(false);

            var user = await _userService.UserLogIn(userName, password);

            if (user == null)
            {
                return(RedirectToAction("Index"));
            }

            var toDoList = await _toDoService.GetList(user.Id);

            var model = new UserViewModel();

            return(View(model));
        }
コード例 #13
0
        public async Task ShouldHavePassWhenPostModelStateIsValidAndReturnOkAsync()
        {
            //arrange
            var controller = new ToDosController(_itemToDoRepository.Object);

            var command = new CreateToDoCommand("Hello world!");

            //actual
            var result = await controller.PostAsync(command);

            //assert
            Assert.IsInstanceOf <OkObjectResult>(result);

            var response = result as OkObjectResult;

            Assert.IsInstanceOf <CreateToDoCommand>(response.Value);

            var model = response.Value as CreateToDoCommand;

            Assert.AreEqual(command.Name, model.Name);
        }
コード例 #14
0
        public async Task ToDo_CreateCommand_With_Valid_ButNotSetStatus_ToDo()
        {
            //arrange
            var createToDoCommand = new CreateToDoCommand
            {
                ToDoModel = new Models.ToDoModel
                {
                    Title = "Test Todo"
                },
            };

            _ = _toDoReposiotry.Setup(x => x.AddAsync(It.IsAny <ToDoItem>()).Result).Returns(0);
            //act
            var _commandHandler = new CreateNewToDoCommandHandler(_toDoReposiotry.Object, _argumentValidator.Object);

            var result = await _commandHandler.HandleAsync(createToDoCommand);

            //assert
            result.Should().NotBeNull();
            result.IsSuccess.Should().BeFalse();
        }
 public async Task <ActionResult <int> > Create([FromBody] CreateToDoCommand command)
 {
     Response.StatusCode = StatusCodes.Status201Created;
     return(await _mediator.Send(command));
 }
コード例 #16
0
        public async Task <IActionResult> CreateToDo([FromBody] CreateToDoCommand command)
        {
            var result = await _mediator.Send(command);

            return(CreatedAtAction("GetToDo", routeValues: new { id = result.id }, value: result));
        }