示例#1
0
        public async System.Threading.Tasks.Task <ActionResult> Update(Models.BrandUserUpdateVM model)
        {
            if (ModelState.IsValid)
            {
                /*Update custom fields*/
                var user = aspNetUserService
                           .Get(a => a.Id == model.Id)
                           .FirstOrDefault();
                var currUser = Helper.GetCurrentUser();
                if (user != null)
                {
                    user.BrandID  = currUser.BrandID;
                    user.FullName = model.FullName;
                    user.isActive = model.isActive;
                    await this.aspNetUserService.UpdateAsync(user);

                    /*Update user role*/
                    //Remove from other Roles
                    var userRoles = UserManager.GetRoles(user.Id).ToArray();
                    if (userRoles.Length > 0)
                    {
                        UserManager.RemoveFromRole(user.Id, userRoles[0]);
                    }
                    //Add to new Role
                    if (model.Role.CompareTo("System Admin") == 0)
                    {
                        model.Role = "Active User";
                    }
                    UserManager.AddToRoles(user.Id, new string[] { model.Role });
                    Session.Clear();
                    Session["UPDATE_RESULT"] = true;
                    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));
        }
        public List <Models.UserMngVM> GetAllUser()
        {
            var users   = aspNetUserService.Get().ToList();
            var userVMs = new List <Models.UserMngVM>();

            foreach (var item in users)
            {
                var u = new Models.UserMngVM
                {
                    UserName  = item.UserName,
                    Id        = item.Id,
                    Email     = item.Email,
                    FullName  = item.FullName,
                    isActive  = item.isActive,
                    BrandName = brandService.GetBrandNameByID(item.BrandID),
                };
                userVMs.Add(u);
            }
            return(userVMs);
        }
        public JsonResult CheckBrandIdIsUsed(int id)
        {
            bool check = false;

            try
            {
                IAspNetUserService userService = DependencyUtils.Resolve <IAspNetUserService>();
                var user = userService
                           .Get(a => a.BrandID == id)
                           .FirstOrDefault();
                if (user != null)
                {
                    check = true;
                }
                return(Json(new
                {
                    isUsing = check
                }, JsonRequestBehavior.AllowGet));
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }