public Task Put(UpdateTodo request)
        {
            var todo = Todos.FirstOrDefault(x => x.Id == request.Id)
                       ?? throw HttpError.NotFound($"Todo with Id '{request.Id}' does not exit");

            todo.PopulateWith(request);
            return(ServerEvents.NotifyChannelAsync("todos", "todos.update", todo));
        }
        public async Task update_todo_should_succeed_given_valid_title_and_description_and_priority_and_state()
        {
            var command = new UpdateTodo(Guid.NewGuid(), "Some Title", "Some Description", "HIGH", "INPROCESS");

            await _todosService.UpdateAsync(command);

            await _todoRepository.Received().UpdateAsync(Arg.Is <Todo>(x =>
                                                                       x.Id == command.Id &&
                                                                       x.Title == command.Title &&
                                                                       x.Description == command.Description &&
                                                                       x.Priority == Priority.HIGH &&
                                                                       x.State == State.INPROCESS));
        }
        public async Task Handle_Async_Published_Update_TodoItem_Rejected_If_TodoItem_With_Given_Id_Does_Not_Exist()
        {
            UpdateTodo command = new UpdateTodo(_id, _title, _description, _isDone, _userId);

            _todoItemRepository
            .GetAsync(_id)
            .ReturnsNull();

            await Act(command);

            await _busPublisher
            .Received()
            .PublishAsync(Arg.Is <UpdateTodoItemRejected>(e => e.Id == command.Id && e.Code == "todo_item_does_not_exist" && e.Reason == $"TodoItem with id: '{command.Id}' was not found."), _context);
        }
        public async Task Handle_Async_Published_Todo_Item_Updated_If_Ok()
        {
            UpdateTodo command = new UpdateTodo(_id, _title, _description, true, _userId);
            TodoItem   item    = new TodoItem(_id, _userId, _description, _title, _isDone);

            _todoItemRepository
            .GetAsync(_id)
            .Returns(item);

            await Act(command);

            await _busPublisher
            .Received()
            .PublishAsync(Arg.Is <TodoItemUpdated>(e => e.Id == command.Id && e.Title == command.Title && e.Description == command.Description && e.IsDone == command.IsDone && e.UserId == command.UserId), _context);
        }
Exemple #5
0
        public async Task UpdateAsync(UpdateTodo command)
        {
            if (!Enum.TryParse <State>(command.State, true, out var state))
            {
                throw new InvalidTodoStateException(command.State);
            }

            if (!Enum.TryParse <Priority>(command.Priority, true, out var priority))
            {
                throw new InvalidTodoPriorityException(command.Priority);
            }

            var todo = new Todo(command.Id, command.Title, command.Description, priority, state);

            await _todoRepository.UpdateAsync(todo);
        }
Exemple #6
0
 public ActionResult UpdateTodoItem(long id, [FromBody] UpdateTodo todoItem)
 {
     try
     {
         _todoService.UpdateTodoItem(id, todoItem);
         return(NoContent());
     }
     catch (TodoNotFoundException ex)
     {
         return(NotFound(ex.Message));
     }
     catch (Exception ex)
     {
         _logger.LogError(ex, "Unhandled exception occurred (HTTP 500): {0} {2}{3}", Request.Method, Request.Path, Request.QueryString);
         return(StatusCode((int)HttpStatusCode.InternalServerError, "Unexpected error occured"));
     }
 }
Exemple #7
0
        public void UpdateTodoItem(long id, UpdateTodo updateTodoItem)
        {
            var todoItem = _todoStore.GetTodoById(id);

            if (todoItem == null)
            {
                throw new TodoNotFoundException();
            }

            if (updateTodoItem.Value != null)
            {
                todoItem.Value = updateTodoItem.Value;
            }

            if (updateTodoItem.IsComplete != null)
            {
                todoItem.IsComplete = (bool)updateTodoItem.IsComplete;
            }

            _todoStore.UpdateTodoItem(todoItem);
        }
Exemple #8
0
        static TodoAppState UpdateTodo(TodoAppState state, UpdateTodo act) => new TodoAppState
        {
            Todos = state.Todos.Select(todo =>
            {
                if (todo.Id == act.Id)
                {
                    return(new Todo
                    {
                        Id = todo.Id,
                        Description = act.Description,
                        IsCompleted = todo.IsCompleted
                    });
                }
                else
                {
                    return(todo);
                }
            }),

            Visibility = state.Visibility
        };
Exemple #9
0
        public IActionResult UpdateTodo(int id)
        {
            var            nhanvien       = new UpdateTodo();
            var            url            = $"{Common.Common.ApiUrl}/todo/gettodobyid/{id}";
            HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create(url);

            httpWebRequest.Method = "GET";
            var response = httpWebRequest.GetResponse();

            {
                string responseData;
                Stream responseStream = response.GetResponseStream();
                try
                {
                    StreamReader streamReader = new StreamReader(responseStream);
                    try
                    {
                        responseData = streamReader.ReadToEnd();
                    }
                    finally
                    {
                        ((IDisposable)streamReader).Dispose();
                    }
                }
                finally
                {
                    ((IDisposable)responseStream).Dispose();
                }
                nhanvien = JsonConvert.DeserializeObject <UpdateTodo>(responseData);
            }
            ViewBag.VGgroups   = ListGroup();
            ViewBag.VGgroupid  = groupIdC;
            ViewBag.VGgroupidd = ListGroup().Where(p => p.IDG == groupIdC).FirstOrDefault().GroupName;

            TempData["Done"] = null;
            TempData["Fail"] = null;

            return(View(nhanvien));
        }
Exemple #10
0
        public IActionResult UpdateTodo(UpdateTodo model)
        {
            int editResult     = 0;
            var httpWebRequest = (HttpWebRequest)WebRequest.Create($"{Common.Common.ApiUrl}/todo/updatetodo");

            httpWebRequest.ContentType = "application/json";
            httpWebRequest.Method      = "PUT";
            using (var streamWrite = new StreamWriter(httpWebRequest.GetRequestStream()))
            {
                var json = JsonConvert.SerializeObject(model);
                streamWrite.Write(json);
            }
            var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse();

            using (var streamReader = new StreamReader(httpResponse.GetResponseStream()))
            {
                var result = streamReader.ReadToEnd();
                editResult = int.Parse(result);
            }
            ViewBag.VGgroups  = ListGroup();
            ViewBag.VGgroupid = groupIdC;
            if (editResult <= 0)
            {
                TempData["Fail"] = "Todo edit fail";
                return(View(model));
            }
            else
            {
                TempData["Done"] = "Todo edit successfully";
                ModelState.Clear();
                return(View(new UpdateTodo()
                {
                    GroupIDG = groupIdC
                }));
            }
        }
Exemple #11
0
 public async Task <IActionResult> Put(Guid id, UpdateTodo command)
 => await SendAsync(command.Bind(c => c.Id, id),
                    resourceId : command.Id, resource : "products");
Exemple #12
0
 public async Task<ActionResult> Put(UpdateTodo command)
 {
     await _todoService.UpdateAsync(command);
     return Ok();
 }
 private async Task Act(UpdateTodo command) => await _commandHandler.HandleAsync(command, _context);