Пример #1
0
        public ActionResult Form(string id)
        {
            Models.BrandUserDetailVM model = null;
            if (id != null)
            {
                var user = this.aspNetUserService.Get(id);
                if (user != null)
                {
                    model = new Models.BrandUserDetailVM
                    {
                        UserName    = user.UserName,
                        FullName    = user.FullName,
                        isActive    = user.isActive,
                        PhoneNumber = user.PhoneNumber,
                        Email       = user.Email,
                        Id          = user.Id,
                    };
                    var userRoles = UserManager.GetRoles(user.Id).ToArray();
                    ViewBag.userRoles = userRoles;
                    if (userRoles.Length > 0)
                    {
                        model.Role = userRoles[0];
                    }
                }
            }
            ViewBag.brandList = BrandController.GetBrandList();
            List <Models.RoleVM> roleList = UserMngController.GetRoleList();

            roleList.RemoveAt(2);
            ViewBag.roleList = roleList;
            return(View(model));
        }
Пример #2
0
        public async System.Threading.Tasks.Task <ActionResult> Add(Models.BrandUserDetailVM model)
        {
            if (ModelState.IsValid)
            {
                var currUser = Helper.GetCurrentUser();
                var user     = new Wisky.Models.ApplicationUser
                {
                    UserName    = model.UserName,
                    Email       = model.Email,
                    FullName    = model.FullName,
                    PhoneNumber = model.PhoneNumber,
                    BrandId     = currUser.BrandID,
                    isActive    = model.isActive,
                };
                var result = await UserManager.CreateAsync(user, model.Password);

                if (result.Succeeded)
                {
                    Session.Clear();
                    Session["ADD_RESULT"] = true;
                    if (model.Role.CompareTo("System Admin") == 0)
                    {
                        model.Role = "Active User";
                    }
                    UserManager.AddToRoles(user.Id, new string[] { model.Role });
                    return(new ContentResult
                    {
                        Content = string.Format("<script type='text/javascript'>window.parent.location.href = '{0}';</script>", Url.Action("Index", "BrandUserMng")),
                        ContentType = "text/html"
                    });
                }
            }
            // If we got this far, something failed, redisplay form
            ViewBag.brandList = BrandController.GetBrandList();
            ViewBag.roleList  = UserMngController.GetRoleList();
            return(View("Form", model));
        }