예제 #1
0
 public void UpdateLoginInfo(LoginInfo loginInfo)
 {
     using (var dbContext = new AccountDbContext())
     {
         if (loginInfo != null)
         {
             dbContext.Update<LoginInfo>(loginInfo);
             dbContext.SaveChanges();
         }
     }
 }
예제 #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();
                    }
                }
            }
        }
예제 #3
0
 public void SaveRole(Role model)
 {
     using (var dbContext = new AccountDbContext())
     {
         if (model.ID > 0)
         {
             dbContext.Update<Role>(model);
         }
         else
         {
             dbContext.Insert<Role>(model);
         }
     }
 }
예제 #4
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); //删除菜单缓存
     }
 }
예제 #5
0
 public void ModifyPwd(UserInput model)
 {
     using (var dbContext = new AccountDbContext())
     {
         var oldModel = GetUser(model.ID);
         if (oldModel.Password != model.Password)
         {
             throw new BusinessException("Password", "原密码不正确!");
         }
         oldModel.Password = model.NewPassword;
         oldModel.Email = model.Email;
         oldModel.Mobile = model.Mobile;
         dbContext.Update<User>(oldModel);
     }
 }
예제 #6
0
        public LoginInfo GetLoginInfo(Guid token)
        {
            return CacheHelper.Get<LoginInfo>(string.Format(_LoginInfoKeyFormat, token), () =>
            {
                using (var dbContext = new AccountDbContext())
                {
                    //如果有超时的,启动超时处理
                    var timeoutList = dbContext.FindAll<LoginInfo>(p => DbFunctions.DiffMinutes(DateTime.Now, p.LastAccessTime) > _UserLoginTimeoutMinutes);
                    if (timeoutList.Count > 0)
                    {
                        foreach (var li in timeoutList)
                            dbContext.LoginInfos.Remove(li);
                    }

                    dbContext.SaveChanges();

                    var loginInfo = dbContext.FindAll<LoginInfo>(l => l.LoginToken == token).FirstOrDefault();
                    if (loginInfo != null)
                    {
                        loginInfo.LastAccessTime = DateTime.Now;
                        dbContext.Update<LoginInfo>(loginInfo);
                    }

                    return loginInfo;
                }
            });
        }