private void DeleteTask(DeleteTaskMessage m) { DisableCalculation(); Tasks.Remove(m.Task); if (Tasks.Count == 0) { AddDummyTask(); } AllowCalculation(); CalculateTotals(); }
public static async Task Run( [SignalRTrigger(Constants.SignalRTasksHubName, "messages", DeleteTaskMessage.MethodName, ConnectionStringSetting = Constants.SignalRConnectionStringSetting)] InvocationContext invocationContext, [SignalRParameter] DeleteTaskMessage argument, [CosmosDB(Constants.CosmosDbDatabase, Constants.CosmosDbTasksCollection, ConnectionStringSetting = Constants.CosmosDbConnectionStringSetting)] DocumentClient documentClient, [SignalR(HubName = Constants.SignalRTasksHubName, ConnectionStringSetting = Constants.SignalRConnectionStringSetting)] IAsyncCollector <SignalRMessage> signalRMessages, ILogger log) { var taskListId = argument.TaskListId; var taskId = argument.QuickTaskId; // Send new task to everyone await signalRMessages.AddAsync(new SignalRMessage { GroupName = taskListId, Target = GotDeletedTaskMessage.MethodName, Arguments = new object[] { new GotDeletedTaskMessage(taskId) { IgnoreConnectionId = invocationContext.ConnectionId } } }); // Get entire task list var uri = UriFactory.CreateDocumentUri(Constants.CosmosDbDatabase, Constants.CosmosDbTasksCollection, taskListId.ToString()); var requestOptions = new RequestOptions { PartitionKey = new PartitionKey(taskListId.ToString()), JsonSerializerSettings = new JsonSerializerSettings { ContractResolver = new CamelCasePropertyNamesContractResolver() } }; var taskList = await documentClient.ReadDocumentAsync <QuickTaskList>(uri, requestOptions); // // Add task to task list // TODO: handle error // if (taskList.Document == null) return new NotFoundResult(); // if (taskList.Document.Tasks == null) return new BadRequestObjectResult("No tasks found for this list."); var index = taskList.Document.Tasks.FindIndex(t => t.Id == taskId); // TODO: handle error // if (index == -1) return new BadRequestObjectResult($"Task with id {taskId} not found on this list."); taskList.Document.Tasks.RemoveAt(index); await documentClient.ReplaceDocumentAsync(uri, taskList.Document, requestOptions); }