Ejemplo n.º 1
0
 public virtual ActionResult List(string term = "", int pageNumber = 1, int pageCount = 10,
                                  Order order = Order.Descending, UserOrderBy userOrderBy
                                              = UserOrderBy.RegisterDate, UserSearchBy userSearchBy = UserSearchBy.PhoneNumber)
 {
     #region Retrive Data
     int totalUsers;
     var users = _userService.GetDataTable(out totalUsers, term, pageNumber, pageCount, order, userOrderBy, userSearchBy);
     var model = new UsersListViewModel
     {
         UserOrderBy = userOrderBy,
         Term        = term,
         PageNumber  = pageNumber,
         Order       = order,
         UsersList   = users,
         TotalUsers  = totalUsers,
         PageCount   = pageCount
     };
     #endregion
     ViewBag.UserSearchByList = DropDown.GetUserSearchByList(userSearchBy);
     ViewBag.UserOrderByList  = DropDown.GetUserOrderByList(userOrderBy);
     ViewBag.CountList        = DropDown.GetCountList(pageCount);
     ViewBag.OrderList        = DropDown.GetOrderList(order);
     ViewBag.UserSearchBy     = userSearchBy;
     return(PartialView(MVC.Admin.User.Views._ListPartial, model));
 }
Ejemplo n.º 2
0
        public virtual ActionResult List(bool freeSend = false, bool deleted = false, string term = "", int page = 1, int count = 10,
                                         Order order   = Order.Descending, ProductOrderBy productOrderBy = ProductOrderBy.Name, long categoryId = 0, ProductType productType = ProductType.All)
        {
            #region Retrive Data
            int total;
            var products = _productService.DataList(out total, term, deleted, freeSend, page, count, categoryId, productOrderBy,
                                                    order, productType);
            var model = new ProductListViewModel
            {
                CategoryId     = categoryId,
                Order          = order,
                ProductOrderBy = productOrderBy,
                PageCount      = count,
                PageNumber     = page,
                ProductList    = products,
                ProductType    = productType,
                Term           = term,
                TotalProducts  = total,
                Deleted        = deleted,
                FreeSend       = freeSend
            };
            #endregion

            ViewBag.ProductOrderByList = DropDown.GetProductOrderByList(productOrderBy);
            ViewBag.CountList          = DropDown.GetCountList(count);
            ViewBag.OrderList          = DropDown.GetOrderList(order);
            PopulateCategoriesDropDownList(categoryId);
            return(PartialView(MVC.Admin.Product.Views._ListPartial, model));
        }
Ejemplo n.º 3
0
        public IEnumerable <ProductViewModel> DataList(out int total, string term, bool deleted, bool freeSend, int page, int count, long categoryId, ProductOrderBy productOrderBy, Order order, ProductType productType)
        {
            var selectedProducts =
                _products.AsNoTracking()
                .Include(a => a.Category)
                .Include(a => a.Values)
                .Include(a => a.Images)
                .AsQueryable();

            if (deleted || freeSend)
            {
                selectedProducts =
                    selectedProducts.Where(a => a.Deleted == deleted && a.IsFreeShipping == freeSend).AsQueryable();
            }

            if (categoryId != 0)
            {
                selectedProducts = selectedProducts.Where(a => a.CategoryId == categoryId).AsQueryable();
            }

            if (productType != ProductType.All)
            {
                selectedProducts = selectedProducts.Where(a => a.Type == productType).AsQueryable();
            }

            if (!string.IsNullOrEmpty(term))
            {
                selectedProducts = selectedProducts.Where(product => product.Name.Contains(term)).AsQueryable();
            }

            if (order == Order.Asscending)
            {
                switch (productOrderBy)
                {
                case ProductOrderBy.Name:
                    selectedProducts = selectedProducts.OrderBy(product => product.Name).AsQueryable();
                    break;

                case ProductOrderBy.DiscountPercent:
                    selectedProducts = selectedProducts.OrderBy(product => product.DiscountPercent).AsQueryable();
                    break;

                case ProductOrderBy.NotificationStockMinimun:
                    selectedProducts = selectedProducts.OrderBy(product => product.NotificationStockMinimum).AsQueryable();
                    break;

                case ProductOrderBy.Price:
                    selectedProducts = selectedProducts.OrderBy(product => product.Price).AsQueryable();
                    break;

                case ProductOrderBy.ReserveCount:
                    selectedProducts = selectedProducts.OrderBy(product => product.Reserve).AsQueryable();
                    break;

                case ProductOrderBy.SellCount:
                    selectedProducts = selectedProducts.OrderBy(product => product.SellCount).AsQueryable();
                    break;

                case ProductOrderBy.StockCount:
                    selectedProducts = selectedProducts.OrderBy(product => product.Stock).AsQueryable();
                    break;

                case ProductOrderBy.ViewCount:
                    selectedProducts = selectedProducts.OrderBy(product => product.ViewCount).AsQueryable();
                    break;
                }
            }
            else
            {
                switch (productOrderBy)
                {
                case ProductOrderBy.Name:
                    selectedProducts = selectedProducts.OrderByDescending(product => product.Name).AsQueryable();
                    break;

                case ProductOrderBy.DiscountPercent:
                    selectedProducts = selectedProducts.OrderByDescending(product => product.DiscountPercent).AsQueryable();
                    break;

                case ProductOrderBy.NotificationStockMinimun:
                    selectedProducts = selectedProducts.OrderByDescending(product => product.NotificationStockMinimum).AsQueryable();
                    break;

                case ProductOrderBy.Price:
                    selectedProducts = selectedProducts.OrderByDescending(product => product.Price).AsQueryable();
                    break;

                case ProductOrderBy.ReserveCount:
                    selectedProducts = selectedProducts.OrderByDescending(product => product.Reserve).AsQueryable();
                    break;

                case ProductOrderBy.SellCount:
                    selectedProducts = selectedProducts.OrderByDescending(product => product.SellCount).AsQueryable();
                    break;

                case ProductOrderBy.StockCount:
                    selectedProducts = selectedProducts.OrderByDescending(product => product.Stock).AsQueryable();
                    break;

                case ProductOrderBy.ViewCount:
                    selectedProducts = selectedProducts.OrderByDescending(product => product.ViewCount).AsQueryable();
                    break;
                }
            }
            var totalQuery  = selectedProducts.FutureCount();
            var selectQuery = selectedProducts.Skip((page - 1) * count).Take(count)
                              .Select(a => new ProductViewModel
            {
                ApplyCategoryDiscount = a.ApplyCategoryDiscount,
                CategoryName          = a.Category.Name,
                Deleted         = a.Deleted,
                DiscountPercent = a.DiscountPercent,
                Id                       = a.Id,
                IsFreeShipping           = a.IsFreeShipping,
                Name                     = a.Name,
                NotificationStockMinimum = a.NotificationStockMinimum,
                Price                    = a.Price,
                PrincipleImagePath       = a.PrincipleImagePath,
                Rate                     = a.Rate.TotalRating,
                Ratio                    = a.Ratio,
                ReserveCount             = a.Reserve,
                SellCount                = a.SellCount,
                Stock                    = a.Stock,
                ViewCount                = a.ViewCount,
                AddedImages              = a.Images.Any(),
                CompletedAttributes      = a.Values.Any(),
                Notification             = a.Stock - a.Reserve <= a.NotificationStockMinimum
            }).Future();

            total = totalQuery.Value;
            var products = selectQuery.ToList();

            return(products);
        }
Ejemplo n.º 4
0
        public IList <UserViewModel> GetDataTable(out int total, string term, int page, int count, DomainClasses.Enums.Order order, UserOrderBy orderBy, UserSearchBy searchBy)
        {
            var selectedUsers = _users.AsNoTracking().Include(a => a.Role).AsQueryable();

            if (!string.IsNullOrEmpty(term))
            {
                switch (searchBy)
                {
                case UserSearchBy.UserName:
                    selectedUsers = selectedUsers.Where(user => user.UserName.Contains(term)).AsQueryable();
                    break;

                case UserSearchBy.RoleDescription:
                    selectedUsers = selectedUsers.Where(user => user.Role.Description.Contains(term)).AsQueryable();
                    break;

                case UserSearchBy.PhoneNumber:
                    selectedUsers =
                        selectedUsers.Where(user => user.PhoneNumber.Contains(term)).AsQueryable();
                    break;

                case UserSearchBy.Ip:
                    selectedUsers =
                        selectedUsers.Where(user => user.IP.Contains(term)).AsQueryable();
                    break;
                }
            }


            if (order == DomainClasses.Enums.Order.Asscending)
            {
                switch (orderBy)
                {
                case UserOrderBy.UserName:
                    selectedUsers = selectedUsers.OrderBy(user => user.UserName).AsQueryable();
                    break;

                case UserOrderBy.OrderCount:
                    selectedUsers = selectedUsers.OrderBy(user => user.Orders.Count).AsQueryable();
                    break;

                case UserOrderBy.RegisterDate:
                    selectedUsers = selectedUsers.OrderBy(user => user.RegisterDate).AsQueryable();
                    break;
                }
            }
            else
            {
                switch (orderBy)
                {
                case UserOrderBy.UserName:
                    selectedUsers = selectedUsers.OrderByDescending(user => user.UserName).AsQueryable();
                    break;

                case UserOrderBy.OrderCount:
                    selectedUsers = selectedUsers.OrderByDescending(user => user.Orders.Count).AsQueryable();
                    break;

                case UserOrderBy.RegisterDate:
                    selectedUsers = selectedUsers.OrderByDescending(user => user.RegisterDate).AsQueryable();
                    break;
                }
            }
            var totalQuery  = selectedUsers.FutureCount();
            var selectQuery = selectedUsers.Skip((page - 1) * count).Take(count)
                              .Select(a => new UserViewModel
            {
                UserName        = a.UserName,
                FullName        = a.FirstName + " " + a.LastName,
                PhoneNumber     = a.PhoneNumber,
                RegisterType    = a.RegisterType == UserRegisterType.Active ? "خرید کرده" : "خرید نکرده",
                Baned           = a.IsBaned,
                CommentCount    = a.Comments.Count,
                Id              = a.Id,
                OrderCount      = a.Orders.Count,
                RoleDescritpion = a.Role.Description
            }).Future();

            total = totalQuery.Value;
            var users = selectQuery.ToList();

            return(users);
        }