public async Task <IViewComponentResult> InvokeAsync()
        {
            var userId = UserClaimsPrincipal.FindFirstValue(ClaimTypes.NameIdentifier);
            var user   = await this.users.ByIdAsync <UserNavServiceModel>(userId);

            return(View(user));
        }
        public async Task <IViewComponentResult> InvokeAsync()
        {
            var userID = UserClaimsPrincipal.FindFirstValue(ClaimTypes.NameIdentifier);

            var currentUser = await this.service.GetUserAsync(userID);

            bool isChangedPass = currentUser.FirstLog == true;

            return(View(isChangedPass));
        }
        public async Task <IViewComponentResult> InvokeAsync()
        {
            var userID = UserClaimsPrincipal.FindFirstValue(ClaimTypes.NameIdentifier);

            var currentUser = await this.accountsService.GetUserAsync(userID);

            bool exists = currentUser != null;

            return(View(exists));
        }
Esempio n. 4
0
        public async Task <IViewComponentResult> InvokeAsync()
        {
            var userID = UserClaimsPrincipal.FindFirstValue(ClaimTypes.NameIdentifier);

            var currentUser = await this.accountsService.GetUserAsync(userID);

            bool isExpired = currentUser.Expired == null || currentUser.Expired < DateTime.Now;

            return(View(isExpired));
        }
Esempio n. 5
0
        //此方法由视图组件调用
        public IViewComponentResult Invoke()
        {
            ViewBag.CurrentUser = UserClaimsPrincipal.FindFirstValue(ClaimTypes.Name);
            string roleKeys = UserClaimsPrincipal.FindFirstValue(ClaimTypes.Role);
            //缓存权限集合
            var dtos = appCache.GetCacheAsync <PermissionDto>(roleKeys, async() =>
            {
                var model = await roleService.SingleAsync(
                    express: inf => inf.Code.Contains(roleKeys),
                    include: inf => inf.Include(r => r.RoleAuthorizes).ThenInclude(p => p.PermissionInformation));
                return(model.PermssionDtos);
            }).Result;

            return(View(dtos));
        }
Esempio n. 6
0
        public async Task <IViewComponentResult> InvokeAsync()
        {
            List <Product> allProducts = _context.Products.Include(p => p.Brand).ToList <Product>();
            User           user        = await _context.Users.FirstAsync(u => u.Email.Equals(UserClaimsPrincipal.FindFirstValue(ClaimTypes.Email)));

            var productsOrderedByUser = from p in _context.Products.Include(b => b.Brand)
                                        from o in _context.Order.Where(o => o.UserId == user.UserId)
                                        where o.OrderProducts.Any(op => op.ProductId == p.ProductId)
                                        select p;

            if (allProducts.Count() < 3)
            {
                return(await Task.FromResult((IViewComponentResult)View("Default", new List <Product>())));
            }

            if (productsOrderedByUser.Count() == 0 && allProducts.Count() >= 3)
            {
                return(await Task.FromResult((IViewComponentResult)View("Default", allProducts.OrderBy(x => x.ProductPrice).Take(3))));
            }


            double minPrice          = productsOrderedByUser.Min(p => p.ProductPrice);
            double maxPrice          = productsOrderedByUser.Max(p => p.ProductPrice);
            string mostFrequentBrand = productsOrderedByUser.ToList()
                                       .GroupBy(q => q.Brand.BrandName)
                                       .OrderByDescending(gp => gp.Count())
                                       .First()
                                       .Select(g => g.Brand.BrandName).First().ToString();

            List <string> orderedTypes = productsOrderedByUser
                                         .GroupBy(q => q.ProductType)
                                         .Select(p => p.Key).ToList <string>();

            List <Product> recommendedProducts = new List <Product>();

            foreach (Product item in allProducts)
            {
                if (item.ProductPrice >= minPrice &&
                    item.ProductPrice <= maxPrice &&
                    item.Brand.Equals(mostFrequentBrand) &&
                    !orderedTypes.Contains(item.ProductType))
                {
                    recommendedProducts.Add(item);
                    if (recommendedProducts.Count() == 3)
                    {
                        return(await Task.FromResult((IViewComponentResult)View("Default", recommendedProducts)));
                    }
                }
            }

            foreach (Product item in allProducts)
            {
                if (item.Brand.Equals(mostFrequentBrand) &&
                    !orderedTypes.Contains(item.ProductType) &&
                    !recommendedProducts.Contains(item) &&
                    !productsOrderedByUser.Contains(item))
                {
                    recommendedProducts.Add(item);
                    if (recommendedProducts.Count() == 3)
                    {
                        return(await Task.FromResult((IViewComponentResult)View("Default", recommendedProducts)));
                    }
                }
            }


            if (recommendedProducts.Count() < 3)
            {
                foreach (Product item in allProducts)
                {
                    if (!orderedTypes.Contains(item.ProductType) &&
                        !recommendedProducts.Contains(item) &&
                        !productsOrderedByUser.Contains(item))
                    {
                        recommendedProducts.Add(item);
                        if (recommendedProducts.Count() == 3)
                        {
                            return(await Task.FromResult((IViewComponentResult)View("Default", recommendedProducts)));
                        }
                    }
                }

                foreach (Product item in allProducts)
                {
                    if (!recommendedProducts.Contains(item) &&
                        !productsOrderedByUser.Contains(item) &&
                        item.Brand.Equals(mostFrequentBrand))
                    {
                        recommendedProducts.Add(item);
                        if (recommendedProducts.Count() == 3)
                        {
                            return(await Task.FromResult((IViewComponentResult)View("Default", recommendedProducts)));
                        }
                    }
                }

                foreach (Product item in allProducts)
                {
                    if (!recommendedProducts.Contains(item) &&
                        !productsOrderedByUser.Contains(item))
                    {
                        recommendedProducts.Add(item);
                        if (recommendedProducts.Count() == 3)
                        {
                            return(await Task.FromResult((IViewComponentResult)View("Default", recommendedProducts)));
                        }
                    }
                }
            }

            foreach (Product item in allProducts)
            {
                recommendedProducts.Add(item);
                if (recommendedProducts.Count() == 3)
                {
                    return(await Task.FromResult((IViewComponentResult)View("Default", recommendedProducts)));
                }
            }

            return(await Task.FromResult((IViewComponentResult)View("Default", recommendedProducts)));
        }