public async Task <IActionResult> RemoveUserFromGroup(string adminId, int groupId, string userId) { AppUser user = await userManager.FindByIdAsync(adminId); Group group = repository.Groups.FirstOrDefault(g => g.GroupId == groupId); if (user != null) { repository.RemoveUserFromGroup(groupId, userId); //remove user from chat if (group.GroupChatId != 0) { if (repository.GroupChatUsers .FirstOrDefault(g => g.GroupChatId == group.GroupChatId && g.UserId == userId) != null) { repository.RemoveUserFromGroupChat(group.GroupChatId, userId); } } //remove notification for user Notification notification = repository.Notifications .FirstOrDefault(n => n.For == "Group" && n.ForId == groupId && n.Subject == "NewGroupUser" && n.ForUserId == userId); if (notification != null) { repository.DeleteNotification(notification.NotificationId); } return(RedirectToAction("GroupDetails", new { id = adminId, groupId })); } else { return(RedirectToAction("UserNotFound", "Error")); } }