Exemple #1
0
        public async Task <ActionResult> Update([FromBody] SysUserView model)
        {
            var resdata = await AutoException.Excute <SysUser>(async (result) =>
            {
                model.UpdateBy = "admin";
                model.UpdateDt = DateTime.Now;
                var res        = await SysUserDAL.UpdateAsync(model);
                result.Data    = model;
                if (!res)
                {
                    throw new Exception("数据修改异常,JSON:" + Newtonsoft.Json.JsonConvert.SerializeObject(model));
                }
                else
                {
                    if (!string.IsNullOrEmpty(model.userrole))
                    {
                        string[] idstr = model.userrole.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
                        List <SysUserRole> rolelist = (from p in idstr
                                                       select new SysUserRole
                        {
                            RoleId = Convert.ToInt32(p),
                            UserId = model.Id,
                            Status = 1,
                            CreateDt = DateTime.Now,
                            CreateBy = model.UpdateBy
                        }).ToList();
                        await SysUserRoleDAL.BatchInsertAsync(rolelist);
                    }
                }
            }, false);

            return(Json(resdata));
        }
Exemple #2
0
        public async Task <ActionResult> UpdatePwd(string id, string pwd)
        {
            var resdata = await AutoException.Excute <long>(async (result) =>
            {
                string[] idstr = id.Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries);
                foreach (var item in idstr)
                {
                    var model      = await SysUserDAL.GetByOneAsync(w => w.Id == Convert.ToInt32(item));
                    model.Password = pwd; //MD5编码
                    var bl         = await SysUserDAL.UpdateAsync(model);
                    if (!bl)
                    {
                        throw new Exception("密码修改异常,ID:" + item);
                    }
                }
            }, false);

            return(Json(resdata));
        }