示例#1
0
        public ActionResult NewCustodian(Guid id, [Bind(Include = "LoginId,Password,EmailAddress,FirstName,LastName")] CreateCustodianModel createCustodian)
        {
            var community = _communitiesQuery.GetCommunity(id);

            if (community == null)
            {
                return(NotFound("community", "id", id));
            }

            if (createCustodian == null)
            {
                createCustodian = new CreateCustodianModel();
            }

            try
            {
                // Look for errors.

                createCustodian.Validate();

                // Create the login.

                CreateCustodian(community, createCustodian);

                // Get ready to create another.

                return(RedirectToRouteWithConfirmation(CommunitiesRoutes.NewCustodian, new { id }, HttpUtility.HtmlEncode("The account for " + createCustodian.FirstName + " " + createCustodian.LastName + " has been created.")));
            }
            catch (UserException ex)
            {
                ModelState.AddModelError(ex, new StandardErrorHandler());
            }

            return(View(new NewCustodianModel
            {
                Community = community,
                Custodian = createCustodian
            }));
        }
示例#2
0
        private void CreateCustodian(Community community, CreateCustodianModel model)
        {
            // For now use the old way of doing things.

            var custodian = new Custodian
            {
                EmailAddress = new EmailAddress {
                    Address = model.EmailAddress
                },
                FirstName = model.FirstName,
                LastName  = model.LastName,
            };

            var credentials = new LoginCredentials
            {
                LoginId      = model.LoginId,
                PasswordHash = LoginCredentials.HashToString(model.Password),
            };

            // Create the account.

            _custodianAccountsCommand.CreateCustodian(custodian, credentials, community.Id);
        }