Пример #1
0
        public IEnumerable <T> GetAll(string[] includes = null)
        {
            //HANDLE INCLUDES FOR ASSOCIATED OBJECTS IF APPLICABLE
            if (includes != null && includes.Count() > 0)
            {
                var query = dataContext.Set <T>().Include(includes.First());
                foreach (var include in includes.Skip(1))
                {
                    query = query.Include(include);
                }
                return(query.AsQueryable());
            }

            return(dataContext.Set <T>().AsQueryable());
        }
        public async Task <List <Menu> > GetUserMenu(int?userId)
        {
            var userModules = new List <int>();
            var menu        = await _dbContext.Menu.Include("SubMenu").Where(x => !x.IsDeleted).ToListAsync();

            if (userId > 0)
            {
                userModules = await _dbContext.Set <UserRoleModulePermission>().Where(x => x.UserId == userId && !x.IsDeleted).Select(x => (int)x.ModuleId).ToListAsync();
            }
            else
            {
                userModules = await _dbContext.Set <ModuleMaster>().Where(x => !x.IsDeleted).Select(x => x.Id).ToListAsync();
            }

            //if (userModules != null)
            //{
            //    var result = (from um in userModules
            //                  join mm in menu on um equals mm.ModuleId into menus
            //                  from m in menus.DefaultIfEmpty()
            //                  where m.IsDeleted == false
            //                  select new Menu
            //                  {
            //                      Title = m.Title,
            //                      Title_TId = m.Title_TId,
            //                      Title_TName = m.Title_TName,
            //                      Icon = m.Icon,
            //                      Path = m.Path,
            //                      CreatedBy = m.CreatedBy,
            //                      CreatedDate = m.CreatedDate,
            //                      ModifiedBy = m.ModifiedBy,
            //                      ModifiedDate = m.ModifiedDate,
            //                      SubMenu = m.SubMenu
            //                  }).ToList();
            //    return result;
            //}
            return(menu as List <Menu>);
        }
Пример #3
0
        public bool IsSessionValid(long logId)
        {
            var maxExtensionTime = _clock().AddMinutes(-1 * Convert.ToInt32(_settings.SessionTimeout));

            //if (_securityContext.User == null)
            //{
            //    return false;
            //}

            return((from session in _dbContext.Set <DailyLoginHistory>()
                    where session.Id == logId &&
                    session.LogOutTime == null &&
                    (session.LoginTime > maxExtensionTime || session.LastExtension != null && session.LastExtension > maxExtensionTime)
                    select true).SingleOrDefault());
        }
Пример #4
0
        //IQueryable<ValidSecurityTask> AvailableTasksFromDb(int userId)
        //{
        //    var today = _clock().Date;

        //    var tasks = _dbContext.PermissionsGranted(userId, "TASK", null, null, today)
        //        .Where(_ => _.CanExecute || _.CanDelete || _.CanInsert || _.CanUpdate);

        //    return from t in tasks
        //        select new ValidSecurityTask
        //        {
        //            TaskId = (short) t.ObjectIntegerKey,
        //            CanInsert = t.CanInsert,
        //            CanUpdate = t.CanUpdate,
        //            CanDelete = t.CanDelete,
        //            CanExecute = t.CanExecute
        //        };
        //}

        //public static IQueryable<PermissionsGrantedItem> PermissionsGranted(this AdminDbContext dbContext, int UserId, string objectTable, int? objectIntegerKey, string objectStringKey, DateTime today)
        //{
        //    var ctx = dbContext as SqlDbContext;

        //    return ctx == null
        //        ? FromInMemoryContext<PermissionsGrantedItem>(dbContext)
        //        : ctx.PermissionsGranted(UserId, objectTable, objectIntegerKey, objectStringKey, today);
        //}

        //[DbFunction("CodeFirstDatabaseSchema", "fn_PermissionsGranted")]
        //public IQueryable<PermissionsGrantedItem> PermissionsGranted(int userIdentityId, string objectTable, int? objectIntegerKey, string objectStringKey, DateTime today)
        //{
        //    var intKey = objectIntegerKey.HasValue;
        //    var strKey = !string.IsNullOrWhiteSpace(objectStringKey);

        //    var parameters = new[]
        //    {
        //        new ObjectParameter("pnIdentityKey", userIdentityId),
        //        new ObjectParameter("psObjectTable", objectTable),
        //        intKey ? new ObjectParameter("pnObjectIntegerKey", objectIntegerKey) : new ObjectParameter("pnObjectIntegerKey", typeof(int?)),
        //        strKey ? new ObjectParameter("psObjectStringKey", objectStringKey) : new ObjectParameter("psObjectStringKey", typeof(string)),
        //        new ObjectParameter("pdtToday", today)
        //    };

        //    var ctx = ((IObjectContextAdapter)this).ObjectContext;
        //    return ctx.CreateQuery<PermissionsGrantedItem>($"[{GetType().Name}].[fn_PermissionsGranted](@pnIdentityKey, @psObjectTable, @pnObjectIntegerKey, @psObjectStringKey, @pdtToday)", parameters);
        //}

        static IQueryable <T> FromInMemoryContext <T>(AdminDbContext dbContext) where T : class
        {
            return(dbContext.Set <T>().AsQueryable());
        }
Пример #5
0
 public ServiceBase(AdminDbContext applicationContext)
 {
     _context  = applicationContext;
     _entities = applicationContext.Set <T>();
 }
Пример #6
0
 public virtual async Task <T> GetByIdAsync(int id)
 {
     return(await _dbContext.Set <T>().FindAsync(id));
 }
 /// <summary>
 /// 获取实体集合
 /// </summary>
 /// <returns></returns>
 public List <TEntity> GetAllList()
 {
     return(_dbContext.Set <TEntity>().ToList());
 }