public async Task <IActionResult> Index(string searchString, SortState sortOrder = SortState.NameAsc)
        {
            IQueryable <Item> items = db.Items;

            if (!String.IsNullOrEmpty(searchString))
            {
                items = items.Where(s => s.Name.Contains(searchString));
            }

            items = sortOrder switch
            {
                SortState.NameDesc => items.OrderByDescending(s => s.Name),
                SortState.CostAsc => items.OrderBy(s => s.Cost),
                SortState.CostDesc => items.OrderByDescending(s => s.Cost),
                SortState.CompanyAsc => items.OrderBy(s => s.Company),
                SortState.CompanyDesc => items.OrderByDescending(s => s.Company),
                _ => items.OrderBy(s => s.Name),
            };

            IndexViewModel viewModel = new IndexViewModel
            {
                Items         = await items.AsNoTracking().ToListAsync(),
                SortViewModel = new SortViewModel(sortOrder)
            };

            return(View(viewModel));
        }
Exemple #2
0
        // GET: Suppliers
        public async Task <IActionResult> Index(SortState sortState = SortState.CountryAsc)
        {
            IQueryable <Supplier> clothings = _context.Suppliers;

            ViewData["MaterialSort"] = sortState == SortState.MaterialAsc ? SortState.MaterialDesc : SortState.MaterialAsc;
            ViewData["NameSort"]     = sortState == SortState.NameAsc ? SortState.NameDesc : SortState.NameAsc;
            ViewData["CostSort"]     = sortState == SortState.CostAsc ? SortState.CostDesc : SortState.CostAsc;
            ViewData["CountrySort"]  = sortState == SortState.CountryAsc ? SortState.CountryDesc : SortState.CountryAsc;
            ViewData["PhoneSort"]    = sortState == SortState.PhoneAsc ? SortState.PhoneDesc : SortState.PhoneAsc;

            clothings = sortState switch
            {
                SortState.MaterialDesc => clothings.OrderByDescending(x => x.Material),
                SortState.MaterialAsc => clothings.OrderBy(x => x.Material),
                SortState.CountryAsc => clothings.OrderBy(x => x.Country),
                SortState.CountryDesc => clothings.OrderByDescending(x => x.Country),
                SortState.NameDesc => clothings.OrderByDescending(x => x.Name),
                SortState.NameAsc => clothings.OrderBy(x => x.Name),
                SortState.CostAsc => clothings.OrderBy(x => x.Cost),
                SortState.CostDesc => clothings.OrderByDescending(x => x.Cost),
                SortState.PhoneDesc => clothings.OrderByDescending(x => x.PhoneNumber),
                SortState.PhoneAsc => clothings.OrderBy(x => x.PhoneNumber),
                _ => throw new NotImplementedException()
            };
            return(View(await clothings.AsNoTracking().ToListAsync()));
        }
Exemple #3
0
        public async Task <IActionResult> ViewVehicles(SortState sortOrder = SortState.DefaultByID)
        {
            ViewData["ModelName"] = sortOrder == SortState.ModelNameAsc ? SortState.ModelNameDesc : SortState.ModelNameAsc;
            ViewData["Mileage"]   = sortOrder == SortState.MileageAsc ? SortState.MileageDesc : SortState.MileageAsc;
            ViewData["TypeName"]  = sortOrder == SortState.TypeNameAsc ? SortState.TypeNameDesc : SortState.TypeNameAsc;

            var vehicleDtos = await db.GetAll();

            var mapper = new MapperConfiguration(cfg => { cfg.CreateMap <VehicleDto, VehicleViewModel>().ForMember(dest => dest.TypeName, act => act.MapFrom(src => src.Type.TypeName)); }).CreateMapper();

            vehicleDtos = sortOrder switch
            {
                SortState.ModelNameAsc => vehicleDtos.OrderBy(v => v.ModelName),
                SortState.ModelNameDesc => vehicleDtos.OrderByDescending(v => v.ModelName),
                SortState.TypeNameAsc => vehicleDtos.OrderBy(v => v.Type.TypeName),
                SortState.TypeNameDesc => vehicleDtos.OrderByDescending(v => v.Type.TypeName),
                SortState.MileageAsc => vehicleDtos.OrderBy(v => v.Mileage),
                SortState.MileageDesc => vehicleDtos.OrderByDescending(v => v.Mileage),
                _ => vehicleDtos.OrderBy(v => v.Id)
            };

            var vehicles = mapper.Map <IEnumerable <VehicleDto>, List <VehicleViewModel> >(vehicleDtos);

            return(View(vehicles));
        }
Exemple #4
0
        public WebAPI.DTO.IPagedResponse <FavoriteDTO> GetFavorites(int page, SortState sortOrder)
        {
            int pageSize       = 8;
            var favorites      = favoriteRepository.GetAllFavorites();
            var count          = favorites.Count();
            var pageNumber     = (int)Math.Ceiling(count / (double)pageSize);
            var favoriteSerial = mapper.Map <IEnumerable <FavoriteDTO> >(favorites.Where(s => s.ContentType == ContentType.Serial).Select(i => (_serialRepository.GetSerialById(i.ContentId))));
            var favoriteMovie  = mapper.Map <IEnumerable <FavoriteDTO> >(favorites.Where(s => s.ContentType == ContentType.Movie).Select(i => (_movieRepository.GetMovieById(i.ContentId))));
            IEnumerable <FavoriteDTO> union = favoriteSerial.Union(favoriteMovie);

            union = sortOrder switch
            {
                SortState.NameDesc => union.OrderByDescending(s => s.Name),
                SortState.RatingAsc => union.OrderBy(s => s.Rating),
                SortState.RatingDesc => union.OrderByDescending(s => s.Rating),
                SortState.YearAsc => union.OrderBy(s => s.Year),
                SortState.YearDesc => union.OrderByDescending(s => s.Year),
                _ => union.OrderBy(s => s.Name),
            };
            var items = union.Skip((page - 1) * pageSize).Take(pageSize).ToList();

            WebAPI.DTO.IPagedResponse <FavoriteDTO> pagedResponse = new WebAPI.DTO.IPagedResponse <FavoriteDTO>
            {
                PageNumber = pageNumber,
                PageSize   = pageSize,
                TotalCount = count,
                Data       = items
            };
            return(pagedResponse);
        }
Exemple #5
0
        public IActionResult Index(SortState sortOrder, string searchString)
        {
            var contactsDto = db.Contacts
                              .Select(c => c.ToDto())
                              .ToList()
                              .AsQueryable();

            ViewData["SearchString"]    = searchString;
            ViewData["NameSort"]        = sortOrder == SortState.NameAscending ? SortState.NameDescending : SortState.NameAscending;
            ViewData["LastNameSort"]    = sortOrder == SortState.LastNameAscending ? SortState.LastNameDescending : SortState.LastNameAscending;
            ViewData["PhoneNumberSort"] = sortOrder == SortState.PhoneNumberAscending ? SortState.PhoneNumberDescending : SortState.PhoneNumberAscending;

            contactsDto = sortOrder switch
            {
                SortState.NameDescending => contactsDto.OrderByDescending(c => c.Name),
                SortState.LastNameAscending => contactsDto.OrderBy(c => c.LastName),
                SortState.LastNameDescending => contactsDto.OrderByDescending(c => c.LastName),
                SortState.PhoneNumberAscending => contactsDto.OrderBy(c => c.PhoneNumber),
                SortState.PhoneNumberDescending => contactsDto.OrderByDescending(c => c.PhoneNumber),
                _ => contactsDto.OrderBy(c => c.Name),
            };

            if (searchString != null)
            {
                contactsDto = contactsDto
                              .Select(n => n)
                              .Where(c => (c.Name.Contains(searchString) || c.LastName.Contains(searchString) || c.PhoneNumber.Contains(searchString)));
            }

            return(View(contactsDto));
        }
        // GET: Customers
        public async Task <IActionResult> Index(string searchString, SortState sortOrder = SortState.LastNameAsc)
        {
            var customers = from c in await _customers.GetAllAsync()
                            select c;

            ViewData["CurrentFilter"] = searchString;
            if (!String.IsNullOrEmpty(searchString))
            {
                customers = customers.Where(s => s.LastName.Contains(searchString) ||
                                            s.FirstName.Contains(searchString));
            }

            ViewData["LastNameSort"] =
                sortOrder == SortState.LastNameAsc ? SortState.LastNameDesc : SortState.LastNameAsc;
            ViewData["AddressSort"] = sortOrder == SortState.AddressAsc ? SortState.AddressDesc : SortState.AddressAsc;

            customers = sortOrder switch
            {
                SortState.LastNameDesc => customers.OrderByDescending(c => c.LastName),
                SortState.AddressAsc => customers.OrderBy(c => c.Address),
                SortState.AddressDesc => customers.OrderByDescending(c => c.Address),
                _ => customers.OrderBy(c => c.LastName),
            };
            return(View(customers));
        }
Exemple #7
0
 private void Sort(SortState sortOrder)
 {
     Users = sortOrder switch
     {
         SortState.NameDesc => Users.OrderByDescending(user => user.Fullname),
         SortState.UserLoginAsc => Users.OrderBy(user => user.Login),
         SortState.UserLoginDesc => Users.OrderByDescending(user => user.Login),
         _ => Users.OrderBy(user => user.Fullname),
     };
     SortModel = new SortViewModel(sortOrder);
 }
Exemple #8
0
 private void Sort(SortState sortOrder)
 {
     Beers = sortOrder switch
     {
         SortState.NameDesc => Beers.OrderByDescending(beer => beer.Name),
         SortState.BeerPriceAsc => Beers.OrderBy(beer => beer.Price),
         SortState.BeerPriceDesc => Beers.OrderByDescending(beer => beer.Price),
         _ => Beers.OrderBy(beer => beer.Name),
     };
     SortModel = new SortViewModel(sortOrder);
 }
Exemple #9
0
 private static void SortProfiles(ref IEnumerable <ProfileViewModel> profileViewModels, SortState sortOrder)
 {
     profileViewModels = sortOrder switch
     {
         SortState.LastNameDesc => profileViewModels.OrderByDescending(s => s.LastName),
         SortState.BirthdayAsc => profileViewModels.OrderBy(s => s.Birthday),
         SortState.FirstNameDesc => profileViewModels.OrderByDescending(s => s.FirstName),
         SortState.FirstNameAsc => profileViewModels.OrderBy(s => s.FirstName),
         SortState.BirthdayDesc => profileViewModels.OrderByDescending(s => s.Birthday),
         _ => profileViewModels.OrderBy(s => s.LastName),
     };
 }
Exemple #10
0
        public async Task <IActionResult> Index(string searchString, SortState sortOrder = SortState.DateTimeDesc)
        {
            string userId = _userManager.GetUserId(User);

            List <IncomeCategory> incomeCategory = await _balanceService.GetUserIncomeCategories(userId);

            List <ExpenseCategory> expenseCategory = await _balanceService.GetUserExpenseCategories(userId);

            IEnumerable <Currency> currency = await _balanceService.GetCurrency();

            SelectList currencySelectList = new SelectList(currency, "Id", "Code");

            CreateIncomeViewModel createIncomeViewModel = new CreateIncomeViewModel
            {
                Categories = new SelectList(incomeCategory, "Id", "Title"),
                Currencies = currencySelectList
            };

            CreateExpenseViewModel createExpenseViewModel = new CreateExpenseViewModel
            {
                Categories = new SelectList(expenseCategory, "Id", "Title"),
                Currencies = currencySelectList
            };

            IReadOnlyList <Income> incomes = await _balanceService.GetUserIncomes(userId, searchString);

            IReadOnlyList <Expense> expense = await _balanceService.GetUserExpenses(userId, searchString);

            var operations = _mapper.Map <IReadOnlyList <Income>, List <OperationViewModel> >(incomes);

            operations.AddRange(_mapper.Map <IReadOnlyList <Expense>, List <OperationViewModel> >(expense));

            operations = sortOrder switch
            {
                SortState.DateTimeDesc => operations.OrderByDescending(s => s.Date).ToList(),
                SortState.CategoryAsc => operations.OrderBy(s => s.Category).ToList(),
                SortState.CategoryDesc => operations.OrderByDescending(s => s.Category).ToList(),
                SortState.SumAsc => operations.OrderBy(s => s.SumByn).ToList(),
                SortState.SumDesc => operations.OrderByDescending(s => s.SumByn).ToList(),
                _ => operations.OrderBy(s => s.Date).ToList(),
            };

            BalanceViewModel balanceViewModel = new BalanceViewModel
            {
                CreateIncome   = createIncomeViewModel,
                CreateExpense  = createExpenseViewModel,
                Operations     = operations,
                SearchString   = searchString,
                SortOperations = new SortOperationsViewModel(sortOrder)
            };

            return(View(balanceViewModel));
        }
        public ViewResult Index(string currentFilter, string searchString, int?page, string gqwGroup, SortState sortOrder = SortState.NameAsc)
        {
            ViewBag.Message = "Список выпускных квалификационных работ";

            IQueryable <Gqw> gqws = university.Gqw
                                    .Include(x => x.Graduate)
                                    .Include(y => y.Reviewer)
                                    .Include(z => z.Teacher)
                                    .Include(w => w.Sec);

            ViewData["NameSort"] = sortOrder == SortState.NameAsc ? SortState.NameDesc : SortState.NameAsc;
            ViewData["ArchSort"] = sortOrder == SortState.ArchAsc ? SortState.ArchDesc : SortState.ArchAsc;


            if (searchString != null)
            {
                page = 1;
            }
            else
            {
                searchString = currentFilter;
            }

            ViewBag.CurrentFilter = searchString;

            if (!String.IsNullOrEmpty(searchString))
            {
                gqws = gqws.Where(s => s.Graduate.LastName.Contains(searchString) ||
                                  s.Graduate.FirstName.Contains(searchString) ||
                                  s.Graduate.Patronymic.Contains(searchString));
            }

            if (!String.IsNullOrEmpty(gqwGroup))
            {
                gqws = gqws.Where(x => x.Graduate.Group.Name == gqwGroup);
            }

            gqws = sortOrder switch
            {
                SortState.NameDesc => gqws.OrderByDescending(s => s.Graduate.LastName),
                SortState.ArchAsc => gqws.OrderBy(s => s.IsArchived),
                SortState.ArchDesc => gqws.OrderByDescending(s => s.IsArchived),
                _ => gqws.OrderBy(s => s.Graduate.LastName),
            };

            int pageSize   = 10;
            int pageNumber = (page ?? 1);

            return(View(gqws.ToPagedList(pageNumber, pageSize)));
        }
        public async Task <IActionResult> Sort(SortState sortOrder = SortState.NameAsc)
        {
            IQueryable <GymVisitor> users = db.GymVisitors.Where(x => x.CoachId != null);

            ViewData["NameSort"] = sortOrder == SortState.NameAsc ? SortState.NameDesc : SortState.NameAsc;


            users = sortOrder switch
            {
                SortState.NameDesc => users.OrderByDescending(s => s.LastName),
                SortState.CompanyAsc => users.OrderBy(s => s.LastName),
                SortState.CompanyDesc => users.OrderByDescending(s => s.LastName),
                _ => users.OrderBy(s => s.LastName),
            };
            return(View(await users.AsNoTracking().ToListAsync()));
        }
        public async Task <IActionResult> SecureSys(SortState sortOrder = SortState.NameAsc)
        {
            IQueryable <Product> products = db.Products;

            ViewData["NameSort"]  = sortOrder == SortState.NameAsc ? SortState.NameDesc : SortState.NameAsc;
            ViewData["PriceSort"] = sortOrder == SortState.PriceAsc ? SortState.PriceDesc : SortState.PriceAsc;

            products = sortOrder switch
            {
                SortState.NameDesc => products.OrderByDescending(s => s.Name),
                SortState.PriceAsc => products.OrderBy(s => s.Price),
                SortState.PriceDesc => products.OrderByDescending(s => s.Price),
                _ => products.OrderBy(s => s.Name)
            };
            return(View(await products.AsNoTracking().ToListAsync()));
        }
Exemple #14
0
 public List<UserProfileViewModel> SortUserProfileViewModel(List<UserProfileViewModel> model, SortState sortOrder)
 {
     model = sortOrder switch
     {
         SortState.NameDesc => model.OrderByDescending(s => s.Name).ToList(),
         SortState.DescriptionAsc => model.OrderBy(s => s.Description).ToList(),
         SortState.DescriptionDesc => model.OrderByDescending(s => s.Description).ToList(),
         SortState.GenreAsc => model.OrderBy(s => s.Genre).ToList(),
         SortState.GenreDesc => model.OrderByDescending(s => s.Genre).ToList(),
         SortState.DateOfCreationAsc => model.OrderBy(s => s.DateOfCreation).ToList(),
         SortState.DateOfCreationDesc => model.OrderByDescending(s => s.DateOfCreation).ToList(),
         SortState.NumberOfChaptersAsc => model.OrderBy(s => s.NumberOfChapters).ToList(),
         SortState.NumberOfChaptersDesc => model.OrderByDescending(s => s.NumberOfChapters).ToList(),
         _ => model.OrderBy(s => s.Name).ToList()
     };
     return model;
 }
Exemple #15
0
        public List <RDnDO2Model> GetDo2s(DateTime dt, SortState sortOrder)
        {
            if (dt == null)
            {
                dt = DateTime.Now;
            }

            var sql =
                @"SELECT RD.ID as RdId, DRD.ID as DrdId, DO.ID as Do2Id,
    A.FULL_AWB_NUMBER as FullAwbNumber, A.TECHNOLOGY as AwbTech, 
    RD.OPERATION_DATE as RdDate, ABS(RD.PIECES) as Pieces, ABS(RD.WEIGHT) as Weight
FROM DOCUSR.DOC_AWB_RECEIPT_DISPATCH RD
    INNER JOIN DOCUSR.DOC_AWB A ON A.ID = RD.DOC_ID
    LEFT JOIN DOCUSR.DOC_DO_RECEIPT_DISPATCH DRD ON DRD.AWB_REC_DISP_ID = RD.ID
    LEFT JOIN DOCUSR.DOC_DO_DO2 DO ON DO.REC_DISP_ID = DRD.ID
WHERE 
    A.TECHNOLOGY IN ('IMP', 'TRN')	
    AND A.IS_CUSTOMS_CONTROLLED = 1 
    AND A.IS_PREVENT_SVH_STORAGE = 0
    AND TO_CHAR(RD.OPERATION_DATE, 'DD-MM-YY') = :strDt
    AND RD.STATUS = 'Approved'
    AND RD.OPERATION_TYPE IN ('CLNT', 'EXP', 'DWW', 'DAA', 'DREX', 'ZTK', 'ZTKLOCK')
    AND DO.ID IS NULL ";

            using (var db = new OracleConnection(connectionString))
            {
                //var do1Id = "DO1-938595";
                //var res = db.Query<Do2Model>("SELECT ID, DOC_ID, STATUS, DO2_NUMBER as Do2Number, DO2_DATE FROM DOCUSR.DOC_DO_DO2 WHERE DOC_ID = :do1Id", new { do1Id }).ToList();

                var strDt = dt.ToString("dd-MM-yy");
                //var strDt = "22-04-21";

                //var res = db.Query<RDnDO2Model>(sql, new { strDt }).OrderBy(x => x.FullAwbNumber).ToList();
                var res = db.Query <RDnDO2Model>(sql, new { strDt });

                res = sortOrder switch
                {
                    SortState.AwbNumberDesc => res.OrderByDescending(x => x.FullAwbNumber),
                    SortState.AwbTechAsc => res.OrderBy(x => x.AwbTech),
                    SortState.AwbTechDesc => res.OrderByDescending(x => x.AwbTech),
                    _ => res.OrderBy(x => x.FullAwbNumber), // AwbNumberAsc
                };
                return(res.ToList());
            }
        }
        public IActionResult Index(SortState sortOrder = SortState.DateOrderAsc)
        {
            _logger.LogInformation($"{DateTime.Now.ToString()}: Processing request Order/Index");

            if (User.Identity.IsAuthenticated)
            {
                try
                {
                    string currentUserId = this.User.FindFirst(ClaimTypes.NameIdentifier).Value;

                    IEnumerable <OrderDTO> orderDTOs = _orderService.GetOrders(currentUserId);
                    var mapper = new MapperConfiguration(cfg => cfg.CreateMap <OrderDTO, OrderViewModel>()).CreateMapper();
                    var orders = mapper.Map <IEnumerable <OrderDTO>, List <OrderViewModel> >(orderDTOs);

                    ViewData["IdSort"]        = sortOrder == SortState.IdAsc ? SortState.IdDesc : SortState.IdAsc;
                    ViewData["DateSort"]      = sortOrder == SortState.DateOrderAsc ? SortState.DateOrderDesc : SortState.DateOrderAsc;
                    ViewData["FullPriceSort"] = sortOrder == SortState.FullPriceAsc ? SortState.FullPriceDesc : SortState.FullPriceAsc;
                    ViewData["CountDishSort"] = sortOrder == SortState.CountDishAsc ? SortState.CountDishDesc : SortState.CountDishAsc;

                    orders = sortOrder switch
                    {
                        SortState.IdDesc => orders.OrderByDescending(s => s.Id).ToList(),
                        SortState.DateOrderAsc => orders.OrderBy(s => s.DateOrder).ToList(),
                        SortState.DateOrderDesc => orders.OrderByDescending(s => s.DateOrder).ToList(),
                        SortState.FullPriceAsc => orders.OrderBy(s => s.FullPrice).ToList(),
                        SortState.FullPriceDesc => orders.OrderByDescending(s => s.FullPrice).ToList(),
                        SortState.CountDishAsc => orders.OrderBy(s => s.CountDish).ToList(),
                        SortState.CountDishDesc => orders.OrderByDescending(s => s.CountDish).ToList(),
                        _ => orders.OrderBy(s => s.Id).ToList(),
                    };

                    return(View(orders));
                }
                catch (ValidationException ex)
                {
                    ModelState.AddModelError(ex.Property, ex.Message);
                    _logger.LogError($"{DateTime.Now.ToString()}: {ex.Property}, {ex.Message}");
                }

                return(BadRequest(_sharedLocalizer["BadRequest"]));
            }

            return(RedirectToAction("Login", "Account"));
        }
Exemple #17
0
        public async Task <IActionResult> Index(int?type, string name, int page = 1,
                                                SortState sortOrder             = SortState.NameAsc)
        {
            const int pageSize = 5;

            //фильтрация
            IQueryable <Toy> toys = db.Toys.Include(x => x.Type);

            if (type != null && type != 0)
            {
                toys = toys.Where(p => p.TypeId == type);
            }
            if (!string.IsNullOrEmpty(name))
            {
                toys = toys.Where(p => p.Name.Contains(name));
            }

            // сортировка
            toys = sortOrder switch
            {
                SortState.NameDesc => toys.OrderByDescending(s => s.Name),
                SortState.PriceAsc => toys.OrderBy(s => s.Price),
                SortState.PriceDesc => toys.OrderByDescending(s => s.Price),
                SortState.TypeAsc => toys.OrderBy(s => s.Type.Name),
                SortState.TypeDesc => toys.OrderByDescending(s => s.Type.Name),
                _ => toys.OrderBy(s => s.Name)
            };

            // пагинация
            var count = await toys.CountAsync();

            var items = await toys.Skip((page - 1) *pageSize).Take(pageSize).ToListAsync();

            // формируем модель представления
            var viewModel = new IndexViewModel
            {
                PageViewModel   = new PageViewModel(count, page, pageSize),
                SortViewModel   = new SortViewModel(sortOrder),
                FilterViewModel = new FilterViewModel(db.ToyTypes.ToList(), type, name),
                Toys            = items
            };

            return(View(viewModel));
        }
        public async Task <IActionResult> BooksCollection(string search, SortState sortOrder = SortState.DateDesc, string view = "list", int page = 1)
        {
            ViewData["SearchParam"] = search;
            ViewData["ViewType"]    = view;
            int pageSize             = view == "list" ? 10 : 20;
            IQueryable <Book> source = !string.IsNullOrEmpty(search) ? source = _db.Books
                                                                                .Include(a => a.Author)
                                                                                .Include(a => a.Genre)
                                                                                .Include(a => a.Users)
                                                                                .Include(a => a.Comments)
                                                                                .Where(a => a.Name.Contains(search)) : _db.Books
                                                                                .Include(a => a.Author)
                                                                                .Include(a => a.Genre)
                                                                                .Include(a => a.Users)
                                                                                .Include(a => a.Comments);
            var count = await source.CountAsync();

            var books = await source.Skip((page - 1) *pageSize).Take(pageSize).ToListAsync();

            books = sortOrder switch
            {
                SortState.BookAsc => books.OrderBy(a => a.Name).ToList(),
                SortState.BookDesc => books.OrderByDescending(a => a.Name).ToList(),
                SortState.AuthorAsc => books.OrderBy(a => a.Author.FullName).ToList(),
                SortState.AuthorDesc => books.OrderByDescending(a => a.Author.FullName).ToList(),
                SortState.YearAsc => books.OrderBy(a => a.Year).ToList(),
                SortState.YearDesc => books.OrderByDescending(a => a.Year).ToList(),
                SortState.GenreAsc => books.OrderBy(a => a.Genre.Name).ToList(),
                SortState.GenreDesc => books.OrderByDescending(a => a.Genre.Name).ToList(),
                SortState.DateAsc => books.OrderBy(a => a.AdditionDate).ToList(),
                _ => books.OrderByDescending(a => a.AdditionDate).ToList()
            };

            PageViewModel     pageViewModel = new PageViewModel(count, page, pageSize);
            BookPageViewModel viewModel     = new BookPageViewModel
            {
                PageViewModel = pageViewModel,
                Book          = books,
                SortViewModel = new SortViewModel(sortOrder)
            };

            return(View(viewModel));
        }
        public async Task <IActionResult> Index(SortState sortOrder = SortState.NameAsc)
        {
            IQueryable <Product> products = db.Products.Include(x => x.Device);

            ViewData["NameSort"]       = sortOrder == SortState.NameAsc ? SortState.NameDesc : SortState.NameAsc;
            ViewData["DeviceNameSort"] = sortOrder == SortState.DeviceNAmeAsc ? SortState.DeviceNAmeDesc : SortState.DeviceNAmeAsc;
            ViewData["CountSort"]      = sortOrder == SortState.CountAsc ? SortState.CountDesc : SortState.CountAsc;

            products = sortOrder switch
            {
                SortState.NameDesc => products.OrderByDescending(s => s.Name),
                SortState.CountAsc => products.OrderBy(s => s.Count),
                SortState.CountDesc => products.OrderByDescending(s => s.Count),
                SortState.DeviceNAmeAsc => products.OrderBy(s => s.Device.Name),
                SortState.DeviceNAmeDesc => products.OrderByDescending(s => s.Device.Name),
                _ => products.OrderBy(s => s.Name),
            };
            return(View(await products.AsNoTracking().ToListAsync()));
        }
        public ActionResult Index(int?coach, string name, SortState sortOrder = SortState.NameAsc)
        {
            ViewBag.Title = "Visitors info";
            //IQueryable<GymVisitor> users = db.GymVisitors.Include(p => p.CoachId);
            IQueryable <GymVisitor> users = db.GymVisitors.Where(p => p.CoachId != null);

            ViewData["NameSort"] = sortOrder == SortState.NameAsc ? SortState.NameDesc : SortState.NameAsc;
            users = sortOrder switch
            {
                SortState.NameDesc => users.OrderByDescending(s => s.LastName),
                SortState.CompanyAsc => users.OrderBy(s => s.LastName),
                SortState.CompanyDesc => users.OrderByDescending(s => s.LastName),
                _ => users.OrderBy(s => s.LastName),
            };

            if (coach != null && coach != 0)
            {
                users = users.Where(p => p.CoachId == coach);
            }
            if (!String.IsNullOrEmpty(name))
            {
                users = users.Where(p => p.LastName.Contains(name));
            }

            List <GymCoach> coaches = db.GymCoaches.ToList();

            // устанавливаем начальный элемент, который позволит выбрать всех
            coaches.Insert(0, new GymCoach {
                Id = 0, LastName = "All"
            });


            InfoVIewModel viewModel = new InfoVIewModel
            {
                GymVisitors = users.ToList(),
                Coaches     = new SelectList(coaches, "Id", "LastName"),
                SecondName  = name,
                GymCoaches  = coaches
            };


            return(View(viewModel));
        }
Exemple #21
0
        public async Task <IActionResult> Create(SortState sortState = SortState.MaterialAsc)
        {
            IQueryable <Clothing> clothings = _context.Clothes;

            ViewData["MaterialSort"] = sortState == SortState.MaterialAsc ? SortState.MaterialDesc : SortState.MaterialAsc;
            ViewData["CategorySort"] = sortState == SortState.CategoryAsc ? SortState.CategoryDesc : SortState.CategoryAsc;
            ViewData["CostSort"]     = sortState == SortState.CostAsc ? SortState.CostDesc : SortState.CostAsc;

            clothings = sortState switch
            {
                SortState.MaterialDesc => clothings.OrderByDescending(x => x.Material),
                SortState.MaterialAsc => clothings.OrderBy(x => x.Material),
                SortState.CategoryAsc => clothings.OrderBy(x => x.Category),
                SortState.CategoryDesc => clothings.OrderByDescending(x => x.Category),
                SortState.CostAsc => clothings.OrderBy(x => x.Cost),
                SortState.CostDesc => clothings.OrderByDescending(x => x.Cost),
                _ => throw new NotImplementedException()
            };
            return(View(await clothings.AsNoTracking().ToListAsync()));
        }
Exemple #22
0
        public async Task <IActionResult> Index(string name, int?manufacturer, SortState sortOrder = SortState.NameAsc, int page = 1)
        {
            int pageSize = 4;

            IQueryable <Mobile> songs = db.Mobiles.Include(x => x.Manufacturer);

            if (manufacturer != null && manufacturer != 0)//brand filter
            {
                songs = songs.Where(p => p.ManufacturerId == manufacturer);
            }
            if (!String.IsNullOrEmpty(name))//song name filter
            {
                songs = songs.Where(p => p.Name.Contains(name));
            }

            songs = sortOrder switch
            {
                SortState.NameDes => songs.OrderByDescending(s => s.Name),
                SortState.YearAsc => songs.OrderBy(s => s.Yaer),
                SortState.ManufacturerAsc => songs.OrderBy(s => s.Manufacturer.Name),
                SortState.ManufacturerDes => songs.OrderByDescending(s => s.Manufacturer.Name),
                SortState.DiagonalAsc => songs.OrderBy(s => s.Diagonal),
                SortState.DiagonalDes => songs.OrderByDescending(s => s.Diagonal),
                _ => songs.OrderBy(s => s.Name),
            };

            var count = await songs.CountAsync();

            var items = await songs.Skip((page - 1) *pageSize).Take(pageSize).ToListAsync();

            IndexViewModel viewModel = new IndexViewModel
            {
                PageViewModel   = new PageViewModel(count, page, pageSize),
                SortViewModel   = new SortViewModel(sortOrder),
                FilterViewModel = new FilterViewModel(db.Manufacturers.ToList(), manufacturer, name),
                Mobile          = items
            };

            SetClearance();
            return(View(viewModel));
        }
Exemple #23
0
        public async Task <IActionResult> Index(int?selectID, int?selectNumber, int?selectValue, SortState sortOrder = SortState.IDAsc, int page = 1)
        {
            var data     = _baseService.GetCounters();
            int pageSize = 5;

            if (selectID != null)
            {
                data = data.Where(k => k.ID + 8 == selectID).Select(k => k);
            }
            if (selectNumber != null)
            {
                data = data.Where(k => k.Number == selectNumber).Select(k => k);
            }
            if (selectValue != null)
            {
                data = data.Where(k => k.Value == selectValue).Select(k => k);
            }
            data = sortOrder switch
            {
                SortState.IDDesc => data.OrderByDescending(x => x.ID),
                SortState.NumberAsc => data.OrderBy(x => x.Number),
                SortState.NumberDesc => data.OrderByDescending(x => x.Number),
                SortState.ValueAsc => data.OrderBy(x => x.Value),
                SortState.ValueDesc => data.OrderByDescending(x => x.Value),
                _ => data.OrderBy(x => x.ID),
            };

            var count = await data.CountAsync();

            var items = await data.Skip((page - 1) *pageSize).Take(pageSize).ToListAsync();

            IndexViewModel viewModel = new IndexViewModel
            {
                Counters        = items,
                SortViewModel   = new SortViewModel(sortOrder),
                PageViewModel   = new PageViewModel(count, page, pageSize),
                FilterViewModel = new FilterViewModel(selectID, selectNumber, selectValue)
            };

            return(View(viewModel));
        }
Exemple #24
0
        public async Task <IActionResult> Index(SortState sortOrder = SortState.NameAsc)
        {
            IQueryable <User> users = db.Users.Include(x => x.Company);

            users = sortOrder switch
            {
                SortState.NameDesc => users.OrderByDescending(s => s.Name),
                SortState.AgeAsc => users.OrderBy(s => s.Age),
                SortState.AgeDesc => users.OrderByDescending(s => s.Age),
                SortState.CompanyAsc => users.OrderBy(s => s.Company.Name),
                SortState.CompanyDesc => users.OrderByDescending(s => s.Company.Name),
                _ => users.OrderBy(s => s.Name),
            };
            IndexViewModel viewModel = new IndexViewModel
            {
                Users         = await users.AsNoTracking().ToListAsync(),
                SortViewModel = new SortViewModel(sortOrder)
            };

            return(View(viewModel));
        }
        private IEnumerable <NewsGetDTO> Sort(IEnumerable <NewsGetDTO> newsPerPages, SortState sortState)
        {
            ViewData["RatingSort"] = sortState == SortState.RatinAsc ? SortState.RatingDesc : SortState.RatinAsc;
            newsPerPages           = sortState switch
            {
                SortState.RatingDesc => newsPerPages.OrderByDescending(s => s.Rating),
                SortState.RatinAsc => newsPerPages.OrderBy(s => s.Rating),
                _ => newsPerPages.OrderBy(s => s.Rating),// по умолчанию
            };

            return(newsPerPages);
        }
Exemple #26
0
        public async Task <IActionResult> Index(SortState sortOrder = SortState.IsDoneAsc)
        {
            IQueryable <ItemToDo> item = db.ToDo;

            ViewData["IsDoneSort"] = sortOrder == SortState.IsDoneAsc ? SortState.IsDoneDesc : SortState.IsDoneAsc;

            item = sortOrder switch
            {
                SortState.IsDoneDesc => item.OrderByDescending(s => s.IsDone),
                _ => item.OrderBy(s => s.IsDone),
            };
            return(View(await item.AsNoTracking().ToListAsync()));
        }
Exemple #27
0
        public async Task <IActionResult> Index(SortState sortOrder = SortState.ModifiedDateDesc, int pageNumber = 1)
        {
            IQueryable <Person> users = db.People;

            ViewData["CreateDataSort"]       = sortOrder == SortState.CreateDateAsc ? SortState.CreateDateDesc : SortState.CreateDateAsc;
            ViewData["NameSort"]             = sortOrder == SortState.NameAsc ? SortState.NameDesc : SortState.NameAsc;
            ViewData["CountOfAsparagusSort"] = sortOrder == SortState.CountOfAsparagusAsc ? SortState.CountOfAsparagusDesc : SortState.CountOfAsparagusAsc;
            ViewData["ModifiedDataSort"]     = sortOrder == SortState.ModifiedDateAsc ? SortState.ModifiedDateDesc : SortState.ModifiedDateAsc;

            users = sortOrder switch
            {
                SortState.CreateDateAsc => users.OrderBy(s => s.CreateDate),
                SortState.CreateDateDesc => users.OrderByDescending(s => s.CreateDate),
                SortState.NameDesc => users.OrderByDescending(s => s.Name),
                SortState.NameAsc => users.OrderBy(s => s.Name),
                SortState.CountOfAsparagusAsc => users.OrderBy(s => s.CountOfAsparagus),
                SortState.CountOfAsparagusDesc => users.OrderByDescending(s => s.CountOfAsparagus),
                SortState.ModifiedDateAsc => users.OrderBy(s => s.ModifiedDate),
                _ => users.OrderByDescending(s => s.ModifiedDate),
            };

            return(View(await PaginatedList <Person> .CreateAsync(users.AsNoTracking(), pageNumber, 7)));
        }
        public IActionResult Index(SortState sortOrder = SortState.DateOrderDesc)
        {
            if (User.Identity.IsAuthenticated)
            {
                string currentUserId = GetCurrentUserId();

                IEnumerable <OrderDTO> orderDTOs = _orderService.GetOrders(currentUserId);
                var mapper = new MapperConfiguration(cfg => cfg.CreateMap <OrderDTO, BookViewModel>()).CreateMapper();
                var orders = mapper.Map <IEnumerable <OrderDTO>, List <BookViewModel> >(orderDTOs);

                ViewData["IdSort"]        = sortOrder == SortState.IdAsc ? SortState.IdDesc : SortState.IdAsc;
                ViewData["DateSort"]      = sortOrder == SortState.DateOrderAsc ? SortState.DateOrderDesc : SortState.DateOrderAsc;
                ViewData["FullPriceSort"] = sortOrder == SortState.FullPriceAsc ? SortState.FullPriceDesc : SortState.FullPriceAsc;
                ViewData["CountDishSort"] = sortOrder == SortState.CountBookAsc ? SortState.CountBookDesc : SortState.CountBookAsc;

                orders = sortOrder switch
                {
                    SortState.IdDesc => orders.OrderByDescending(s => s.Id).ToList(),
                    SortState.DateOrderAsc => orders.OrderBy(s => s.DateOrder).ToList(),
                    SortState.DateOrderDesc => orders.OrderByDescending(s => s.DateOrder).ToList(),
                    SortState.FullPriceAsc => orders.OrderBy(s => s.FullPrice).ToList(),
                    SortState.FullPriceDesc => orders.OrderByDescending(s => s.FullPrice).ToList(),
                    SortState.CountBookAsc => orders.OrderBy(s => s.CountBook).ToList(),
                    SortState.CountBookDesc => orders.OrderByDescending(s => s.CountBook).ToList(),
                    _ => orders.OrderBy(s => s.Id).ToList(),
                };

                _loggerService.LogInformation(CONTROLLER_NAME + LoggerConstants.ACTION_INDEX, LoggerConstants.TYPE_GET, "index", currentUserId);

                return(View(orders));
            }

            _loggerService.LogWarning(CONTROLLER_NAME + LoggerConstants.ACTION_INDEX, LoggerConstants.TYPE_GET, LoggerConstants.ERROR_USER_NOT_AUTHENTICATED, null);

            return(RedirectToAction("Login", "Account"));
        }
        // GET: Countries
        public async Task <IActionResult> Index(SortState sortOrder = SortState.NameAsc, string searchString = "")
        {
            IQueryable <Country> countries = _context.country.OrderBy(s => s.name);

            ViewData["NameSort"]      = sortOrder == SortState.NameAsc ? SortState.NameDesc : SortState.NameAsc;
            ViewData["CurrentFilter"] = searchString;

            if (!string.IsNullOrEmpty(searchString))
            {
                countries = countries.Where(s => s.name.StartsWith(searchString));
            }

            countries = sortOrder switch
            {
                SortState.NameDesc => countries.OrderByDescending(s => s.name),
                _ => countries.OrderBy(s => s.name),
            };

            return(View(await countries.AsNoTracking().ToListAsync()));
        }
        // GET: Regions
        public IActionResult Index(bool isReadable, SortState sortOrder = SortState.NameAsc, string searchString = "")
        {
            IQueryable <Region> regions = _context.region.ToList().AsQueryable();

            ViewData["NameSort"]      = sortOrder == SortState.NameAsc ? SortState.NameDesc : SortState.NameAsc;
            ViewData["CurrentFilter"] = searchString;
            ViewData["isReadable"]    = false;

            if (!string.IsNullOrEmpty(searchString))
            {
                regions = regions.Where(s => s.name.StartsWith(searchString));
            }

            regions = sortOrder switch
            {
                SortState.NameDesc => regions.OrderByDescending(s => s.name),
                _ => regions.OrderBy(s => s.name),
            };

            if (isReadable == true)
            {
                ViewData["isReadable"] = true;
                CountryContext countryContext = new CountryContext();
                var            query          = regions.Join(
                    countryContext.country,
                    regions => regions.country_id,
                    country => country.country_id,
                    (regions, country) => new FullRegion
                {
                    region_id = regions.region_id,
                    Country   = country.name,
                    Region    = regions.name
                });
                ViewData["Res"] = query.AsNoTracking().ToList();
                return(View());
            }

            return(View(regions.AsNoTracking().ToList()));
        }