Ejemplo n.º 1
0
        public ActionResult Register(UserAccountModel model)
        {
            if (ModelState.IsValid)
            {
                // Attempt to register the user
                try
                {
                    MembershipCreateStatus createStatus;
                    (Membership.Provider as ByteartRetailMembershipProvider).CreateUser(model.UserName,
                        model.Password,
                        model.Email,
                        null,
                        null,
                        true,
                        null,
                        model.Contact,
                        model.PhoneNumber,
                        new AddressDataObject
                        {
                            Country = model.ContactAddress_Country,
                            State = model.ContactAddress_State,
                            City = model.ContactAddress_City,
                            Street = model.ContactAddress_Street,
                            Zip = model.ContactAddress_Zip
                        },
                        new AddressDataObject
                        {
                            Country = model.DeliveryAddress_Country,
                            State = model.DeliveryAddress_State,
                            City = model.DeliveryAddress_City,
                            Street = model.DeliveryAddress_Street,
                            Zip = model.DeliveryAddress_Zip
                        },
                        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));
                }
            }

            // If we got this far, something failed, redisplay form
            return View(model);
        }
 public ActionResult EditUserAccount(UserAccountModel model)
 {
     using (var proxy = new ServiceProxy<IUserService>())
     {
         var user = model.ConvertToDataObject();
         proxy.Channel.UpdateUsers(new UserDataObjectList { user });
         if (model.Role.ID != Guid.Empty.ToString())
             proxy.Channel.AssignRole(new Guid(model.ID), new Guid(model.Role.ID));
         else
             proxy.Channel.UnassignRole(new Guid(model.ID));
         return RedirectToSuccess("更新用户账户成功!", "UserAccounts", "Admin");
     }
 }
 public ActionResult Account(UserAccountModel model)
 {
     using (var proxy = new ServiceProxy<IUserService>())
     {
         var dataObject = model.ConvertToDataObject();
         proxy.Channel.UpdateUsers(new UserDataObjectList { dataObject });
         return RedirectToSuccess("更新账户信息成功!", "Account", "Account");
     }
 }
Ejemplo n.º 4
0
 public ActionResult AddUserAccount(UserAccountModel model)
 {
     using (ServiceProxy<IUserService> proxy = new ServiceProxy<IUserService>())
     {
         var user = model.ConvertToDataObject();
         var createdUsers = proxy.Channel.CreateUsers(new UserDataObjectList { user });
         if (model.Role.ID != Guid.Empty.ToString())
             proxy.Channel.AssignRole(new Guid(createdUsers[0].ID), new Guid(model.Role.ID));
         return RedirectToSuccess("创建用户账户成功!", "UserAccounts", "Admin");
     }
 }