예제 #1
0
        private ProductsViewModel GetOrderList(int page, int pageSize)
        {
            var products = _repository.GetMany(p => category == null || p.Category.Name == category)
                           .OrderBy(p => p.Id)
                           .Skip((page - 1) * pageSize)
                           .Take(pageSize);
            var productsViewModel = new List <ProductViewModel>();

            foreach (var product in products)
            {
                var productViewModel = new ProductViewModel();
                productViewModel.EntityToProductViewModel(product);
                productsViewModel.Add(productViewModel);
            }

            var model = new ProductsViewModel
            {
                Products   = productsViewModel,
                PagingInfo = new PagingInfo
                {
                    CurrentPage  = page,
                    ItemsPerPage = pageSize,
                    TotalItems   = category == null?
                                   _repository.GetCount() :
                                       _repository.GetMany(e => e.Category.Name == category).Count()
                },
                CurrentCategory = category
            };

            return(model);
        }
예제 #2
0
        public ActionResult Index()
        {
            var userName    = HttpContext.User.Identity.Name;
            var userManager = new UserManager(_userRepository, _roleRepository, _contactsRepository, _unitOfWork);
            var IsAdmin     = userManager.UserIsInRole(userName, ConstantStrings.AdministratorRole);
            var IsModerator = userManager.UserIsInRole(userName, ConstantStrings.ModeratorRole);

            //-----------------------------------------
            if (IsAdmin || IsModerator)
            {
                var masterViewModel   = new MasterPageModel();
                var productsViewModel = new ProductsViewModel();
                var products          = _repository.GetAll();
                var productList       = new List <ProductViewModel>();
                foreach (var product in products)
                {
                    var tmp = new ProductViewModel();
                    tmp.EntityToProductViewModel(product);
                    productList.Add(tmp);
                }
                productsViewModel.Products        = productList;
                masterViewModel.ProductsViewModel = productsViewModel;
                masterViewModel.UserModel         = userManager.GetUserViewModelByName(userName);
                masterViewModel.UserRole          = ConstantStrings.AdministratorRole;
                return(View(masterViewModel));
            }
            else
            {
                return(RedirectToAction("Index", "Home"));
            }
        }
예제 #3
0
        public ProductViewModel GetProduct(int Id)
        {
            var product     = new ProductViewModel();
            var tempProduct = _repository.GetById(Id);

            product.EntityToProductViewModel(tempProduct);
            return(product);
        }