Exemplo n.º 1
0
        public JsonResult searchListItem(string userName , GridSettings gridSettings)
        {
            DataItemSearchFilter filter = new DataItemSearchFilter();
            filter.Email = userName;
            if (gridSettings.IsSearch)
            {
                filter.Title = gridSettings.Where.rules.Any(r => r.field == "Title") ?
                        gridSettings.Where.rules.FirstOrDefault(r => r.field == "Title").data : string.Empty;

                filter.AuthorName = gridSettings.Where.rules.Any(r => r.field == "Author") ?
                        gridSettings.Where.rules.FirstOrDefault(r => r.field == "Author").data : string.Empty;
            }
            int totalRecords = 0;
            var items = dataItemService.Search(filter, gridSettings.SortColumn, gridSettings.SortOrder, gridSettings.PageSize, gridSettings.PageIndex, out totalRecords);

            var jsonData = new
            {
                total = totalRecords / gridSettings.PageSize + 1,
                page = gridSettings.PageIndex,
                records = totalRecords,
                rows = (
                    from a in items
                    select new
                    {
                        ID = a.ID,
                        Title = a.Title,
                        SubMenuName = a.MainMenu.CodeName + " > " + a.SubCategory.CodeName,
                        Country = a.Country.CodeName,
                        InsertDate = a.CreatedDate,
                        EditDate = a.LastUpdatedDate,
                        Author = a.CreatedUser.FullName
                    }
                )
            };

            JsonResult result = Json(jsonData);
            return result;
        }
Exemplo n.º 2
0
        public IEnumerable<DataItem> Search(DataItemSearchFilter filter, string sortColumn, string sortOrder, int pageSize, int pageIndex, out int totalRecords)
        {
            IEnumerable<DataItem> items = context.DataItems.ToList();

            if (!string.IsNullOrEmpty(filter.Title))
            {
               items = items.Where(t => t.Title.ToLower().Contains(filter.Title.ToLower()));
            }

            if (!string.IsNullOrEmpty(filter.CountryName))
            {
                var country = this.context.SubCategories.Where(c => c.ParentCategoryCode == (int)MainCategoryType.Country && c.CodeName.Contains(filter.CountryName.ToLower())).FirstOrDefault();
                if (country != null)
                {
                    items = items.Where(t => t.CountryID == country.Code);
                }
            }

            if (!string.IsNullOrEmpty(filter.SubMenuName))
            {
                string[] menus = filter.SubMenuName.Split('>');
                if(menus.Count() > 1)
                {
                    string mainMenu = menus[0].Trim();
                    string subMenu = menus[1].Trim();

                    var main = this.context.MainMenus.Where(m => m.CodeName.Contains(mainMenu.ToLower())).FirstOrDefault();
                    if(main != null)
                    {
                        var sub = this.context.SubMenus.Where(m => m.ParentCategoryCode == main.Code && m.CodeName.Contains(subMenu.ToLower())).FirstOrDefault();
                        if(sub != null)
                        {
                            items = items.Where(t => t.SubCategoryID == sub.Code);
                        }

                    }

                }

            }

            if (!string.IsNullOrEmpty(filter.AuthorName))
            {

                     items = items.Where(t => t.CreatedUser.FullName.ToLower().Contains(filter.AuthorName.ToLower()));

            }

            if (!string.IsNullOrEmpty(filter.Email))
            {
                items = items.Where(t => t.CreatedUser.Email.ToLower().Contains(filter.Email.ToLower()));
            }
            totalRecords = items.Count();
            return items.OrderByDescending(item => item.CreatedDate).Skip((pageIndex - 1) * pageSize).Take(pageSize).ToList();
        }