Beispiel #1
0
 public Guid SaveVerifyCode(string verifyCodeText)
 {
     if (string.IsNullOrWhiteSpace(verifyCodeText))
         throw new BusinessException("verifyCode", "输入的验证码不能为空!");
     using (var dbContext = new AccountDbContext())
     {
         var verifyCode = new VerifyCode() { VerifyText = verifyCodeText, Guid = Guid.NewGuid() };
         dbContext.Insert<VerifyCode>(verifyCode);
         return verifyCode.Guid;
     }
 }
Beispiel #2
0
        public void SaveUser(User user)
        {
            using (var dbContext = new AccountDbContext())
            {
                if (user.ID > 0)
                {
                    dbContext.Update<User>(user);

                    var roles = dbContext.Roles.Where(r => user.RoleIds.Contains(r.ID)).ToList();
                    user.Roles = roles;
                    dbContext.SaveChanges();
                }
                else
                {
                    var existUser = dbContext.FindAll<User>(u => u.LoginName == user.LoginName);
                    if (existUser.Count > 0)
                    {
                        throw new BusinessException("LoginName", "此登录名已存在!");
                    }
                    else
                    {
                        dbContext.Insert<User>(user);
                        var roles = dbContext.Roles.Where(r => user.RoleIds.Contains(r.ID)).ToList();
                        user.Roles = roles;
                        dbContext.SaveChanges();
                    }
                }
            }
        }
Beispiel #3
0
 /// <summary>
 /// 编辑保存
 /// </summary>
 public void SaveMenu(Menu model)
 {
     string cachingKey = "ConfigFile_AdminMenuConfig";
     using (var dbContext = new AccountDbContext())
     {
         model.ParentId = model.ParentId ?? _RootMenuId;
         if (model.ID > 0)
         {
             dbContext.Update<Menu>(model);
         }
         else
         {
             model.Orderby = MaxOrderNumber(model.Parent ?? GetMenu(model.ParentId.Value));
             dbContext.Insert<Menu>(model);
         }
         Caching.Remove(cachingKey); //删除菜单缓存
     }
 }
Beispiel #4
0
 public void SaveRole(Role model)
 {
     using (var dbContext = new AccountDbContext())
     {
         if (model.ID > 0)
         {
             dbContext.Update<Role>(model);
         }
         else
         {
             dbContext.Insert<Role>(model);
         }
     }
 }
Beispiel #5
0
        public LoginInfo Login(string loginName, string password, string ip = null)
        {
            LoginInfo loginInfo = null;
            //password = Encrypt.MD5(password);
            loginName = loginName.Trim();

            using (var dbContext = new AccountDbContext())
            {
                var user = dbContext.Users.Include("Roles").Where(u => u.LoginName == loginName && u.Password == password && u.IsActive).FirstOrDefault();
                if (user != null)
                {
                    ip = ip ?? Fetch.UserIp;
                    loginInfo = dbContext.FindAll<LoginInfo>(p => p.LoginName == loginName && p.ClientIP == ip).FirstOrDefault();
                    if (loginInfo != null)
                    {
                        loginInfo.LastAccessTime = DateTime.Now;
                    }
                    else
                    {
                        loginInfo = new LoginInfo(user.ID, user.LoginName);
                        if (user.Roles != null && user.Roles.Count > 0 && user.Roles.Exists(u => u.Name == "系统管理员"))   //判断是否系统管理员
                            loginInfo.EnumLoginAccountType = (int)EnumLoginAccountType.Administrator;
                        loginInfo.ClientIP = ip;
                        loginInfo.BusinessPermissionList = user.BusinessPermissionList;
                        dbContext.Insert<LoginInfo>(loginInfo);
                    }
                }
            }

            return loginInfo;
        }