public async Task <IActionResult> SearchByCategory(string keyword, int page = 1)
        {
            if (keyword == null || keyword.Length < 3 || keyword.Length > 20)
            {
                return(RedirectToAction("Index", "Home"));
            }
            else
            {
                Categor category = (Categor)System.Enum.Parse(typeof(Categor), keyword);

                var result = _context.Adverts.OrderByDescending(x => x.DateStartTime).Where(advert => advert.Category == category);;

                int pageSize = 9;

                var count = await result.CountAsync();

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

                PageViewModel  pageViewModel = new PageViewModel(count, page, pageSize);
                IndexViewModel viewModel     = new IndexViewModel
                {
                    PageViewModel = pageViewModel,
                    Adverts       = items
                };

                ViewBag.keyword = keyword;
                return(View(viewModel));
            }
        }
Пример #2
0
        public static CategorDto FroCategor(this CategorDto dto, Categor a)
        {
            dto.Id    = a.Id;
            dto.Title = a.Title;
            dto.Info  = a.Info;

            return(dto);
        }
Пример #3
0
 public static CategorDto ToCategorDto(this Categor a)
 {
     return(new CategorDto
     {
         Id = a.Id,
         Title = a.Title,
         Info = a.Info
     });
 }
Пример #4
0
        public static Categor ToCategor(this CategorDto dto)
        {
            var cat = new Categor
            {
                Id    = dto.Id,
                Title = dto.Title,
                Info  = dto.Info
            };

            return(cat);
        }
Пример #5
0
        public async Task <IActionResult> Create(ManageCategorsModel model, string returnUrl = null)
        {
            ViewData["ReturnUrl"] = returnUrl;
            if (ModelState.IsValid)
            {
                var elementToAdd = new Categor
                {
                    Name = model.Name
                };
                await _context.Categors.AddAsync(elementToAdd);

                var result = await _context.SaveChangesAsync();

                if (result > 0)
                {
                    return(RedirectToAction("Index"));
                }
            }
            return(View(model));
        }
Пример #6
0
 private void AddCategors(object arg)
 {
     Categors.Add(SelectCategor);
     SelectCategor = new Categor();
     NotifyPropertyChanged("Categors");
 }