Esempio n. 1
0
        public async Task <IActionResult> AssignOrganizationAdmin(AssignOrganizationAdminModel model)
        {
            var user = _dataAccess.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 (_dataAccess.Organziations.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)));
                }
                else
                {
                    ModelState.AddModelError(nameof(AssignOrganizationAdminModel.OrganizationId), "Invalid Organization. Please contact support.");
                }
            }

            return(View());
        }
Esempio n. 2
0
        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);
        }