public IActionResult AbortNewGroupChat(string id, int groupChatId)
        {
            ViewData["Id"] = id;

            repository.DeleteGroupChat(groupChatId);

            return(RedirectToAction("Index", new { id }));
        }
        public async Task DeleteGroupChat(int chatId)
        {
            GroupChat chat = repository.GroupChats.FirstOrDefault(c => c.ChatId == chatId);

            IQueryable <string> chatUsers = repository.GroupChatUsers.Where(cu => cu.GroupChatId == chatId).Select(c => c.UserId);

            repository.DeleteGroupChat(chatId);

            await Clients.All.SendAsync("DeleteGroupChat-DeleteChatFromHeader", chatId);

            await Clients.All.SendAsync("DeleteGroupChat-DeleteChatFromIndex", chatId);

            await Clients.All.SendAsync("DeleteGroupChat-ExitChat", chatId);
        }
        public async Task <IActionResult> DeleteGroup(string id, int groupId)
        {
            AppUser user = await userManager.FindByIdAsync(id);

            Group group = repository.Groups.FirstOrDefault(g => g.GroupId == groupId);

            if (user != null)
            {
                //delete group chat if exists
                if (group.GroupChatId != 0)
                {
                    repository.DeleteGroupChat(group.GroupChatId);
                }

                //delete notifications
                foreach (Notification notification in repository.Notifications
                         .Where(n => n.For == "Group" && n.ForId == groupId))
                {
                    repository.DeleteNotification(notification.NotificationId);
                }

                //delete photo and group directory
                if (group.GroupPhotoPath != null)
                {
                    string dirPath = Path.Combine(hostingEnvironment.WebRootPath, $@"UsersData\Groups\{group.GroupId}");
                    System.IO.Directory.Delete(dirPath, true);
                }

                repository.DeleteGroup(groupId);

                return(RedirectToAction("Groups", new { id }));
            }
            else
            {
                return(RedirectToAction("UserNotFound", "Error"));
            }
        }