public async Task Delete(Group group) { var forums = _forumService.GetByGroupId(group.Id).ToList(); foreach (var forum in forums) { await _forumService.Delete(forum.Id); } var usersId = _usersGroupsService.GetUsersByGroupId(group.Id).ToList(); foreach (var userId in usersId) { await _usersGroupsService.DeleteUserGroup(userId, group.Id); } _context.Remove(group); await _context.SaveChangesAsync(); }
public async Task <IActionResult> ChosenGroupAsync(string id) { var group = _groupService.GetById(id); var forum = _forumService.GetByGroupId(id); var userId = _userManager.GetUserId(User); if (group == null) { return(new NotFoundResult()); } var authorizationResult = await _authorizationService .AuthorizeAsync(User, group, "EditPolicy"); if (authorizationResult.Succeeded) { var model = new GroupListingModel { Id = group.Id, Name = group.Name, Description = group.Description, ImageUrl = group.ImageUrl, Forums = forum, AdminId = group.AdminId, CurrentUserid = userId }; return(View(model)); } else if (User.Identity.IsAuthenticated) { return(new ForbidResult()); } else { return(new ChallengeResult()); } }