예제 #1
0
 public IQueryable <NavNode> GetAll()
 {
     using (_dbContextScopeFactory.CreateReadOnly())
     {
         return(_navNodeRepository.GetAll());
     }
 }
예제 #2
0
        public async Task <Tuple <int, IReadOnlyList <MenuPagingDto> > > GetPagingAsync(SearchMenuDto dto)
        {
            try
            {
                using (_dbContextScopeFactory.CreateReadOnly())
                {
                    var iquery = _menuRepository.GetAll()
                                 .Where(x => x.ActiveFag != CommonUtility.ActiveFag.Delete)
                                 .GroupJoin(_navNodeRepository.GetAll()
                                            .Where(x => x.ActiveFag == CommonUtility.ActiveFag.Active &&
                                                   x.Status != CommonValues.NavNode.NavNodeStatus.Ignore),
                                            mn => mn.NavNodeId,
                                            nav => nav.Id,
                                            (mn, nav) => new { mn, nav = nav.DefaultIfEmpty() })
                                 .SelectMany(z => z.nav.Select(nv => new { z.mn, nv }))
                                 .Select(x => new
                    {
                        x.mn,
                        NavName = x.nv.Name,
                        x.nv.Areas,
                        x.nv.Controller,
                        x.nv.Action,
                        x.nv.Params,
                        NavURL = x.nv.URL,
                    });
                    if (!string.IsNullOrEmpty(dto.KeyWord))
                    {
                        var trimKeyword = dto.KeyWord.Trim();
                        var urlKeyWord  = CommonUtility.ToUnsignString(trimKeyword);
                        iquery = iquery.Where(x => x.mn.Name.ToLower().Contains(trimKeyword) ||
                                              x.mn.Name.ToLower().Contains(trimKeyword) ||
                                              x.Areas.ToLower().Contains(trimKeyword) ||
                                              x.Controller.ToLower().Contains(trimKeyword) ||
                                              x.Action.ToLower().Contains(trimKeyword) ||
                                              x.NavURL.Contains(urlKeyWord) ||
                                              x.mn.URL.Contains(urlKeyWord));
                    }
                    var total = iquery.Count();
                    var data  = await iquery
                                .OrderBy(x => x.mn.Code)
                                .ThenBy(x => x.mn.Order)
                                .Skip((dto.PageIndex - 1) * dto.PageSize)
                                .Take(dto.PageSize)
                                .Select(x => new MenuPagingDto
                    {
                        Id         = x.mn.Id,
                        Code       = x.mn.Code,
                        ParentId   = x.mn.ParentId,
                        NavNodeId  = x.mn.NavNodeId,
                        Layout     = x.mn.Layout,
                        TypeModule = x.mn.TypeModule,
                        Status     = x.mn.Status,
                        Name       = x.mn.Name,
                        Icon       = x.mn.Icon,
                        Areas      = x.Areas,
                        Controller = x.Controller,
                        Action     = x.Action,
                        Params     = x.Params
                    })
                                .ToListAsync();

                    return(new Tuple <int, IReadOnlyList <MenuPagingDto> >(total, data));
                }
            }
            catch (Exception ex) { }
            return(new Tuple <int, IReadOnlyList <MenuPagingDto> >(0, new List <MenuPagingDto>()));
        }