public ActionResult MerchantsPage()
        {
            var model = new MerchantsListViewModel
            {
                CurrentPage  = 1,
                IsFullAccess = this.GetUserRolesPair().HasAccessToFeature(UserFeatureAccess.LykkePayMerchantsFull)
            };

            return(View(model));
        }
Beispiel #2
0
        public async Task <IActionResult> OnGet(int productPage = 1, string searchName = null, string searchCity = null, string searchState = null)
        {
            var user = await GetUser();

            MerchantListVM = new MerchantsListViewModel
            {
                Merchants = await _db.Merchant.Where(x => x.Id == user.MerchantId || user.IsAdmin).ToListAsync()
            };

            var param = new StringBuilder();

            param.Append("/Merchants?productPage=:");
            param.Append("&searchName=");
            if (searchName != null)
            {
                param.Append(searchName);
            }
            param.Append("&searchCity=");
            if (searchCity != null)
            {
                param.Append(searchCity);
            }
            param.Append("&searchState=");
            if (searchState != null)
            {
                param.Append(searchState);
            }

            if (searchName != null)
            {
                MerchantListVM.Merchants = await _db.Merchant
                                           .Where(x => x.Name.ToLower().Contains(searchName.ToLower()) && (user.IsAdmin || x.Id == user.MerchantId)).ToListAsync();
            }
            else
            {
                if (searchCity != null)
                {
                    MerchantListVM.Merchants = await _db.Merchant
                                               .Where(x => x.City.ToLower().Contains(searchCity.ToLower()) && (user.IsAdmin || x.Id == user.MerchantId)).ToListAsync();
                }
                else
                {
                    if (searchState != null)
                    {
                        MerchantListVM.Merchants = await _db.Merchant
                                                   .Where(x => x.State.ToLower().Contains(searchState.ToLower()) && (user.IsAdmin || x.Id == user.MerchantId)).ToListAsync();
                    }
                }
            }

            var count = MerchantListVM.Merchants.Count;

            MerchantListVM.PagingInfo = new PagingInfo
            {
                CurrentPage  = productPage,
                ItemsPerPage = SD.PaginationUsersPageSize,
                TotalItems   = count,
                UrlParam     = param.ToString()
            };

            MerchantListVM.Merchants = MerchantListVM.Merchants.OrderBy(p => p.Name)
                                       .Skip((productPage - 1) * SD.PaginationUsersPageSize)
                                       .Take(SD.PaginationUsersPageSize).ToList();

            return(Page());
        }
        public async Task <ActionResult> MerchantsList(MerchantsListViewModel vm)
        {
            var merchants = await _payMerchantClient.Api.GetAllAsync();

            vm.PageSize = vm.PageSize == 0 ? 10 : vm.PageSize;
            var pagesize = Request.Cookies["PageSize"];

            if (pagesize != null)
            {
                vm.PageSize = Convert.ToInt32(pagesize);
            }
            var list = new List <MerchantModel>(merchants).AsQueryable();

            if (!string.IsNullOrEmpty(vm.SearchValue) && !vm.FilterByEmail)
            {
                list = list.Where(x =>
                                  x.Name.ToLower().Contains(vm.SearchValue.ToLower()) ||
                                  x.ApiKey.ToLower().Contains(vm.SearchValue.ToLower())).AsQueryable();
            }
            if (vm.FilterByEmail)
            {
                try
                {
                    var allstaffs = await _payInvoiceClient.GetEmployeesAsync();

                    var filteredstaffs = allstaffs
                                         .Where(s => !string.IsNullOrEmpty(s.Email) && s.Email.Contains(vm.SearchValue))
                                         .GroupBy(x => x.MerchantId).ToList();
                    var filtered = new List <MerchantModel>();
                    foreach (var merchant in filteredstaffs)
                    {
                        var model = merchants.FirstOrDefault(m => m.Id == merchant.Key);
                        if (model != null)
                        {
                            filtered.Add(model);
                        }
                    }

                    list = filtered.AsQueryable();
                }
                catch (Exception)
                {
                    list = new List <MerchantModel>().AsQueryable();
                }
            }

            var pagedlist   = new List <MerchantModel>();
            var pageCount   = Convert.ToInt32(Math.Ceiling((double)list.Count() / vm.PageSize));
            var currentPage = vm.CurrentPage == 0 ? 1 : vm.CurrentPage;

            if (list.Count() != 0)
            {
                pagedlist = list.ToPagedList(currentPage, vm.PageSize).ToList();
            }
            var viewmodel = new MerchantsListViewModel()
            {
                Merchants    = pagedlist,
                PageSize     = vm.PageSize,
                Count        = pageCount,
                CurrentPage  = currentPage,
                IsEditAccess = (this.GetUserRolesPair()).HasAccessToFeature(UserFeatureAccess.LykkePayMerchantsEdit),
                IsFullAccess = (this.GetUserRolesPair()).HasAccessToFeature(UserFeatureAccess.LykkePayMerchantsFull)
            };

            return(View(viewmodel));
        }