Пример #1
0
        public async Task <IActionResult> Sort(SortState sortOrder = SortState.NameAsc)
        {
            IIncludableQueryable <MetanitExampleCoreMVC.Models.User, Company> users = dbUsers.Users.Include(x => x.Company);
            IQueryable <MetanitExampleCoreMVC.Models.User> usersResult;

            ViewData["NameSort"]    = sortOrder == SortState.NameAsc ? SortState.NameDesc : SortState.NameAsc;
            ViewData["AgeSort"]     = sortOrder == SortState.AgeAsc ? SortState.AgeDesc : SortState.AgeAsc;
            ViewData["CompanySort"] = sortOrder == SortState.CompanyAsc ? SortState.CompanyDesc : SortState.CompanyAsc;

            switch (sortOrder)
            {
            case SortState.NameDesc:
                usersResult = users.OrderByDescending(s => s.Name);
                break;

            case SortState.AgeAsc:
                usersResult = users.OrderBy(s => s.Name);
                break;

            case SortState.AgeDesc:
                usersResult = users.OrderByDescending(s => s.Name);
                break;

            case SortState.CompanyAsc:
                usersResult = users.OrderBy(s => s.Name);
                break;

            case SortState.CompanyDesc:
                usersResult = users.OrderByDescending(s => s.Company.Name);
                break;

            default:
                usersResult = users.OrderBy(s => s.Name);
                break;
            }

            IndexSortViewModel viewModel = new IndexSortViewModel
            {
                Users         = await usersResult.AsNoTracking().ToListAsync(),
                SortViewModel = new SortViewModel(sortOrder)
            };

            return(View(viewModel));
        }
Пример #2
0
        /// <summary>
        /// Index
        /// </summary>
        /// <returns></returns>
        public IActionResult Index()
        {
            IIncludableQueryable <Opportunity, Organization> opportunitiesQueryable = _context.Opportunities
                                                                                      .Include(o => o.Category)
                                                                                      .Include(o => o.CreatedBy)
                                                                                      .Include(o => o.Organization);

            List <Opportunity> opportunities = opportunitiesQueryable
                                               .OrderByDescending(x => x.Id)
                                               .ToList();

            return(View(opportunities
                        .Select(opportunity => new OpportunityIndexViewModel()
            {
                Id = opportunity.Id,
                CreatedDateTime = opportunity.CreatedDateTime,
                OrganizationName = opportunity.Organization.Name,
                Name = opportunity.Name,
                Category = opportunity.Category?.Name,
                OpportunityType = opportunity.OpportunityType,
                IsArchived = opportunity.IsArchived
            })
                        .ToList()));
        }
Пример #3
0
        // [Authorize(oAppConst.AccessPolicies.LevelTwo)] /// Done
        public async Task <IActionResult> Get(
            int selectedPage,
            int maxNumberPerItemsPage,
            int filterProductStoreId,
            string filterProductCategory,
            string searchValue       = "",
            string filterProductUnit = "",
            string filterStatus      = "",
            bool isAccendingSort     = true,
            SortByType sortByType    = SortByType.product)
        {
            try
            {
                bool.TryParse(filterStatus, out bool boolFilterStatus);
                int.TryParse(filterProductCategory, out int filterProductCategoryId);
                ProductUnitType productUnitType = ProductUnitType.Grams;
                switch (filterProductUnit)
                {
                case nameof(ProductUnitType.Grams):
                    productUnitType = ProductUnitType.Grams;
                    break;

                case nameof(ProductUnitType.Kg):
                    productUnitType = ProductUnitType.Kg;
                    break;

                case nameof(ProductUnitType.PerItem):
                    productUnitType = ProductUnitType.PerItem;
                    break;

                default:
                    filterProductUnit = oAppConst.GetAllRecords;
                    break;
                }
                int totalCount = await DbContext.StoreProducts
                                 .Where(sp => filterProductStoreId.Equals(oAppConst.GetAllRecords)?true : sp.Store.Id == filterProductStoreId)
                                 .Where(sp => filterProductUnit.Equals(oAppConst.GetAllRecords) ? true : sp.Product.Unit == productUnitType)
                                 .Where(sp => filterProductCategory.Equals(oAppConst.GetAllRecords) ? true : sp.Product.Category.Id == filterProductCategoryId)
                                 .CountAsync(sp => searchValue.Equals(oAppConst.GetAllRecords) ? true : (sp.Product.Name.Contains(searchValue) || sp.Product.Id.ToString().Contains(searchValue)))
                                 .ConfigureAwait(false);

                /// Include the necessary properties
                IIncludableQueryable <oStoreProduct, oCategory> product = DbContext.StoreProducts
                                                                          .Include(sp => sp.Store)
                                                                          .Include(sp => sp.Product)
                                                                          .ThenInclude(p => p.Category);

                IQueryable sortedList;
                if (isAccendingSort)
                {
                    sortedList = sortByType switch
                    {
                        SortByType.category => product.OrderBy(sp => sp.Product.Category.Name),
                        SortByType.price => product.OrderBy(sp => sp.Product.Price),
                        SortByType.unit => product.OrderBy(sp => sp.Product.Unit),
                        SortByType.unitQuantity => product.OrderBy(sp => sp.Product.UnitQuantity),
                        SortByType.status => product.OrderBy(sp => sp.Status),
                        _ => product.OrderBy(sp => sp.Product.Name),
                    }
                }
                ;
                else
                {
                    sortedList = sortByType switch
                    {
                        SortByType.category => product.OrderByDescending(sp => sp.Product.Category.Name),
                        SortByType.price => product.OrderByDescending(sp => sp.Product.Price),
                        SortByType.unit => product.OrderByDescending(sp => sp.Product.Unit),
                        SortByType.unitQuantity => product.OrderByDescending(sp => sp.Product.UnitQuantity),
                        SortByType.status => product.OrderByDescending(sp => sp.Status),
                        _ => product.OrderByDescending(sp => sp.Product.Name),
                    }
                };

                List <oStoreProduct> list = await product
                                            .Where(sp => filterProductStoreId.Equals(oAppConst.GetAllRecords)?true : sp.Store.Id == filterProductStoreId)
                                            .Where(sp => filterProductUnit.Equals(oAppConst.GetAllRecords) ? true : sp.Product.Unit == productUnitType)
                                            .Where(sp => filterProductCategory.Equals(oAppConst.GetAllRecords) ? true : sp.Product.Category.Id == filterProductCategoryId)
                                            .Where(sp => searchValue.Equals(oAppConst.GetAllRecords) ? true : (sp.Product.Name.Contains(searchValue) || sp.Product.Id.ToString().Contains(searchValue)))
                                            .Skip((selectedPage - 1) * maxNumberPerItemsPage)
                                            .Take(maxNumberPerItemsPage)
                                            .ToListAsync()
                                            .ConfigureAwait(false);


                //int totalCount = await DbContext.Products
                //    .Where(c => filterProductUnit.Equals(oAppConst.GetAllRecords) ? true : c.Unit == productUnitType)
                //    .Where(c => filterProductCategory.Equals(oAppConst.GetAllRecords) ? true : c.Category.Id == filterProductCategoryId)
                //    .CountAsync(c => searchValue.Equals(oAppConst.GetAllRecords) ? true : c.Name.Contains(searchValue))
                //    .ConfigureAwait(false);

                //List<oProduct> list = await DbContext.Products
                //    .OrderBy(c => c.Name)
                //    .Where(c => filterProductUnit.Equals(oAppConst.GetAllRecords) ? true : c.Unit == productUnitType)
                //    .Where(c => filterProductCategory.Equals(oAppConst.GetAllRecords) ? true : c.Category.Id == filterProductCategoryId)
                //    .Include(t => t.StoreProducts)
                //    .Skip((selectedPage - 1) * maxNumberPerItemsPage)
                //    .Take(maxNumberPerItemsPage)
                //    .ToListAsync()
                //    .ConfigureAwait(false);
                //foreach (oProduct product in list)
                //{
                //    product.StoreProducts = product.StoreProducts.Where(t => t.StoreId == filterProductStoreId).ToList();
                //}
                /// return the list of Categories
                return(Ok(new { list, totalCount }));
            }
Пример #4
0
 public IEnumerable <AuditHeader> GetMany() => _records.OrderByDescending(r => r.Timestamp);