Ejemplo n.º 1
0
        /// <summary>
        /// 用户添加
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public static bool Add(UserModel model, string[] roleIds)
        {
            UserModel.repo.BeginTransaction();
            StringBuilder sqlLog = new StringBuilder();

            try
            {
                if (string.IsNullOrEmpty(model.CreateMan + ""))
                {
                    model.CreateMan = MTConfig.CurrentUserID.ToInt();
                }
                model.Password = PwdThreeEncrypt.PasswordThreeMd5Encrypt(model.Password);
                string newUserID = UserModel.repo.Insert(model).ToString();
                sqlLog.Append(UserModel.repo.LastCommand + "\n");

                if (roleIds != null)
                {
                    foreach (string roleId in roleIds)
                    {
                        RoleModel roles = new RoleModel();
                        roles = RoleModel.FirstOrDefault("where id = " + roleId);
                        UserProductModel userProduct = new UserProductModel();
                        userProduct.ProductId = roles.ProductId;
                        userProduct.UserId    = newUserID.ToInt();
                        userProduct.Insert();
                        int i = 0;
                        if (int.TryParse(roleId, out i))
                        {
                            UserRoleModel userRole = new UserRoleModel();
                            userRole.UserID    = newUserID.ToInt();
                            userRole.RoleID    = roleId.ToInt();
                            userRole.CreateMan = !string.IsNullOrEmpty(model.CreateMan + "") ? model.CreateMan : MTConfig.CurrentUserID.ToInt();
                            userRole.Insert();
                            sqlLog.Append(UserModel.repo.LastCommand + "\n");
                        }
                    }
                }

                UserModel.repo.CompleteTransaction();
                LogDAL.AppendSQLLog(string.IsNullOrEmpty(model.CreateMan + "") ? MTConfig.CurrentUserID : model.CreateMan + "",
                                    "User", sqlLog.ToString());
            }
            catch (Exception)
            {
                UserModel.repo.AbortTransaction();
                sqlLog = null;
                return(false);
            }

            return(true);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 用户编辑
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public static bool Edit(UserModel model, string[] roleIds)
        {
            UserModel.repo.BeginTransaction();
            StringBuilder sqlLog = new StringBuilder();

            try
            {
                model.CreateMan = MTConfig.CurrentUserID.ToInt();
                UserModel.repo.Save(model);
                sqlLog.Append(UserModel.repo.LastCommand);
                UserRoleModel.Delete("where UserID = @0", model.ID);
                sqlLog.Append(UserModel.repo.LastCommand + "\n");

                if (roleIds != null)
                {
                    foreach (string roleId in roleIds)
                    {
                        UserProductModel.Delete(" where UserID = @0", model.ID);
                        RoleModel roles = new RoleModel();
                        roles = RoleModel.FirstOrDefault("where id = " + roleId);
                        UserProductModel userProduct = new UserProductModel();
                        userProduct.ProductId = roles.ProductId;
                        userProduct.UserId    = model.ID.ToInt();
                        userProduct.Insert();
                        int i = 0;
                        if (int.TryParse(roleId, out i))
                        {
                            UserRoleModel userRole = new UserRoleModel();
                            userRole.UserID    = model.ID.ToInt();
                            userRole.RoleID    = roleId.ToInt();
                            userRole.CreateMan = MTConfig.CurrentUserID.ToInt();
                            userRole.Insert();
                            sqlLog.Append(UserModel.repo.LastCommand + "\n");
                        }
                    }
                }

                UserModel.repo.CompleteTransaction();
                LogDAL.AppendSQLLog(MTConfig.CurrentUserID, "User", sqlLog.ToString());
            }
            catch (Exception)
            {
                UserModel.repo.AbortTransaction();
                sqlLog = null;
                return(false);
            }

            return(true);
        }
Ejemplo n.º 3
0
        public static bool StartFlag(string id)
        {
            bool result = false;

            try
            {
                int rs = UserModel.Update("set DelFlag = 0 where ID=@0", id);
                if (rs == 1)
                {
                    LogDAL.AppendSQLLog(MTConfig.CurrentUserID, "SysUser");
                    result = true;
                }
            }
            catch (Exception)
            {
                throw;
            }
            return(result);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// 修改密码
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public static bool UpdatePassword(UserViewModel model)
        {
            bool result = false;

            try
            {
                model.ModifyPassword = PwdThreeEncrypt.PasswordThreeMd5Encrypt(model.ModifyPassword);
                int rs = UserModel.Update("set password = @0 where id = @1", model.ModifyPassword, model.Id);
                if (rs == 1)
                {
                    LogDAL.AppendSQLLog(MTConfig.CurrentUserID, "SysUser");
                    result = true;
                }
            }
            catch
            {
                throw;
            }
            return(result);
        }
Ejemplo n.º 5
0
 /// <summary>
 /// 登陆
 /// </summary>
 /// <param name="model"></param>
 /// <returns></returns>
 public static bool Login(ref UserModel model)
 {
     model = UserModel.FirstOrDefault("where Name=@0 and Password=@1 and DelFlag=0", model.Name, PwdThreeEncrypt.PasswordThreeMd5Encrypt(model.Password));
     LogDAL.AppendSQLLog(MTConfig.CurrentUserID, "User");
     return(model != null);
 }
Ejemplo n.º 6
0
        public static void AppendSQLLog(string userid, Type modelType, params string[] sql)
        {
            var pd = PocoData.ForType(modelType);

            LogDAL.AppendSQLLog(MTConfig.CurrentUserID, pd.TableInfo.TableName);
        }