private Task OnTodoCreated(TodoCreated created, CancellationToken ct) { _todoList.ItemsLeft++; _todoList.Todos.Add(new ListViewModel.TodoViewModel { Id = created.Todo.Id, IsCompleted = created.Todo.IsCompleted, Title = created.Todo.Title, }); return(_publisher.PublishAsync(new ClientMessage { ClientIds = _clientIds, Payload = _todoList, Type = nameof(ListViewModel) }, ct)); }
private async Task AddTodoAsync() { var newTodo = new Todo { Title = TitleTextBox.Text, Description = DescriptionTextBox.Text, StartDate = StartDatePicker.Value, DueDate = DueDatePicker.Value, Status = StatusBox.SelectedItem.ToString().ParseEnum <TodoStatus>(), Priority = PriorityBox.SelectedItem.ToString().ParseEnum <TodoPriority>() }; if (UsersBox.SelectedItem is User selectedUser && !selectedUser.IsEmpty()) { newTodo.UserId = selectedUser.Id; } var result = await _todoCommandService.AddAsync(newTodo); TodoCreated?.Invoke(this, result); }
public AddEditTaskWindow(Todo todo = null) { InitializeComponent(); if (todo == null) { this.Title = CreateTaskButtonText; TaskDatePicker.SelectedDate = DateTime.Now; DescriptionTb.Text = DefaultTaskDescription; AddEditTaskButton.Content = CreateTaskButtonText; AddEditTaskButton.Click += (sender, args) => { if (Validate()) { TodoCreated?.Invoke(TaskDatePicker.SelectedDate.Value, DescriptionTb.Text); Close(); } }; } else { this.Title = EditTaskButtonText; TaskDatePicker.SelectedDate = todo.Date; DescriptionTb.Text = todo.Description; AddEditTaskButton.Content = EditTaskButtonText; AddEditTaskButton.Click += (sender, args) => { if (Validate()) { todo.Date = TaskDatePicker.SelectedDate.Value; todo.Description = DescriptionTb.Text; TodoEdited?.Invoke(todo); Close(); } }; } }
async void handleToDoMessage(BasicDeliverEventArgs msg) { await toDoSema.WaitAsync(); try { var message = Encoding.UTF8.GetString(msg.Body.ToArray()); var toDo = JsonConvert.DeserializeObject <TodoModel>(message); var headers = msg.BasicProperties.Headers.Where(x => x.Value is byte[]).ToDictionary(x => x.Key, y => Encoding.UTF8.GetString(y.Value as byte[])); if (headers.TryGetValue("event", out var ev)) // still_todo: add as constants, not as hardcoded values { toDo.RabbitEventHeader = ev; if (ev != "ASSIGNED" && ev != "CREATED" && ev != "ACCEPTED" && ev != "DONE") { return; } // we dont care about other events if (ev != "ASSIGNED" && toDo.AssignedToCurrentUser) { return; } // the current user initiated this update -> ignore } // IMPORTANT STILL_TODO: raise event with ToDo for the VM to handle // this goes into the VM: //if (toDo.Assignee == null && DatabaseHelper.Current.LocalTodos.Any(x => x != toDo && x.Blocking && !x.InteractionPending)) //{ // await BackendHelper.DeclineTodoAsync(toDo, true, false); // toDo.RabbitEventHeader = "DECLINED_BECAUSE_BLOCKED"; //} TodoCreated.Invoke(this, new TodoCreatedEventArgs(toDo)); } catch (Exception ex) { } finally { toDoSema.Release(); } }