Ejemplo n.º 1
0
        public IActionResult Post([FromBody] TodoView todo)
        {
            var id      = Guid.NewGuid();
            var created = _todosWriter.CreateTodo(id, todo.Title);

            return(new CreatedAtRouteResult("GetTodo", new { id }, RenderTodoView(created)));
        }
Ejemplo n.º 2
0
        public ActionResult ToDo(ToDo toDo)
        {
            ToDoManager manager = new ToDoManager(Properties.Settings.Default.ConStr);
            TodoView    tdv     = new TodoView();

            tdv.ToDo = toDo;
            return(View(tdv));
        }
Ejemplo n.º 3
0
        static void Main(string[] args)
        {
            ITodoRepository todoRepository = new TodoRepository();
            ITodoService    todoService    = new TodoService(todoRepository);
            var             todoView       = new TodoView(todoService);

            todoView.ViewShowTodoList();
        }
Ejemplo n.º 4
0
        public async Task <IActionResult> Patch(int id, [FromBody] TodoView view, CancellationToken cancellationToken = default(CancellationToken))
        {
            await _commandProcessor.SendAsync(new UpdateTodo(id, view.Title, view.Completed, view.Order), false, cancellationToken).ConfigureAwait(false);

            // todo: yeah, this is a hack
            view.Id  = id;
            view.Url = GetTodoUri(id);

            return(Ok(view));
        }
Ejemplo n.º 5
0
        public async Task <IActionResult> Post([FromBody] TodoView view, CancellationToken cancellationToken = default(CancellationToken))
        {
            var id = Math.Abs(Guid.NewGuid().GetHashCode());
            await _commandProcessor.SendAsync(new CreateTodo(id, view.Title, view.Completed, view.Order), false, cancellationToken).ConfigureAwait(false);

            // todo: yeah, this is a hack
            view.Id  = id;
            view.Url = GetTodoUri(id);

            HttpContext.Response.Headers.Add("Location", view.Url);

            return(Created(view.Url, view));
        }
Ejemplo n.º 6
0
        public async Task <IActionResult> PutTodo([FromRoute] int id, [FromBody] TodoView todoView)
        {
            _logger.LogInformation($"UPDATE todo Id : {id}");

            if (id != todoView.Id)
            {
                return(BadRequest());
            }
            Todo todo = _mapper.Map <Todo>(todoView);
            await _todosService.UpdateTodo(id, todo);

            return(NoContent());
        }
Ejemplo n.º 7
0
        public async Task <IActionResult> PostTodo([FromBody] TodoView todoView)
        {
            _logger.LogInformation($"POST todo");
            if (todoView == null)
            {
                return(BadRequest());
            }
            todoView.Id = 0;
            var todo = _mapper.Map <Todo>(todoView);

            todo = await _todosService.CreateTodo(todo);

            todoView = _mapper.Map <TodoView>(todo);
            return(CreatedAtAction("GetTodo", new { id = todoView.Id }, todoView));
        }
Ejemplo n.º 8
0
        public async Task <IActionResult> Get(int id, CancellationToken cancellationToken = default(CancellationToken))
        {
            var result = await _queryProcessor.ExecuteAsync(new GetTodo(id), cancellationToken).ConfigureAwait(false);

            if (result.Todo == null)
            {
                return(NotFound());
            }

            var view = new TodoView
            {
                Id        = result.Todo.Id,
                Title     = result.Todo.Title,
                Completed = result.Todo.Completed,
                Order     = result.Todo.Order,
                Url       = GetTodoUri(result.Todo.Id)
            };

            return(Ok(view));
        }
Ejemplo n.º 9
0
        public async void PostTodoTest()
        {
            string uriString = "/api/v1/todos/";
            // Act
            var response = await _client.GetAsync(uriString);

            response.EnsureSuccessStatusCode();

            var responseString = await response.Content.ReadAsStringAsync();

            var beforeArray = JArray.Parse(responseString);
            var category    = new TodoCategoryView {
                Id = 3, Name = "TESTCategory", Argb = 120
            };
            var todo = new TodoView {
                Title = "Test", IsDone = false, Type = category
            };
            JObject todoJSON = (JObject)JToken.FromObject(todo);
            //HttpContent content = new StringContent("{\"title\":\"Alma\",\"isDone\":false,\"type\":{\"id\":15,\"name\":\"fsadf\",\"argb\":0},\"creationDate\":\"2018-02-10T11:58:25.2233333\"}",Encoding.UTF8, "application/json");
            HttpContent content = new StringContent(todoJSON.ToString(), Encoding.UTF8, "application/json");

            response = await _client.PostAsync(uriString, content);

            response.EnsureSuccessStatusCode();

            response = await _client.GetAsync(uriString);

            response.EnsureSuccessStatusCode();

            responseString = await response.Content.ReadAsStringAsync();

            var afterArray = JArray.Parse(responseString);

            // Assert
            Assert.Equal(beforeArray.Count + 1, afterArray.Count);
        }