public async Task <SimpleTask> UncompleteAsync(CompleteUncomplete model) { if (!Exists(model.Id, model.UserId)) { throw new ValidationException("Unauthorized"); } ToDoTask originalTask = await _tasksRepository.UncompleteAsync(model.Id, model.UserId); var result = _mapper.Map <SimpleTask>(originalTask); return(result); }
public async Task <IActionResult> Uncomplete([FromBody] CompleteUncomplete dto) { if (dto == null) { return(BadRequest()); } try { dto.UserId = IdentityHelper.GetUserId(User); } catch (UnauthorizedAccessException) { return(Unauthorized()); } SimpleTask task = await _taskService.UncompleteAsync(dto); // Notify var usersToBeNotified = await _userService.GetToBeNotifiedOfListChangeAsync(task.ListId, dto.UserId, task.Id); if (usersToBeNotified.Any()) { var currentUser = await _userService.GetAsync(dto.UserId); SimpleList list = await _listService.GetAsync(task.ListId); foreach (var user in usersToBeNotified) { CultureInfo.CurrentCulture = new CultureInfo(user.Language, false); string message = _localizer["UncompletedTaskNotification", IdentityHelper.GetUserName(User), task.Name, list.Name]; var updateNotificationDto = new CreateOrUpdateNotification(user.Id, dto.UserId, list.Id, task.Id, message); var notificationId = await _notificationService.CreateOrUpdateAsync(updateNotificationDto); var pushNotification = new PushNotification { SenderImageUri = currentUser.ImageUri, UserId = user.Id, Application = "To Do Assistant", Message = message, OpenUrl = GetNotificationsPageUrl(notificationId) }; _senderService.Enqueue(pushNotification); } } return(NoContent()); }