public async Task <IActionResult> ShereTasksAsync(int userId, int userIdToShere, List <TaskInfo> tasksToShere, CancellationToken cancellationToken) { try { if (!ModelState.IsValid) { var errors = ModelState.StringifyModelErrors(); return(BadRequest(errors)); } _logger.LogError($"ShereTasksAsync: shere tasks for user id {userId} - into {userIdToShere}"); var result = await _dataRepository.ShereTasks(userId, tasksToShere, userIdToShere); //send email to user with new tasks var user = await _dataRepository.GetUser(userId); var userTo = await _dataRepository.GetUser(userIdToShere); var tasks = await _dataRepository.GetUserTasks(userId); await _emailRepository.SendEmail(user.Email, userTo.Email, "New Tasks for you", FormatTasks(tasks)); return(Ok(result)); } catch (Exception ex) { _logger.LogError($"ShereTasksAsync: failed to shere tasks for user id {userId} - {ex.Message}"); return(NotFound($"failed to shere tasks for user id {userId} - {ex.Message}")); } }