コード例 #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));
        }
コード例 #2
0
        private void UpdateUserRole(SysUserView obj)
        {
            var Ser = new BaseService <SysUserRole>();

            Ser.Repository.Delete(a => a.UserId == obj.Id);
            string [] Roles;
            if (obj.strRoles != null)
            {
                Roles = obj.strRoles.Split(',');
                var lst = new List <SysUserRole>();
                foreach (var a in Roles)
                {
                    if (!string.IsNullOrEmpty(a))
                    {
                        var RoleModel = new SysUserRole()
                        {
                            RoleId = int.Parse(a),
                            UserId = obj.Id
                        };
                        lst.Add(RoleModel);
                    }
                }
                Ser.Repository.Insert((IEnumerable <SysUserRole>)lst);
            }
            else
            {
                Roles = null;
            }
        }
コード例 #3
0
        /// <summary>
        /// 加载信息
        /// </summary>
        protected void LoadInfo()
        {
            ddl_Group.DataSource     = GetSysGroup();
            ddl_Group.DataTextField  = "GroupName";
            ddl_Group.DataValueField = "ID";
            ddl_Group.DataBind();

            ddl_Department.DataSource     = GetSysDepartment();
            ddl_Department.DataTextField  = "DepartName";
            ddl_Department.DataValueField = "ID";
            ddl_Department.DataBind();

            if (WS.RequestInt("id") > 0)
            {
                txt_Password.EnableNull = true;
                txt_UserName.Enabled    = false;

                SysUser user = SysUserView.GetModelByID(WS.RequestInt("id").ToString());
                txt_UserName.Text            = user.UserName;
                txt_Password.Text            = user.UserPass;
                ddl_Question.SelectedValue   = user.SafeQuestion;
                txt_Answer.Text              = user.SafeAnswer;
                txt_ChineseName.Text         = user.ChineseName;
                txt_Email.Text               = user.Email;
                txt_TelNumber.Text           = user.TelNumber;
                ddl_Department.SelectedValue = user.Department.ToString();
                ddl_Group.SelectedValue      = user.UserGroup.ToString();
                lb_LastLoginTime.Text        = user.LastLoginTime.ToString();
                lb_LastLoginIP.Text          = user.LastLoginIP;
                lb_LoginCount.Text           = user.Logincount.ToString();
                chk_Enable.Checked           = user.Enabled;
            }
        }
コード例 #4
0
        public void Add(SysUserView view)
        {
            if (string.IsNullOrEmpty(view.OrganizationIds))
            {
                throw new Exception("请为用户分配机构");
            }

            SysUser user = view;

            if (Repository.IsExist(u => u.Account == view.Account))
            {
                throw new Exception("账号已存在");
            }
            if (Repository.IsExist(u => u.Name == view.Name))
            {
                throw new Exception("用户名已存在");
            }

            user.Password = Encryption.Encrypt(user.Password); //密码加密
            Repository.Add(user);
            view.Id = user.Id;                                 //要把保存后的ID存入view
            UnitWork.Save();
            int[] orgIds = Array.ConvertAll(view.OrganizationIds.Split(','), int.Parse);

            _revelanceApp.DeleteBy(Define.USERORG, user.Id.Value);
            _revelanceApp.AddRelevance(Define.USERORG, orgIds.ToLookup(u => user.Id.Value));
        }
コード例 #5
0
 public string Update(SysUserView view)
 {
     try
     {
         _app.Update(view);
     }
     catch (Exception ex)
     {
         Result.Code    = 500;
         Result.Message = ex.InnerException?.Message ?? ex.Message;
     }
     return(JsonHelper.Instance.Serialize(Result));
 }
コード例 #6
0
        /// <summary>
        /// 添加或修改用户
        /// </summary>
        /// <param entity=""></param>
        /// <returns></returns>
        public async Task <SysUser> ModifyAsync(SysUserView entity)
        {
            if (await CheckLoginNameExists(entity.UserId, entity.LoginName))
            {
                throw new Exception($"登录名:【{entity.LoginName}】已存在");
            }

            if (entity.Password.Equals("@@**@@") && entity.UserId > 0)
            {
                //不修改密码,获取旧密码
                var oldEntity = await _sysUserRepository.GetModelAsync(p => p.UserId == entity.UserId);

                entity.Password = oldEntity.Password;
            }
            else
            {
                entity.Password = entity.Password.EncryptMD5Encode();
            }
            //工作单元
            using (var uow = _fsq.CreateUnitOfWork())
            {
                var userRepo = uow.GetRepository <SysUser>();
                userRepo.UnitOfWork = uow;
                var userRoleRepo = uow.GetRepository <SysRoleUser>();
                userRoleRepo.UnitOfWork = uow;

                var newEntity = await userRepo.InsertOrUpdateAsync(entity);

                var insertRoleList = new List <SysRoleUser>();
                //处理用户组
                if (entity.RoleIdArray != null)
                {
                    foreach (var roleId in entity.RoleIdArray)
                    {
                        insertRoleList.Add(new SysRoleUser()
                        {
                            RoleId = roleId,
                            UserId = newEntity.UserId,
                        });
                    }
                }
                //删除之前的
                await userRoleRepo.DeleteAsync(p => p.UserId == newEntity.Id);

                await userRoleRepo.InsertAsync(insertRoleList);

                uow.Commit();
            }
            entity.Password = "******";
            return(entity);
        }
コード例 #7
0
        /// <summary>
        /// 保存资料
        /// </summary>
        protected void SaveInfo()
        {
            SysUser user = new SysUser();

            if (WS.RequestInt("id") > 0)
            {
                user = SysUserView.GetModelByID(WS.RequestInt("id").ToString());
            }
            else if (txt_Password.Text.Length == 0)
            {
                Js.AlertAndGoback("新增用户时,密码不能为空");
            }

            user.UserName = txt_UserName.Text;
            if (txt_Password.Text.Length > 0)
            {
                user.UserPass = Voodoo.Security.Encrypt.Md5(txt_Password.Text);
            }

            user.SafeQuestion = ddl_Question.SelectedValue;
            user.SafeAnswer   = txt_Answer.Text;
            user.Email        = txt_Email.Text;
            user.TelNumber    = txt_TelNumber.Text;
            user.Department   = ddl_Department.SelectedValue.ToInt32();
            user.UserGroup    = ddl_Group.SelectedValue.ToInt32();
            user.ChineseName  = txt_ChineseName.Text;
            user.Enabled      = chk_Enable.Checked;

            if (WS.RequestInt("id") > 0)
            {
                //修改
                SysUserView.Update(user);
                Js.AlertAndChangUrl("修改成功!", "SysUserList.aspx");
            }
            else
            {
                user.LastLoginTime = DateTime.Now;
                user.LastLoginIP   = WS.GetIP();
                Result r = SysUserAction.UserAdd(user);

                if (r.Success)
                {
                    Js.AlertAndChangUrl(r.Text, "SysUserList.aspx");
                }
                else
                {
                    Js.AlertAndGoback(r.Text);
                }
            }
        }
コード例 #8
0
        /// <summary>
        /// 用户登陆
        /// </summary>
        /// <param name="UserName">账号</param>
        /// <param name="PassWord">密码</param>
        /// <param name="Question">问题</param>
        /// <param name="Answer">答案</param>
        /// <returns></returns>
        public static Result UserLogin(string UserName, string PassWord, string Question, string Answer)
        {
            Result r = new Result();

            SysUser user = SysUserView.Find(string.Format("UserName='******'", UserName));

            if (user.UserPass == null || user.UserPass != Encrypt.Md5(PassWord))
            {
                r.Success = false;
                r.Text    = "账号或密码错误";
                return(r);
            }
            else
            {
                //验证问答
                if (user.SafeQuestion != Question || user.SafeAnswer != Answer)
                {
                    r.Success = false;
                    r.Text    = "问题或者回答错误!";
                    return(r);
                }
                else
                {
                    if (user.Enabled == false)
                    {
                        r.Success = false;
                        r.Text    = "用户账号已经停用!";
                        return(r);
                    }
                    else
                    {
                        //更新登陆记录
                        user.Logincount++;
                        user.LastLoginIP   = WS.GetIP();
                        user.LastLoginTime = DateTime.Now;
                        SysUserView.Update(user);

                        //写入Session

                        System.Web.HttpContext.Current.Session["sys_user"] = user.ID;

                        r.Success = true;
                        r.Text    = "登陆成功!";
                        return(r);
                    }
                }
            }
        }
コード例 #9
0
        /// <summary>
        /// 加载信息
        /// </summary>
        protected void LoadInfo()
        {
            ddl_Class.DataSource     = NewsAction.NewsClass.Where(p => p.IsLeafClass && p.ModelID == 2);
            ddl_Class.DataTextField  = "ClassName";
            ddl_Class.DataValueField = "ID";
            ddl_Class.DataBind();

            ddl_Class.SelectedValue = cls.ToS();

            ddl_Author.DataSource     = SysUserView.GetModelList();
            ddl_Author.DataTextField  = "UserName";
            ddl_Author.DataValueField = "ID";
            ddl_Author.DataBind();

            ImageAlbum imga = ImageAlbumView.GetModelByID(id.ToS());

            //txt_Title.Text = imga.Title;
            //ddl_Author.SelectedValue = imga.AuthorID.ToS();
            //txt_Folder.Text = imga.Folder;
            //txt_Keyword.Text=imga.

            if (id > 0)
            {
                ddl_Class.SelectedValue = imga.ClassID.ToS();
                txt_Title.Text          = imga.Title;
                ddl_Author.Text         = imga.AuthorID.ToS();
                //txt_Folder.Text = imga.Folder;
                txt_Keyword.Text    = imga.KeyWords;
                txt_ClickCount.Text = imga.ClickCount.ToS();
                txt_ReplyCount.Text = imga.ClickCount.ToS();
                txt_Intro.Text      = imga.Intro;

                rp_list.DataSource = ImagesView.GetModelList(string.Format("AlbumID={0} order by id", imga.ID));
                rp_list.DataBind();
            }
            else
            {
                ImageAlbumView.Del("AuthorID=0 and CreateTime<'" + DateTime.Now.AddDays(-1).ToString("yyyy-MM-dd") + "'");
                imga = new ImageAlbum()
                {
                    ClassID = cls, ClickCount = 0, ReplyCount = 0, ZtID = 0, CreateTime = DateTime.Now, AuthorID = 0, UpdateTime = DateTime.Now
                };
                ImageAlbumView.Insert(imga);
                Response.Redirect(string.Format("ImageEdit.aspx?class={0}&id={1}", cls, imga.ID));
            }
        }
コード例 #10
0
        /// <summary>
        /// 加载当前登录用户可访问的一个部门及子部门全部用户
        /// </summary>
        public TableData Load(PageReq request, int?orgId)
        {
            var loginUser = _auth.GetCurrentUser();

            string cascadeId = ".0.";

            if (orgId != null)
            {
                var org = loginUser.Orgs.SingleOrDefault(u => u.Id == orgId.Value);
                cascadeId = org.CascadeId;
            }

            var ids     = loginUser.Orgs.Where(u => u.CascadeId.Contains(cascadeId)).Select(u => u.Id.Value).ToArray();
            var userIds = _revelanceApp.Get(Define.USERORG, false, ids);

            //SQL2008不支持分页的语法
            //var data = UnitWork.Find<User>(u => userIds.Contains(u.Id)).ToList();
            //var users = data
            //       .OrderBy(u => u.Name)
            //       .Skip((request.page - 1) * request.limit)
            //       .Take(request.limit);

            var users = Repository.Find(u => userIds.Contains(u.Id.Value) && u.Account != "System")
                        .OrderBy(u => u.Name)
                        .Skip((request.page - 1) * request.limit)
                        .Take(request.limit);

            var records = Repository.GetCount(u => userIds.Contains(u.Id.Value) && u.Account != "System");

            var userviews = new List <SysUserView>();

            foreach (var user in users.ToList())
            {
                SysUserView uv   = user;
                var         orgs = LoadByUser(user.Id.Value);
                uv.Organizations   = string.Join(",", orgs.Select(u => u.Name).ToList());
                uv.OrganizationIds = string.Join(",", orgs.Select(u => u.Id).ToList());
                userviews.Add(uv);
            }

            return(new TableData
            {
                count = records,
                data = userviews,
            });
        }
コード例 #11
0
        /// <summary>
        /// 用户增加
        /// </summary>
        /// <param name="user"></param>
        /// <returns></returns>
        public static Result UserAdd(SysUser user)
        {
            Result r = new Result();

            if (SysUserView.Exist(string.Format("UserName = '******'", user.UserName)))
            {
                r.Success = false;
                r.Text    = "这个账号已经存在,请重新选择一个账号!";
                return(r);
            }
            else
            {
                SysUserView.Insert(user);
                r.Success = true;
                r.Text    = "添加用户成功!";
                return(r);
            }
        }
コード例 #12
0
        public void Update(SysUserView view)
        {
            if (string.IsNullOrEmpty(view.OrganizationIds))
            {
                throw new Exception("请为用户分配机构");
            }

            SysUser user = view;

            Repository.Update(u => u.Id == view.Id, u => new SysUser
            {
                Account    = user.Account,
                Name       = user.Name,
                Sex        = user.Sex,
                Status     = user.Status,
                UpdateBy   = Repository._loginInfo.Account,
                UpdateTime = DateTime.Now
            });

            int[] orgIds = Array.ConvertAll(view.OrganizationIds.Split(','), int.Parse);

            _revelanceApp.DeleteBy(Define.USERORG, user.Id.Value);
            _revelanceApp.AddRelevance(Define.USERORG, orgIds.ToLookup(u => user.Id.Value));
        }
コード例 #13
0
 /// <summary>
 /// 删除
 /// </summary>
 /// <param name="ids"></param>
 protected void Delete(string ids)
 {
     SysUserView.Del(string.Format("id in({0})", ids));
     Js.AlertAndChangUrl("删除成功!", "SysUserList.aspx");
 }
コード例 #14
0
 public static void SetAppUser(SysUserView user)
 {
     HttpContext.Current.Session[CacheKey.UserKeys] = user;
 }