public IActionResult ViewMessage(int messageId) { if (!_authorizationService.CanUserViewMessage(UserId, messageId)) { Unauthorized(); } ViewMessageView model = new ViewMessageView(); model.User = _usersService.GetUserById(UserId); model.Department = _departmentsService.GetDepartmentById(DepartmentId); model.Message = _messageService.GetMessageById(messageId); model.UnreadMessages = _messageService.GetUnreadMessagesCountByUserId(UserId); model.UserGroupsAndRoles = _usersService.GetUserGroupAndRolesByDepartmentId(DepartmentId, true, true, true); _messageService.ReadMessageRecipient(messageId, UserId); return(View(model)); }
public async Task <IActionResult> ViewMessage(int messageId, CancellationToken cancellationToken) { if (!await _authorizationService.CanUserViewMessageAsync(UserId, messageId)) { Unauthorized(); } ViewMessageView model = new ViewMessageView(); model.User = _usersService.GetUserById(UserId); model.Department = await _departmentsService.GetDepartmentByIdAsync(DepartmentId); model.Message = await _messageService.GetMessageByIdAsync(messageId); model.UnreadMessages = await _messageService.GetUnreadMessagesCountByUserIdAsync(UserId); model.UserGroupsAndRoles = _usersService.GetUserGroupAndRolesByDepartmentId(DepartmentId, true, true, true); await _messageService.ReadMessageRecipientAsync(messageId, UserId, cancellationToken); return(View(model)); }