Ejemplo n.º 1
0
 public ActionResult EditUserAccount(UserAccountModel model)
 {
     using (var proxy = new UserServiceClient())
     {
         var user = model.ConvertToDto();
         proxy.UpdateUsers(new List<UserDto> { user }.ToArray());
         if (model.Role.Id != Guid.Empty.ToString())
             proxy.AssignRole(new Guid(model.Id), new Guid(model.Role.Id));
         else
             proxy.UnassignRole(new Guid(model.Id));
         return RedirectToSuccess("更新用户账户成功!", "UserAccounts", "Admin");
     }
 }
Ejemplo n.º 2
0
 public ActionResult Manage(UserAccountModel model)
 {
     using(var proxy = new UserServiceClient())
     {
         var userDto = model.ConvertToDto();
         proxy.UpdateUsers(new List<UserDto>() { userDto }.ToArray());
         return RedirectToSuccess("更新账户信息成功!", "Account", "Account");
     }
 }
Ejemplo n.º 3
0
 public ActionResult AddUserAccount(UserAccountModel model)
 {
     using (var proxy = new UserServiceClient())
     {
         var user = model.ConvertToDto();
         var createdUsers = proxy.CreateUsers(new List<UserDto> { user }.ToArray());
         if (model.Role.Id != Guid.Empty.ToString())
             proxy.AssignRole(new Guid(createdUsers[0].Id), new Guid(model.Role.Id));
         return RedirectToSuccess("创建用户账户成功!", "UserAccounts", "Admin");
     }
 }
Ejemplo n.º 4
0
        public ActionResult Register(UserAccountModel model)
        {
            if (!ModelState.IsValid)
                return View(model);

            try
            {
                MembershipCreateStatus createStatus = MembershipCreateStatus.ProviderError;

                var onlineStoreMembershipProvider = Membership.Provider as OnlineStoreMembershipProvider;
                if (onlineStoreMembershipProvider != null)
                    onlineStoreMembershipProvider.CreateUser(model.UserName,
                    model.Password,
                    model.Email,
                    null,
                    null,
                    true,
                    null,
                    model.Contact,
                    model.PhoneNumber,
                    new AddressDto
                    {
                        Country = model.ContactAddressCountry,
                        State = model.ContactAddressState,
                        City = model.ContactAddressCity,
                        Street = model.ContactAddressStreet,
                        Zip = model.ContactAddressZip
                    },
                    new AddressDto
                    {
                        Country = model.DeliveryAddressCountry,
                        State = model.DeliveryAddressState,
                        City = model.DeliveryAddressCity,
                        Street = model.DeliveryAddressStreet,
                        Zip = model.DeliveryAddressZip
                    },
                    out createStatus);

                if (createStatus == MembershipCreateStatus.Success)
                {
                    FormsAuthentication.SetAuthCookie(model.UserName, false /* createPersistentCookie */);
                    return RedirectToAction("Index", "Home");
                }
                else
                    ModelState.AddModelError("", ErrorCodeToString(createStatus));
            }
            catch (MembershipCreateUserException e)
            {
                ModelState.AddModelError("", ErrorCodeToString(e.StatusCode));
            }

            return View(model);
        }