public TodoItemViewModel Handle(CreateTodoItem request)
        {
            var todoItem = TodoItem.Create(request.Description);

            _repository.Add(todoItem);

            return(Mapper.Map <TodoItemViewModel>(todoItem));
        }
Beispiel #2
0
        public HttpResponseMessage CreateItem([FromBody] TodoItem item)
        {
            item = _todoItemsRepo.Add(item);

            var response = Request.CreateResponse <TodoItem>(HttpStatusCode.Created, item);

            response.Headers.Location = new Uri(Url.Link("DefaultApi", new { id = item.Id }));

            return(response);
        }
        public Task AddTodoItem(string title, string description)
        {
            var todoItem = new TodoItem
            {
                Title       = title,
                Description = description
            };

            todoItem.Create();

            return(_todoItemRepository.Add(todoItem.ToData()));
        }
        public async Task Handle(AddCommand message, IMessageHandlerContext context)
        {
            logger.LogDebug($"command received with id {message.Id}");
            var newTodoItem = new TodoItem(Guid.Parse(message.Id), message.Title, message.DueDate.ToDateTime());

            repository.Add(newTodoItem);
            await context.Publish(new TodoAddedEvent
            {
                Id    = newTodoItem.Id.ToString(),
                Title = newTodoItem.Title
            });
        }
Beispiel #5
0
        public async Task <ActionResult <List <TodoItem> > > Get()
        {
            var todoItem = new TodoItem
            {
                Id         = 1,
                Name       = "A simple TODO item",
                IsComplete = false
            };

            // For rapid testing.
            _todoItemRepository.Add(todoItem);
            todoItem.Id = 2;
            _todoItemRepository.Add(todoItem);
            todoItem.Id = 3;
            _todoItemRepository.Add(todoItem);
            todoItem.Id = 4;
            _todoItemRepository.Add(todoItem);
            var test = _todoItemRepository.GetTodoItems();

            return(test);
        }
Beispiel #6
0
        public TodoItemMutation(ITodoItemRepository repo)
        {
            this.repo = repo;

            Field <TodoItemType>(
                "addTodo",
                description: "Adds a todo to the database",
                arguments: new QueryArguments
            {
                new QueryArgument <TodoItemInputType>()
                {
                    Name = "todo"
                }
            },
                resolve: context =>
            {
                var task = context.GetArgument <TodoItem>("todo");
                return(repo.Add(task));
            }
                );

            Field <TodoItemType>(
                "updateTodo",
                description: "Updates a todo in the database",
                arguments: new QueryArguments
            {
                new QueryArgument <TodoItemInputType>()
                {
                    Name = "todo"
                }
            },
                resolve: context =>
            {
                return(repo.Update(context.GetArgument <TodoItem>("todo")));
            }
                );

            Field <BooleanGraphType>(
                "deleteTodo",
                description: "Deletes a todo from the database",
                arguments: new QueryArguments
            {
                new QueryArgument <StringGraphType>()
                {
                    Name = "todoId"
                }
            },
                resolve: context =>
            {
                return(repo.Delete(context.GetArgument <string>("todoId")));
            }
                );
        }
        public override async Task <AddReply> Add(AddRequest request, ServerCallContext context)
        {
            logger.LogDebug("adding a todo");
            var newTodoItem = new TodoItem(Guid.NewGuid(), request.Title, request.DueDate.ToDateTime());

            repository.Add(newTodoItem);
            await PublishTodoAddedEventFor(newTodoItem);

            return(new AddReply
            {
                Item = AsMessage(newTodoItem)
            });
        }
Beispiel #8
0
        public IHttpActionResult PostTodoItem(TodoItem todoItem)
        {
            todoItem.Id        = Guid.NewGuid().ToString();
            todoItem.CreatedAt = DateTimeOffset.UtcNow;
            todoItem.UpdatedAt = DateTimeOffset.UtcNow;

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            _repository.Add(todoItem);

            return(CreatedAtRoute("DefaultApi", new { id = todoItem.Id }, todoItem));
        }
        public void CreateTodoItem()
        {
            var t = new TodoItem {
                Priority = 4, Description = "test", DueDate = new DateTime(1999, 9, 13)
            };

            _todoItemRepository.Add(t);
            _todoItemRepository.SaveChanges();
            Assert.AreNotEqual(0, t.Id);
            Assert.AreEqual("test", t.Description);
            Assert.AreEqual(new DateTime(1999, 9, 13), t.DueDate);
            Assert.AreEqual(4, t.Priority);
        }
Beispiel #10
0
 public async Task <Either <TodoFailure, Unit> > Handle(AddTodoCommand request, CancellationToken cancellationToken) =>
 await
     (from item in Validate(request)
     from _ in _todoItemRepository.Add(item)
     select _).ToEither();
Beispiel #11
0
 public TodoItem PostProduct(TodoItem item)
 {
     item = repository.Add(item);
     return(item);
 }
 public TodoItemDto Create(TodoItemDto todo)
 {
     return(mapper.Map <TodoItemDto>(repository.Add(mapper.Map <TodoItem>(todo))));
 }
Beispiel #13
0
        public async Task <ActionResult <TodoItem> > AddTodo([FromBody] TodoItem todo)
        {
            TodoItem addedTodo = await repo.Add(todo);

            return(CreatedAtAction(nameof(Get), new { todoId = addedTodo.Id }, addedTodo));
        }
Beispiel #14
0
 public async Task <TodoItem> Create(TodoItemDto item)
 {
     return(await _todoItemRepository.Add(item));
 }