Exemple #1
0
        public static BaseSpecification <TodoItem> NameStartWith(string name, int skip, int take)
        {
            var spec = new BaseSpecification <TodoItem>(t => t.Name.Contains(name));

            spec.ApplyOrderBy(t => t.Name);
            spec.ApplyPaging(skip, take);
            return(spec);
        }
        public async Task <IReadOnlyList <Operation> > ListAllWithGraphAsync()
        {
            BaseSpecification <Operation> spec = new BaseSpecification <Operation>();

            spec.AddInclude(o => o.IdCategorieNavigation);
            spec.ApplyOrderBy(O => O.Dateoperation);
            return(await this.ListAsync(spec));
        }
        public async Task<IReadOnlyList<Categorie>> ListAllWithGraphAsync()
        {
            BaseSpecification<Categorie> spec = new BaseSpecification<Categorie>();
            spec.AddInclude(C => C.IdTypecategorieNavigation);
            spec.ApplyOrderBy(C => C.Libelle);

            return await _repositoryAsync.ListAsync(spec);            
        }
Exemple #4
0
        public async Task <IDataSourceResult <UserGroup> > GetUserGroupsAsync(int skip, int take, string name = "")
        {
            BaseSpecification <UserGroup> baseSpecification = new BaseSpecification <UserGroup>(q =>
                                                                                                (string.IsNullOrEmpty(name) || q.Name.Contains(name)));

            baseSpecification.ApplyOrderBy(q => q.DisplayOrder);
            baseSpecification.ApplyPaging(skip, take);
            return(await ToDataSourceResultAsync(baseSpecification));
        }
Exemple #5
0
        public async Task <IDataSourceResult <CmsMenu> > GetMenusAsync(int skip, int take, string position = "", bool?active = null, string name = null, string parentId = null)
        {
            BaseSpecification <CmsMenu> menuSpecification = new BaseSpecification <CmsMenu>(q =>
                                                                                            (string.IsNullOrEmpty(name) || EF.Functions.Contains(q.Name, name)) &&
                                                                                            (string.IsNullOrEmpty(position) || EF.Functions.Contains(q.Position, position)) &&
                                                                                            (string.IsNullOrEmpty(parentId) || q.ParentId == parentId) &&
                                                                                            (!active.HasValue || q.Active == active));

            menuSpecification.ApplyOrderBy(q => q.DisplayOrder);
            menuSpecification.ApplyPaging(skip, take);
            return(await ToDataSourceResultAsync(menuSpecification));
        }
        public async Task <IDataSourceResult <FileResourceMapping> > GetMediaMappingsAsync(int skip, int take, string fileResourceId = null, string objectId = null, ObjectTypeEnum?objectTypeId = null, bool?published = null)
        {
            BaseSpecification <FileResourceMapping> baseSpecification = new BaseSpecification <FileResourceMapping>(q =>
                                                                                                                    (!published.HasValue || q.Published == published) &&
                                                                                                                    (!objectTypeId.HasValue || q.ObjectType == objectTypeId) &&
                                                                                                                    (string.IsNullOrEmpty(objectId) || q.ObjectId == objectId) &&
                                                                                                                    (string.IsNullOrEmpty(fileResourceId) || q.FileResourceId == fileResourceId));

            baseSpecification.ApplyOrderBy(q => q.DisplayOrder);
            baseSpecification.ApplyPaging(skip, take);
            return(await ToDataSourceResultAsync(baseSpecification));
        }
        public async Task <List <ReceiverViewModel> > GetReceivers(Guid currentUserId, int pageIndex)
        {
            BaseSpecification <Group> groupSpec = new BaseSpecification <Group>();

            groupSpec.AddCriteria(x => x.GroupUsers.Any(y => y.UserId == currentUserId));
            groupSpec.ApplyPaging(pageIndex * Constants.ItemsPerPage, Constants.ItemsPerPage);
            groupSpec.ApplyOrderBy(x => x.Name);
            IReadOnlyList <Group> groups = await _groupRepository.ListAsync(groupSpec);

            List <ReceiverViewModel> results = groups.Select(x => new ReceiverViewModel()
            {
                Id      = x.Id,
                Name    = x.Name,
                IconUrl = "https://ptetutorials.com/images/user-profile.png"                 //todo: need add to db
            }).ToList();

            if (Constants.ItemsPerPage == results.Count)
            {
                return(results);
            }

            int groupCount = await _groupRepository.CountAsync(new BaseSpecification <Group>());

            int gropupPage = (int)Math.Floor((decimal)(groupCount / Constants.ItemsPerPage));

            pageIndex -= gropupPage;
            int skip = pageIndex > 0 ? (((gropupPage + 1) * Constants.ItemsPerPage) - groupCount) + ((pageIndex - 1) * Constants.ItemsPerPage) : 0;
            BaseSpecification <User> userSpec = new BaseSpecification <User>();

            userSpec.AddCriteria(x => x.Id != currentUserId);
            userSpec.ApplyPaging(skip, Constants.ItemsPerPage - results.Count);
            userSpec.ApplyOrderBy(x => x.Name);
            IReadOnlyList <User> users = await _userRepository.ListAsync(userSpec);

            results.AddRange(users.Select(x => new ReceiverViewModel()
            {
                Id      = x.Id,
                Name    = x.Name,
                IconUrl = "https://ptetutorials.com/images/user-profile.png"                 //todo: need add to db
            }).ToList());

            return(results);
        }
Exemple #8
0
        public async Task <IDataSourceResult <Currency> > GetCurrenciesAsync(
            int skip,
            int take,
            string name            = "",
            string currencyCode    = "",
            bool?published         = null,
            bool?isPrimaryExchange = null,
            bool?isPrimarySystem   = null)
        {
            BaseSpecification <Currency> baseSpecification = new BaseSpecification <Currency>(q =>
                                                                                              (string.IsNullOrEmpty(name) || EF.Functions.Contains(q.Name, name)) &&
                                                                                              (string.IsNullOrEmpty(currencyCode) || q.CurrencyCode == currencyCode) &&
                                                                                              (!published.HasValue || q.Published == published) &&
                                                                                              (!isPrimaryExchange.HasValue || q.IsPrimaryExchange == isPrimaryExchange) &&
                                                                                              (!isPrimarySystem.HasValue || q.IsPrimarySystem == isPrimarySystem));

            baseSpecification.ApplyOrderBy(q => q.DisplayOrder);
            baseSpecification.ApplyPaging(skip, take);
            return(await ToDataSourceResultAsync(baseSpecification));
        }