コード例 #1
0
        public void SaveUser(peAppUser user)
        {
            using (var dbContext = new AccountDbContext())
            {
                if (user.ID > 0)
                {
                    dbContext.Update <peAppUser>(user);

                    var roles = dbContext.Roles.Where(r => user.RoleIds.Contains(r.ID)).ToList();
                    user.Roles = roles;
                    dbContext.SaveChanges();
                }
                else
                {
                    var existUser = dbContext.FindAll <peAppUser>(u => u.LoginName == user.LoginName);
                    if (existUser.Count > 0)
                    {
                        throw new BusinessException("LoginName", "此登录名已存在!");
                    }
                    else
                    {
                        dbContext.Insert <peAppUser>(user);

                        var roles = dbContext.Roles.Where(r => user.RoleIds.Contains(r.ID)).ToList();
                        user.Roles = roles;
                        dbContext.SaveChanges();
                    }
                }
            }
        }
コード例 #2
0
        //
        // GET: /Account/peAppUser/Create

        public ActionResult Create()
        {
            var roles = this.AccountService.GetRoleList();

            this.ViewBag.RoleIds = new SelectList(roles, "ID", "Name");

            var model = new peAppUser();

            model.Password = "******";
            return(View("Edit", model));
        }
コード例 #3
0
        public void ModifyPwd(peAppUser user)
        {
            user.Password = Encrypt.MD5(user.Password);

            using (var dbContext = new AccountDbContext())
            {
                if (dbContext.Users.Any(l => l.ID == user.ID && user.Password == l.Password))
                {
                    if (!string.IsNullOrEmpty(user.NewPassword))
                    {
                        user.Password = Encrypt.MD5(user.NewPassword);
                    }

                    dbContext.Update <peAppUser>(user);
                }
                else
                {
                    throw new BusinessException("Password", "原密码不正确!");
                }
            }
        }
コード例 #4
0
        public ActionResult Create(FormCollection collection)
        {
            var model = new peAppUser();

            this.TryUpdateModel <peAppUser>(model);
            model.Password = "******";
            model.Password = Encrypt.MD5(model.Password);

            try
            {
                this.AccountService.SaveUser(model);
            }
            catch (BusinessException e)
            {
                this.ModelState.AddModelError(e.Name, e.Message);

                var roles = this.AccountService.GetRoleList();
                this.ViewBag.RoleIds = new SelectList(roles, "ID", "Name");

                return(View("Edit", model));
            }

            return(this.RefreshParent());
        }