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}")); } }
public async Task <ActionResult <IEnumerable <UserTaskReadDTO> > > GettUserTasks() { try { string token = HttpContext.Request.Headers["authorization"].Single().Split(" ")[1]; if (!await _repository.ValidateToken(token)) { return(Unauthorized()); } int loggedUserId = Int32.Parse(User.FindFirst(ClaimTypes.NameIdentifier)?.Value); var taskItems = await _repository.GetUserTasks(loggedUserId); return(Ok(_mapper.Map <IEnumerable <UserTaskReadDTO> >(taskItems))); } catch (Exception) { return(new StatusCodeResult(StatusCodes.Status500InternalServerError)); } }