コード例 #1
0
        public ActionResult AddUser(AspNetNewUserModel model)
        {
            if (WWIDal.UserNameExists(model.UserName))
            {
                return(RedirectToAction("Users", "Administration"));
            }

            HashingManager     hasher    = new HashingManager();
            WWIDal             dal       = new WWIDal();
            AspNetNewUserModel userModel = new AspNetNewUserModel();

            try
            {
                userModel = new AspNetNewUserModel()
                {
                    AccessFailedCount = 0,
                    Email             = model.Email,
                    EmailConfirmed    = model.EmailConfirmed,
                    Id                   = Guid.NewGuid().ToString(),
                    LockoutEnabled       = false,
                    LockoutEndDateUtc    = DateTime.MinValue,
                    PasswordHash         = hasher.HashToString(model.Password),
                    PhoneNumber          = (string.IsNullOrEmpty(model.PhoneNumber)) ? "" : model.PhoneNumber,
                    PhoneNumberConfirmed = model.PhoneNumberConfirmed,
                    TwoFactorEnabled     = model.TwoFactorEnabled,
                    UserName             = model.UserName,
                    cbAdministrator      = model.cbAdministrator,
                    cbExecutive          = model.cbExecutive,
                    cbInventory          = model.cbInventory,
                    cbSales              = model.cbSales,
                    cbSupplier           = model.cbSupplier,
                    cbUser               = model.cbUser,
                    cbVendor             = model.cbVendor
                };

                dal = new WWIDal();
                int ret = dal.AddUser(userModel);
            }
            catch (Exception ex)
            {
                Logger.LogError("AddUser Exception", ex);
            }

            return(RedirectToAction("Users", "Administration"));
        }