public void AddOrUpdate(UserView view)
        {
            if (string.IsNullOrEmpty(view.OrganizationIds))
            {
                throw new Exception("请为用户分配机构");
            }
            User user = view;

            if (string.IsNullOrEmpty(view.Id))
            {
                if (UnitWork.IsExist <User>(u => u.Account == view.Account))
                {
                    throw new Exception("用户账号已存在");
                }
                user.CreateTime = DateTime.Now;
                user.Password   = user.Account; //初始密码与账号相同
                UnitWork.Add(user);
                view.Id = user.Id;              //要把保存后的ID存入view
            }
            else
            {
                UnitWork.Update <User>(u => u.Id == view.Id, u => new User
                {
                    Account = user.Account,
                    BizCode = user.BizCode,
                    Name    = user.Name,
                    Sex     = user.Sex,
                    Status  = user.Status
                });
            }
            UnitWork.Save();
            string[] orgIds = view.OrganizationIds.Split(',').ToArray();

            _revelanceApp.DeleteBy(Define.USERORG, user.Id);
            _revelanceApp.AddRelevance(Define.USERORG, orgIds.ToLookup(u => user.Id));
        }
Exemple #2
0
 /// <summary>
 /// 更新相应的多对多关系
 /// </summary>
 /// <param name="view"></param>
 private void UpdateRele(RoleView view)
 {
     string[] orgIds = view.OrganizationIds.Split(',').ToArray();
     _revelanceApp.DeleteBy(Define.ROLEORG, view.Id);
     _revelanceApp.AddRelevance(Define.ROLEORG, orgIds.ToLookup(u => view.Id));
 }