public async Task <ResultData <QZ_User> > ModifyPassword(QZ_User qZ_User, string oldPassword, string newPassword)
        {
            string message = "密码修改失败,不存在的用户!";

            var query = from u in ModelQZ.DatabaseContext.QZ_User
                        where (u.LoginName == qZ_User.LoginName)
                        select u;

            var data = query.FirstOrDefault();

            if (data != null && data.LoginPwd == (oldPassword + data.PwdSalt).Md5())
            {
                ReflectionHelper.CopyProperties <QZ_User>(qZ_User, data, new String[] { "UserId", "LoginPwd" });

                data.ModifyTime = DateTime.Now.ToString();

                data.PwdSalt  = Guid.NewGuid().ToString("N");
                data.LoginPwd = (newPassword + data.PwdSalt).Md5();
                ModelQZ.DatabaseContext.Entry(data).State = System.Data.Entity.EntityState.Modified;
                await ModelQZ.DatabaseContext.SaveChangesAsync();

                message = string.Empty;
            }

            ResultData <QZ_User> result = new ResultData <QZ_User> {
                IsSuccessed = data != null, Message = message, Data = data
            };

            return(result);
        }
        public async Task <ResultData <QZ_User> > Update(QZ_User qZ_User)
        {
            string message = "用户不存在";

            var query = from u in ModelQZ.DatabaseContext.QZ_User
                        where (u.UserId == qZ_User.UserId)
                        select u;

            QZ_User data = query.FirstOrDefault();

            if (data != null)
            {
                ReflectionHelper.CopyProperties <QZ_User>(qZ_User, data, new String[] { "UserId", "LoginPwd" });

                data.ModifyTime = DateTime.Now.ToString();
                ModelQZ.DatabaseContext.Entry(data).State = System.Data.Entity.EntityState.Modified;
                await ModelQZ.DatabaseContext.SaveChangesAsync();

                message = string.Empty;
            }

            ResultData <QZ_User> result = new ResultData <QZ_User> {
                IsSuccessed = data != null, Message = message, Data = data
            };

            return(result);
        }
        public async Task <ResultData <QZ_User> > Login(QZ_User qZ_User)
        {
            ResultData <QZ_User> result = new ResultData <QZ_User>();
            string message = "登录失败,请检查用户名密码是否正确";

            await Task.Run(() =>
            {
                var query = from u in ModelQZ.DatabaseContext.QZ_User
                            where (u.LoginName == qZ_User.LoginName && u.IsDeleteId != 1 && u.IsForbidden != 1)
                            select u;

                var data = query.FirstOrDefault();

                if (data != null && data.LoginPwd == (qZ_User.LoginPwd + data.PwdSalt).Md5())
                {
                    ReflectionHelper.CopyProperties <QZ_User>(data, qZ_User, new String[] { "LoginPwd", "PwdSalt" });

                    message = "success";
                    //data.PwdSalt = "";
                    //data.LoginPwd = "";

                    result.IsSuccessed = true;
                    result.Data        = qZ_User;
                }
            });

            result.Message = message;

            return(result);
        }
Пример #4
0
        public async Task <ResultData <QZ_Role_User> > Add(QZ_Role qZ_Role, QZ_User qZ_User)
        {
            var query = from ru in ModelQZ.DatabaseContext.QZ_Role_User
                        where ru.RoleId == qZ_Role.RoleId && ru.UserId == qZ_User.UserId
                        select ru;


            QZ_Role_User data = query.FirstOrDefault();

            if (data == null)
            {
                data = ModelQZ.DatabaseContext.QZ_Role_User.Add(new QZ_Role_User
                {
                    RoleId     = qZ_Role.RoleId,
                    UserId     = qZ_User.UserId,
                    IsDeleteId = 0,
                    CreateTime = DateTime.Now.ToString(),
                    ModifyTime = DateTime.Now.ToString()
                });

                await ModelQZ.DatabaseContext.SaveChangesAsync();
            }

            ResultData <QZ_Role_User> result = new ResultData <QZ_Role_User> {
                IsSuccessed = true, Data = data
            };

            return(result);
        }
        public async Task <ResultData <QZ_User> > Add(QZ_User qZ_User)
        {
            string message = "用户已经存在";

            var query = from u in ModelQZ.DatabaseContext.QZ_User
                        where (u.LoginName == qZ_User.LoginName)
                        select u;

            QZ_User data = query.FirstOrDefault();

            bool isSuccessed = false;

            if (data == null)
            {
                qZ_User.PwdSalt  = Guid.NewGuid().ToString("N");
                qZ_User.LoginPwd = (qZ_User.LoginPwd + qZ_User.PwdSalt).Md5();


                qZ_User.CreateTime = DateTime.Now.ToString();
                qZ_User.ModifyTime = DateTime.Now.ToString();
                //ModelQZ.DatabaseContext.Entry(qZ_User).State = System.Data.Entity.EntityState.Added;

                try
                {
                    data = ModelQZ.DatabaseContext.QZ_User.Add(qZ_User);
                    await ModelQZ.DatabaseContext.SaveChangesAsync();

                    message = string.Empty;

                    isSuccessed = true;
                }
                catch (Exception ex)
                {
                    isSuccessed = false;
                    message     = ex.Message;
                }
            }

            ResultData <QZ_User> result = new ResultData <QZ_User> {
                IsSuccessed = isSuccessed, Message = message, Data = data
            };

            return(result);
        }
Пример #6
0
        public ResultData <QZ_Role> QueryRoleByUser(QZ_User qZ_User)
        {
            string message = "获取角色信息失败";

            var query = from ru in ModelQZ.DatabaseContext.QZ_Role_User
                        join r in ModelQZ.DatabaseContext.QZ_Role
                        on ru.RoleId equals r.RoleId
                        where ru.UserId == qZ_User.UserId
                        select r;

            QZ_Role data = query.FirstOrDefault();

            if (data != null)
            {
                message = string.Empty;
            }

            ResultData <QZ_Role> result = new ResultData <QZ_Role> {
                IsSuccessed = data != null, Message = message, Data = data
            };

            return(result);
        }
Пример #7
0
        public ResultData <QZ_Deparment> QueryDeparmentByUser(QZ_User qZ_User)
        {
            string message = "没有该部门信息";

            var query = from du in ModelQZ.DatabaseContext.QZ_Deparment_User
                        join d in ModelQZ.DatabaseContext.QZ_Deparment
                        on du.DeparmentId equals d.DeparmentId
                        where du.UserId == qZ_User.UserId
                        select d;

            QZ_Deparment data = query.FirstOrDefault();

            if (data != null)
            {
                message = string.Empty;
            }

            ResultData <QZ_Deparment> result = new ResultData <QZ_Deparment> {
                IsSuccessed = data != null, Message = message, Data = data
            };

            return(result);
        }