Ejemplo n.º 1
0
        public async Task <DataStorageResult <IEnumerable <StaffMemberDataModel> > > GetStaffMembersAsync([ParameterDocumentation("Ο δείκτης της σελίδας ξεκινώντας από το 0")] int page, [ParameterDocumentation("Οι κανόνες αναζήτησης")] DateDataStorageArgs args = null)
        {
            if (args == null)
            {
                args = new DateDataStorageArgs();
            }

            try
            {
                var query = (IQueryable <StaffMemberDataModel>)DbContext.StaffMembers;

                if (args.Search != null)
                {
                    query = query.Where(x => x.NormalizedName.Contains(args.Search));
                }

                query = AttachParameters(query, args);

                return(await query.OrderByDescending(x => x.Id).Skip((page * PerPage) + args.Offset).Take(PerPage).ToListAsync());
            }
            catch (Exception ex)
            {
                return(ex);
            }
        }
Ejemplo n.º 2
0
        private IQueryable <T> AttachParameters <T>(IQueryable <T> query, DateDataStorageArgs args)
            where T : BaseDateDataModel
        {
            if (args == null)
            {
                args = new DateDataStorageArgs();
            }

            if (args.After != null)
            {
                query = query.Where(x => x.DateCreated >= args.After);
            }

            if (args.Before != null)
            {
                query = query.Where(x => x.DateCreated <= args.Before);
            }

            if (!args.Include.IsNullOrEmpty())
            {
                query = query.Where(x => args.Include.Contains(x.Id));
            }

            return(query);
        }