public void GetCountCategories()
        {
            var waitValue            = 2;
            var totalCategoriesCount = _categoryRepository.Count();

            Assert.AreEqual(waitValue, totalCategoriesCount);
        }
Exemplo n.º 2
0
        /// <summary>
        /// 按价格随机筛选一个元素
        /// </summary>
        /// <param name="count">数量</param>
        /// <param name="type">广告类型</param>
        /// <param name="cid">分类id</param>
        /// <returns></returns>
        public List <Advertisement> GetsByWeightedPrice(int count, AdvertiseType type, IPLocation ipinfo, int?cid = null)
        {
            var(location, _, _) = ipinfo;
            return(CacheManager.GetOrAdd($"Advertisement:{location.Crc32()}:{type}:{count}-{cid}", _ =>
            {
                var atype = type.ToString("D");
                Expression <Func <Advertisement, bool> > where = a => a.Types.Contains(atype) && a.Status == Status.Available;
                var catCount = CategoryRepository.Count(_ => true);
                where = where.And(a => a.RegionMode == RegionLimitMode.All || (a.RegionMode == RegionLimitMode.AllowRegion ? Regex.IsMatch(location, a.Regions) : !Regex.IsMatch(location, a.Regions)));
                if (cid.HasValue)
                {
                    var scid = cid.ToString();
                    if (Any(a => a.CategoryIds.Contains(scid)))
                    {
                        where = where.And(a => a.CategoryIds.Contains(scid) || string.IsNullOrEmpty(a.CategoryIds));
                    }
                }

                var list = GetQuery(where).OrderBy(a => - Math.Log(DataContext.Random()) / ((double)a.Price / a.Types.Length * catCount / (string.IsNullOrEmpty(a.CategoryIds) ? catCount : (a.CategoryIds.Length + 1)))).Take(count).ToList();
                var ids = list.Select(a => a.Id).ToArray();
                GetQuery(a => ids.Contains(a.Id)).UpdateFromQuery(a => new Advertisement()
                {
                    DisplayCount = a.DisplayCount + 1
                });

                return list;
            }));
        }
        public void Category_Repo_Has_List()
        {
            var result   = underTest.Count();
            int expected = 0;

            Assert.True(result > expected);
        }
Exemplo n.º 4
0
 public ListModel <Category> List([FromBody] ListQuery listQuery)
 {
     return(new ListModel <Category>
     {
         List = _repository.List(listQuery),
         Count = _repository.Count(listQuery)
     });
 }
Exemplo n.º 5
0
        public ActionResult Index(string Search, int?page)

        {
            using (var session = _dbFactory.Create <IAppSession>())
            {
                ViewBag.count = _categoryRepository.Count(session);
                int pageSize   = 10;
                int pageNumber = (page ?? 1);
                if (Search != null)
                {
                    return(View("Index", this._categoryRepository.Searching(Search).ToPagedList(pageNumber, pageSize)));
                }
                else
                {
                    return(View("Index", this._categoryRepository.GetAll(session).ToPagedList(pageNumber, pageSize)));
                }
            }
        }
Exemplo n.º 6
0
 public static void Search()
 {
     while (true)
     {
         Console.Clear();
         CategoriesList.Show();
         Console.Write("Введите номер категории: ");
         categoryNumberString = Console.ReadLine();
         categoryNumberString = categoryNumberString.ExtractOnlyDigits();
         if (categoryNumberString.IsDigits() == true)
         {
             Int32.TryParse(categoryNumberString, out categoryNumber);
             categoryRepository = new CategoryRepository();
             categoriesQuantity = categoryRepository.Count();
             if (categoryNumber > 0 && categoryNumber <= categoriesQuantity)
             {
                 Console.Clear();
                 if (ItemsList.ShowAllItemsByCategory(categoryNumber) == true)
                 {
                     Console.Write("Введите номер товара: ");
                     itemNumberString = Console.ReadLine();
                     itemNumberString = itemNumberString.ExtractOnlyDigits();
                     if (itemNumberString.IsDigits() == true)
                     {
                         Int32.TryParse(itemNumberString, out itemNumber);
                         itemRepository = new ItemRepository();
                         itemsQuantity  = itemRepository.Count();
                         if (itemNumber > 0 && itemNumber <= itemsQuantity)
                         {
                             Console.Clear();
                             ItemsList.ShowItemDetails(itemNumber);
                             Console.ReadKey();
                         }
                     }
                 }
                 else
                 {
                     Console.ReadKey();
                 }
             }
         }
     }
 }
Exemplo n.º 7
0
 public long Count(bool isActive, string keyword)
 {
     return(_entityRepository.Count(isActive, keyword));
 }