public async Task Handles_ValidInput_ApproveGroupMemberAsync()
        {
            var invitedUserMailAddress = new MailAddress("*****@*****.**");
            var approvedByUsername     = "******";
            var invitedToGroupSlug     = "group-slug";

            var response = await _groupAddMemberService.ApproveGroupMemberAsync(invitedUserMailAddress,
                                                                                approvedByUsername,
                                                                                invitedToGroupSlug,
                                                                                CancellationToken.None);

            Assert.AreEqual(response, ResponseType.Success);
        }
Exemplo n.º 2
0
        public async Task <ActionResult> AddMemberAsync(GroupAddMemberViewModel model, CancellationToken cancellationToken)
        {
            ViewBag.HideSideBar = true;

            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            var invitedMemberMailAddress    = new MailAddress(model.Email);
            var groupAddMemberQueryResponse = await _addMemberService.GroupAddMemberQueryAsync(invitedMemberMailAddress, model.Slug, cancellationToken);

            //Dont want to use IMembershipService
            var addedByUsername = System.Web.HttpContext.Current.User.Identity.Name;

            if (ResponseType.DoesntExist == groupAddMemberQueryResponse.Response)
            {
                ModelState.AddModelError(nameof(model.Email), "This user is not registered on the platform.  The platform is not open for new registrations at present, please contact support for more information.");
                return(View(model));
            }

            var response = ResponseType.NoResponse;

            if (ResponseType.AlreadyExists == groupAddMemberQueryResponse.Response)
            {
                if (groupAddMemberQueryResponse.IsApproved)
                {
                    ModelState.AddModelError(nameof(model.Email), "The email address belongs to a member of this group.");
                    return(View(model));
                }
                response = await _addMemberService.ApproveGroupMemberAsync(invitedMemberMailAddress, addedByUsername, model.Slug, cancellationToken);
            }

            if (ResponseType.Success == groupAddMemberQueryResponse.Response)
            {
                response = await _addMemberService.AddMemberToGroupAsync(invitedMemberMailAddress, StandardMemberRole, addedByUsername, model.Slug, cancellationToken);
            }

            if (ResponseType.Success == response)
            {
                var newModel = new GroupAddMemberViewModel
                {
                    Slug     = model.Slug,
                    Response = ResponseType.Success
                };
                return(View(newModel));
            }

            ModelState.AddModelError(nameof(model.Email), response.ToString());
            return(View(model));
        }