protected override async Task Handle(EditItem request, CancellationToken cancellationToken) { var accountPlan = await _accountPlanRepository.FindAccountPlanByAccountIdAsync(request.AccountId); var plan = await _planRepository.FindPlanByIdAsync(accountPlan.PlanId); var accountPlanAuthorization = new AccountPlanAuthorizationValidator(accountPlan, plan); var list = await _todoListRepository.FindTodoListIdByIdAsync(request.ListId); var item = await _todoListItemRepository.FindToDoListItemByIdAsync(request.ItemId); var todoListAuthorizationValidator = new TodoListAuthorizationValidator(list.Contributors, request.Email); if (todoListAuthorizationValidator.IsUserAuthorized()) { var dueDate = accountPlanAuthorization.CanAddDueDate() ? request.DueDate : null; item.Name = request.Name; item.Notes = request.Notes; item.DueDate = dueDate; item.EditItem(item); await _todoListItemRepository.SaveChangesAsync(); } }
public async Task <TodoListItem> Handle(CreateItem request, CancellationToken cancellationToken) { var accountPlan = await _accountPlanRepository.FindAccountPlanByAccountIdAsync(request.AccountId); var plan = await _planRepository.FindPlanByIdAsync(accountPlan.PlanId); var accountPlanAuthorization = new AccountPlanAuthorizationValidator(accountPlan, plan); var list = await _todoListRepository.FindTodoListIdByIdAsync(request.ListId); var todoListAuthorization = new TodoListAuthorizationValidator(list.Contributors, request.Email); if (todoListAuthorization.IsUserAuthorized()) { if (list == null) { return(null); } var dueDate = accountPlanAuthorization.CanAddDueDate() ? request.DueDate : null; var id = _todoListItemRepository.NextId(); var todoItem = list.CreateListItem(id, request.Name, request.Notes, dueDate, request.Important); await _todoListItemRepository.AddTodoListItemAsync(todoItem); await _todoListItemRepository.SaveChangesAsync(); return(todoItem); } return(null); }
protected async override Task Handle(MarkItemAsImportant request, CancellationToken cancellationToken) { var item = await _itemRepository.FindToDoListItemByIdAsync(request.ItemId); item.Important = request.Important; await _itemRepository.SaveChangesAsync(); }
protected override async Task Handle(TrashItem request, CancellationToken cancellationToken) { var item = await _listItemRepository.FindToDoListItemByIdAsync(request.ItemId); item.MoveToTrash(); await _listItemRepository.SaveChangesAsync(); }
public async Task Handle(SubItemCreated notification, CancellationToken cancellationToken) { var itemId = notification.SubItem.ListItemId.GetValueOrDefault(); var item = await _todoListItemRepository.FindToDoListItemByIdAsync(itemId); item.SetHasSubItems(true); await _todoListItemRepository.SaveChangesAsync(); }
public async Task Handle(SubItemMovedToTrash notification, CancellationToken cancellationToken) { var item = await _todoListItemRepository.FindToDoListItemByIdAsync(notification.ItemId.GetValueOrDefault()); var subItems = await _subItemRepository.FindAllSubItemsByListItemIdAsync(item.Id); item.SetHasSubItems(subItems.Count > 0); await _todoListItemRepository.SaveChangesAsync(); }
public async Task Handle(SubItemCreated notification, CancellationToken cancellationToken) { var subItems = await _subItemRepository.FindAllSubItemsByListItemIdAsync(notification.SubItem.ListItemId.GetValueOrDefault()); var listItem = await _listItemRepository.FindToDoListItemByIdAsync(notification.SubItem.ListItemId.GetValueOrDefault()); listItem.SetCompleted(subItems); await _listItemRepository.SaveChangesAsync(); }
public async Task Handle(TrashedList notification, CancellationToken cancellationToken) { var itemsInList = await _itemRepository.FindAllTodoListItemsByListIdAsync(notification.ListId); foreach (var item in itemsInList) { var subitems = await _subItem.FindAllSubItemsByListItemIdAsync(item.Id); foreach (var subItem in subitems) { subItem.MoveToTrash(); } item.MoveToTrash(); } await _itemRepository.SaveChangesAsync(); }
protected override async Task Handle(ItemCompletedState request, CancellationToken cancellationToken) { var subItemCount = await _listItemRepository.GetSubItemCountAsync(request.ItemId); if (subItemCount > 0) { return; } var item = await _listItemRepository.FindToDoListItemByIdAsync(request.ItemId); if (request.Completed == true) { item.SetCompleted(); } else if (request.Completed == false) { item.SetNotCompleted(); } await _listItemRepository.SaveChangesAsync(); }