public async Task UnbanUserFromConversation(int conversationId, string userToUnbanId, string whoAccessedId) { if (userToUnbanId == whoAccessedId) { throw new InvalidDataException("Can't unban yourself."); } var conversation = await ConversationRepository.GetByIdAsync(conversationId); var banned = await usersRepository.GetByIdAsync(userToUnbanId); var userRole = await rolesRepository.GetByIdAsync(conversationId, whoAccessedId); if (userRole.RoleId != ChatRole.Moderator && userRole.RoleId != ChatRole.Creator) { throw new InvalidDataException("Only creator / moderator can unban users."); } if (banned == null) { throw new InvalidDataException("Wrong user to unban id was provided."); } if (conversation == null) { throw new InvalidDataException("Wrong conversation id was provided."); } try { var entry = await ConversationsBansRepository.GetByIdAsync(userToUnbanId, conversationId); await ConversationsBansRepository.DeleteAsync(entry); await unitOfWork.Commit(); } catch { throw new InvalidDataException("Wrong conversation id was provided."); } }
public async Task UnbanDialog(string userId, string whoUnbans) { try { await UsersBansRepository.DeleteAsync(await UsersBansRepository.GetByIdAsync(userId, whoUnbans)); } catch { throw new InvalidDataException("Wrong id of a person to unban."); } UsersConversationDataModel dialog; if ((dialog = await usersConversationsRepository.GetDialog(userId, whoUnbans)) != null) { var entry = await ConversationsBansRepository.GetByIdAsync(userId, dialog.Conversation.Id); await ConversationsBansRepository.DeleteAsync(entry); } await unitOfWork.Commit(); }