Example #1
0
        public async Task <IActionResult> JoinGroup(string g, CancellationToken cancellationToken)
        {
            try
            {
                var user = await _authService.GetCurrentUser(HttpContext, cancellationToken);

                int groupId = Base64Utils.Base64DecodeToInt(g);

                var result = await _groupMemberService.PostAssignRole(user.ID, groupId, GroupRoles.Member, user.ID, cancellationToken);

                return(result switch
                {
                    GroupPermissionOutcome.Success => StatusCode((int)HttpStatusCode.OK),
                    GroupPermissionOutcome.Unauthorized => StatusCode((int)HttpStatusCode.Unauthorized),
                    _ => throw new ArgumentException(message: $"Unexpected GroupPermissionOutcome value: {result}", paramName: nameof(result))
                });
            }
Example #2
0
        public async Task <IActionResult> JoinAndGo(string groupIdEnc, CancellationToken cancellationToken)
        {
            var groupId = Int32.Parse(Base64Utils.Base64Decode(groupIdEnc));
            var group   = (Groups)groupId;

            CommunityViewModel communityViewModel = await _communityRepository.GetCommunity(groupId, cancellationToken);

            if (communityViewModel == null)
            {
                return(RedirectToAction("Error404", "Errors"));
            }

            var user = await _authService.GetCurrentUser(HttpContext, cancellationToken);

            var outcome = await _groupMemberService.PostAssignRole(user.ID, groupId, GroupRoles.Member, -1, cancellationToken);

            communityViewModel.IsLoggedIn    = true;
            communityViewModel.IsGroupMember = outcome == GroupPermissionOutcome.Success;

            return(View(communityViewModel.View, communityViewModel));
        }