private async Task ValidateAndAttachUserToContext(HttpContext context,
                                                          ISecurityTokenProvider securityTokenProvider,
                                                          IMerchantRepository merchantRepository,
                                                          string token)
        {
            try
            {
                var merchantId = securityTokenProvider.ValidateTokenAndExtactIdentity(token);

                // attach user to context on successful jwt validation
                context.Items[Extensions.MerchantContextKey] = await merchantRepository.GetById(merchantId);
            }
            catch
            {
                _log.LogWarning($"Token validation failed IP: {context.GetIPAddress()}");
            }
        }
Ejemplo n.º 2
0
        public async Task <Merchant> GetById(string id)
        {
            var result = await _merchantRepository.GetById(id);

            return(result);
        }
Ejemplo n.º 3
0
 public Merchant GetById(int id)
 {
     return(_merchantRepository.GetById(id));
 }
Ejemplo n.º 4
0
        public IActionResult Index(int?merchId, int?cateId, string search = null, int pageSize = 12, int pageNo = 1)
        {
            var merchants  = new List <Merchant>();
            var categories = new List <Category>();
            var products   = new List <Product>();

            if (search != null)
            {
                search    = search.ToLower();
                merchants = _merchantRepository.GetAll();
                products  = _productRepository.GetByCondition(p => p.Name.ToLower().Contains(search) || p.Description.ToLower().Contains(search));
            }
            else
            {
                if ((!merchId.HasValue && !cateId.HasValue))
                {
                    merchants = _merchantRepository.GetAll();
                    products  = _productRepository.GetAll();
                }
                else if (merchId.HasValue && (!cateId.HasValue))
                {
                    var merchant = _merchantRepository.GetById(merchId.Value);
                    merchants.Add(merchant);
                    foreach (var item in _merchantCategoryRepo.GetCategoriesInMerchant(merchant))
                    {
                        var cate = _categoryRepository.GetById(item);
                        categories.Add(cate);//categories contain products
                    }
                    products = _productRepository.GetProductInMerchant(merchId.Value);
                }
                else if (merchId.HasValue && cateId.HasValue)
                {
                    var merchant = _merchantRepository.GetById(merchId.Value);
                    merchants.Add(merchant);
                    foreach (var item in _merchantCategoryRepo.GetCategoriesInMerchant(merchant))
                    {
                        var cate = _categoryRepository.GetById(item);
                        if (cate.Products != null)
                        {
                            categories.Add(cate); //all category doesn't contain any product
                        }
                    }
                    products = _productRepository.GetProductInCategory(cateId.Value);
                }
            }

            categories = categories.Where(c => c.Products != null).ToList();
            categories.OrderByDescending(c => c.Products.Count);
            var merchantsView  = _mapper.Map <List <MerchantViewModel> >(merchants);
            var categoriesView = _mapper.Map <List <CategoryViewModel> >(categories);
            var productsView   = _mapper.Map <List <ProductViewModel> >(products);
            var pages          = PagingList <ProductViewModel> .Create(productsView, pageNo, pageSize);

            dynamic model = new ExpandoObject();

            model.Merchants  = merchantsView;
            model.Categories = categoriesView;
            model.Products   = productsView;
            model.PageList   = pages;
            return(View(model));
        }