Пример #1
0
        private void DeleteCascade(List <IBatisNetBatchStatement> statements, UserPK pk)
        {
            //此处增加级联删除代码

            //删除组成员关系
            GroupMember gm = new GroupMember {
                UserId = pk.UserId
            };

            statements.Add(new IBatisNetBatchStatement {
                StatementName = gm.GetDeleteMethodName(), ParameterObject = gm.ToStringObjectDictionary(false), Type = SqlExecuteType.DELETE
            });
        }
Пример #2
0
        /*
         * public static bool setSysAdmin(this User user, IList<IBatisNetBatchStatement> statements)
         * {
         *  return setSingleRole(user, statements, GuidAsGroup_SysAdmin);
         * }
         *
         * public static bool setSysOper(this User user, IList<IBatisNetBatchStatement> statements)
         * {
         *  return setSingleRole(user, statements, GuidAsGroup_SysOper);
         * }
         */

        public static bool setRoles(this User user, IList <IBatisNetBatchStatement> statements, IList <string> groupIds)
        {
            bool        result = false;
            GroupMember gm     = new GroupMember()
            {
                UserId = user.UserId
            };

            statements.Add(new IBatisNetBatchStatement {
                StatementName = gm.GetDeleteMethodName(), ParameterObject = gm.ToStringObjectDictionary(false), Type = SqlExecuteType.DELETE
            });
            foreach (string groupId in groupIds)
            {
                gm.GroupId    = Guid.Parse(groupId);
                gm.UserId     = user.UserId;
                gm.OperatedBy = NormalSession.UserId.ToGuid();
                gm.OperatedOn = DateTime.Now;
                statements.Add(new IBatisNetBatchStatement {
                    StatementName = gm.GetCreateMethodName(), ParameterObject = gm.ToStringObjectDictionary(false), Type = SqlExecuteType.INSERT
                });
            }
            result = true;
            return(result);
        }
Пример #3
0
        public ModelInvokeResult <LisenceUserPK> Update(string strUserId, LisenceUser lisenceUser)
        {
            ModelInvokeResult <LisenceUserPK> result = new ModelInvokeResult <LisenceUserPK> {
                Success = true
            };

            try
            {
                List <IBatisNetBatchStatement> statements0 = new List <IBatisNetBatchStatement>();
                List <IBatisNetBatchStatement> statements  = new List <IBatisNetBatchStatement>();
                Guid?_UserId = strUserId.ToGuid();
                if (_UserId == null)
                {
                    result.Success   = false;
                    result.ErrorCode = 59996;
                    return(result);
                }
                lisenceUser.UserId = _UserId;
                /***********************begin 自定义代码*******************/
                lisenceUser.OperatedBy = NormalSession.UserId.ToGuid();
                lisenceUser.OperatedOn = DateTime.Now;
                /***********************end 自定义代码*********************/

                /***********************begin 自定义代码*******************/
                //解析
                List <string> groupIds = new List <string>();
                List <string> areaIds  = new List <string>();
                string        areaId   = null;
                string[]      parts    = lisenceUser.UserType.Split("|".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
                if (parts[0] == GlobalManager.DIKey_01001_NormalUser)
                {
                    lisenceUser.UserType = parts[0];
                    groupIds.AddRange(parts[1].Split(",".ToCharArray(), StringSplitOptions.RemoveEmptyEntries));
                    areaIds.AddRange(parts[2].Split(",".ToCharArray(), StringSplitOptions.RemoveEmptyEntries));
                    areaId = parts[3];
                }
                //绑定用户角色
                if (groupIds.Count > 0)
                {
                    GroupMember gm = new GroupMember()
                    {
                        UserId = lisenceUser.UserId
                    };
                    statements.Add(new IBatisNetBatchStatement {
                        StatementName = gm.GetDeleteMethodName(), ParameterObject = gm.ToStringObjectDictionary(false), Type = SqlExecuteType.DELETE
                    });
                    foreach (string groupId in groupIds)
                    {
                        gm.GroupId    = Guid.Parse(groupId);
                        gm.UserId     = lisenceUser.UserId;
                        gm.OperatedBy = NormalSession.UserId.ToGuid();
                        gm.OperatedOn = DateTime.Now;
                        statements.Add(new IBatisNetBatchStatement {
                            StatementName = gm.GetCreateMethodName(), ParameterObject = gm.ToStringObjectDictionary(false), Type = SqlExecuteType.INSERT
                        });
                    }
                }
                //绑定用户辖区
                if (areaIds.Count > 0)
                {
                    UserArea ua = new UserArea()
                    {
                        UserId = lisenceUser.UserId
                    };
                    statements.Add(new IBatisNetBatchStatement {
                        StatementName = ua.GetDeleteMethodName(), ParameterObject = ua.ToStringObjectDictionary(false), Type = SqlExecuteType.DELETE
                    });
                    foreach (string itemId in areaIds)
                    {
                        ua.AreaId     = itemId.ToGuid();
                        ua.UserId     = lisenceUser.UserId;
                        ua.OperatedBy = NormalSession.UserId.ToGuid();
                        ua.OperatedOn = DateTime.Now;
                        statements.Add(new IBatisNetBatchStatement {
                            StatementName = ua.GetCreateMethodName(), ParameterObject = ua.ToStringObjectDictionary(false), Type = SqlExecuteType.INSERT
                        });
                    }
                }

                User user = new User()
                {
                    UserId       = lisenceUser.UserId,
                    UserCode     = lisenceUser.UserCode,
                    UserName     = lisenceUser.UserName,
                    UserType     = lisenceUser.UserType,
                    PasswordHash = lisenceUser.PasswordHash,
                    Gender       = "N",
                    CreatedBy    = NormalSession.UserId.ToGuid(),
                    CreatedOn    = DateTime.Now,
                    OperatedBy   = NormalSession.UserId.ToGuid(),
                    OperatedOn   = DateTime.Now,
                    Area1        = areaId
                };
                statements.Add(new IBatisNetBatchStatement {
                    StatementName = user.GetUpdateMethodName(), ParameterObject = user.ToStringObjectDictionary(false), Type = SqlExecuteType.UPDATE
                });
                /***********************end 自定义代码*********************/
                BuilderFactory.DefaultBulder(GetHttpHeader(GlobalManager.ConnectIdKey)).ExecuteNativeSqlNoneQuery(statements);

                var param0 = lisenceUser.ToStringObjectDictionary(false);
                if (!string.IsNullOrEmpty(areaId))
                {
                    param0["Area1"] = areaId;
                    var rows = BuilderFactory.DefaultBulder(GetHttpHeader(GlobalManager.ConnectIdKey)).List <DictItemEx>("CTE_AreaCityProvice_List",
                                                                                                                         new
                    {
                        ItemId = areaId
                    }.ToStringObjectDictionary());

                    var city = rows.Where(item => item.Levels == 2).FirstOrDefault();
                    if (city != null)
                    {
                        param0["CityId"] = city.ItemId;
                    }
                }

                statements0.Add(new IBatisNetBatchStatement {
                    StatementName = lisenceUser.GetUpdateMethodName(), ParameterObject = param0, Type = SqlExecuteType.UPDATE
                });
                BuilderFactory.DefaultBulder().ExecuteNativeSqlNoneQuery(statements0);


                result.instance = new LisenceUserPK {
                    UserId = _UserId
                };
            }
            catch (Exception ex)
            {
                result.Success      = false;
                result.ErrorMessage = ex.Message;
            }
            return(result);
        }