public void AssignOrganizationAdminPostHasHttpPostAttribute()
        {
            var mediator = new Mock<IMediator>();
            var controller = new SiteController(null, null, mediator.Object);

            var model = new AssignOrganizationAdminModel { UserId = It.IsAny<string>(), OrganizationId = It.IsAny<int>() };

            var attribute = controller.GetAttributesOn(x => x.AssignOrganizationAdmin(model)).OfType<HttpPostAttribute>().SingleOrDefault();

            Assert.NotNull(attribute);
        }
Exemplo n.º 2
0
        public async Task<IActionResult> AssignOrganizationAdmin(AssignOrganizationAdminModel model)
        {
            var user = GetUser(model.UserId);
            if (user == null)
            {
                return RedirectToAction(nameof(Index));
            }
            
            if (model.OrganizationId == 0)
            {
                ModelState.AddModelError(nameof(AssignOrganizationAdminModel.OrganizationId), "You must pick a valid organization.");
            }

            if (ModelState.IsValid)
            {
                if (_mediator.Send(new AllOrganizationsQuery()).Any(t => t.Id == model.OrganizationId))
                {
                    await _userManager.AddClaimAsync(user, new Claim(Security.ClaimTypes.UserType, UserType.OrgAdmin.ToName()));
                    await _userManager.AddClaimAsync(user, new Claim(Security.ClaimTypes.Organization, model.OrganizationId.ToString()));
                    return RedirectToAction(nameof(Index));
                }

                ModelState.AddModelError(nameof(AssignOrganizationAdminModel.OrganizationId), "Invalid Organization. Please contact support.");
            }

            return View();
        }