コード例 #1
0
        public IActionResult OnGet(string id)
        {
            var userId = String.IsNullOrEmpty(id) ? _userManager.GetUserId(User) : id;

            var cart = _cartRepository.GetCurrentUserCart(userId);

            if (cart == null || cart.OrderDetails.Count == 0 || cart.Payed == true || cart.IsDeleted == true)
            {
                return(Page());
            }

            foreach (var item in cart.OrderDetails)
            {
                var price = _productRepository.GetSalePrice((int)item.ProductId) == null?_productRepository.GetCurrentPrice((int)item.ProductId).Price1 : _productRepository.GetSalePrice((int)item.ProductId).Price1;

                Products.Add(new ProductCartViewModel()
                {
                    Id          = item.Id,
                    Price       = (decimal)price,
                    ProductName = item.Product.Name,
                    Quantity    = (int)item.Quantity,
                    Total       = (decimal)price * (int)item.Quantity,
                    ImagePath   = Url.Content(_uploadRepository.GetProductThumbnail((int)item.ProductId).Path)
                });
                Total += (decimal)price * (int)item.Quantity;
            }

            return(Page());
        }
コード例 #2
0
ファイル: Index.cshtml.cs プロジェクト: ertanhasani/ecommerce
        public void OnGet()
        {
            var products = _productRepository.GetProducts().Take(12);

            foreach (var item in products)
            {
                Products.Add(new ProductListViewModel()
                {
                    Id        = item.Id,
                    Url       = "/Producti/" + item.Id,
                    Title     = item.Name,
                    IsOnSale  = (bool)item.IsOnSale,
                    Price     = (decimal)_productRepository.GetCurrentPrice(item.Id).Price1,
                    SalePrice = _productRepository.GetSalePrice(item.Id) != null ? (decimal)_productRepository.GetSalePrice(item.Id).Price1 : 0.00M,
                    ImagePath = Url.Content(_uploadRepository.GetProductThumbnail(item.Id).Path)
                });
            }

            var carousels = _uploadRepository.GetCarousels();

            foreach (var item in carousels)
            {
                Carousels.Add(new CarouselViewModel()
                {
                    Id   = item.Id,
                    Name = item.FileName,
                    Path = Url.Content(item.Path)
                });
            }
        }
コード例 #3
0
        public IActionResult OnGet(int id)
        {
            if (id != 0)
            {
                var product = _productRepository.GetProduct(id);
                if (product == null)
                {
                    return(RedirectToPage("/Index"));
                }

                Id          = id;
                Name        = product.Name;
                Description = product.Description;
                Price       = _productRepository.GetCurrentPrice(id).Price1;
                IsOnSale    = (bool)product.IsOnSale;
                SalePrice   = _productRepository.GetSalePrice(id) == null ? null : _productRepository.GetSalePrice(id).Price1;
                Quantity    = (int)product.Quantity;

                ThumbnailUrl = Url.Content(_uploadRepository.GetProductThumbnail(id).Path);

                var categories         = _categoryRepository.GetCategories();
                var selectedCategories = _categoryRepository.GetProductCategories(id).Select(p => new
                {
                    Id   = p.Category.Id,
                    Name = p.Category.Name
                });
                Categories             = selectedCategories.Select(p => p.Id).ToArray();
                ViewData["Categories"] = new MultiSelectList(categories.Select(p => new
                {
                    Id   = p.Id,
                    Name = p.Name
                }), "Id", "Name", selectedCategories);
            }
            else
            {
                Id = id;
                var categories = _categoryRepository.GetCategories();
                ViewData["Categories"] = new MultiSelectList(categories.Select(p => new
                {
                    Id   = p.Id,
                    Name = p.Name
                }), "Id", "Name");
            }

            return(Page());
        }
コード例 #4
0
ファイル: View.cshtml.cs プロジェクト: ertanhasani/ecommerce
        public IActionResult OnGet(int id, string toastr)
        {
            var cart = _cartRepository.GetCart(id);

            if (id == 0 || cart == null)
            {
                return(RedirectToPage("/Index"));
            }

            foreach (var item in cart.OrderDetails)
            {
                Products.Add(new ProductCartViewModel()
                {
                    Id          = (int)item.ProductId,
                    ProductName = item.Product.Name,
                    ImagePath   = Url.Content(_uploadRepository.GetProductThumbnail((int)item.ProductId).Path),
                    Price       = (decimal)item.Price,
                    Quantity    = (int)item.Quantity,
                    Total       = (decimal)item.Total
                });
                Total += (decimal)item.Total;
            }

            if (User.IsInRole("Admin"))
            {
                Id = id;
                var statuses      = _cartRepository.GetCartStatues();
                var currentStatus = _cartRepository.GetCartStatus(id);
                StatusId             = currentStatus.Id;
                ViewData["Statuses"] = new SelectList(statuses, "Id", "Name", currentStatus);
            }

            var shipping = _cartRepository.GetCartShippingAddress(id);

            Shipping.FullName = shipping.FullName;
            Shipping.Address1 = shipping.Address1;
            Shipping.Address2 = shipping.Address2;
            Shipping.City     = shipping.City;
            Shipping.State    = shipping.State;
            Shipping.ZipCode  = shipping.PostalCode;

            if (!String.IsNullOrEmpty(toastr))
            {
                ViewData["Success"] = toastr;
            }

            return(Page());
        }
コード例 #5
0
        public IActionResult OnGetProducts(int pageNr, int categoryId, string searchQuery)
        {
            var model    = new List <ProductListViewModel>();
            var products = _productRepository.GetProducts();

            if (!String.IsNullOrEmpty(searchQuery))
            {
                products = products.Where(p => p.Name.ToLower().Contains(searchQuery.ToLower()));
            }

            if (categoryId != 0)
            {
                products = products.Where(p => p.ProductCategory.Any(o => o.CategoryId == categoryId));
            }

            decimal pagesInDecimal = (decimal)products.Count() / 20;
            var     totalPages     = pagesInDecimal % 1 == 0 ? pagesInDecimal : (int)pagesInDecimal + 1;

            products = products.Skip((pageNr - 1) * 20).Take(20);

            foreach (var item in products)
            {
                model.Add(new ProductListViewModel()
                {
                    Id        = item.Id,
                    Url       = "/Producti/" + item.Id,
                    Title     = item.Name,
                    IsOnSale  = (bool)item.IsOnSale,
                    Price     = (decimal)_productRepository.GetCurrentPrice(item.Id).Price1,
                    SalePrice = _productRepository.GetSalePrice(item.Id) != null ? (decimal)_productRepository.GetSalePrice(item.Id).Price1 : 0.00M,
                    ImagePath = Url.Content(_uploadRepository.GetProductThumbnail(item.Id).Path)
                });
            }

            return(new JsonResult(new {
                totalPages = totalPages,
                products = model
            }));
        }
コード例 #6
0
        public IActionResult OnGet(int id, string toastr, bool error = false)
        {
            var model = _productRepository.GetProduct(id);

            if (model == null)
            {
                return(RedirectToPage("/Index"));
            }

            Id          = model.Id;
            Name        = model.Name;
            Stock       = (int)model.Quantity;
            Description = model.Description;
            IsOnSale    = (bool)model.IsOnSale;
            Price       = (decimal)_productRepository.GetCurrentPrice(id).Price1;
            if (IsOnSale)
            {
                SalePrice = (decimal)_productRepository.GetSalePrice(id).Price1;
            }
            var categories = _categoryRepository.GetProductCategories(id);
            var i          = 0;

            foreach (var item in categories)
            {
                if (i == 0)
                {
                    Categories = item.Category.Name;
                }
                else
                {
                    Categories += ", " + item.Category.Name;
                }
            }

            var uploads = _uploadRepository.GetProductUploads(id);

            foreach (var item in uploads)
            {
                Uploads.Add(new UploadViewModel()
                {
                    FileName = item.FileName,
                    Path     = item.Path
                });
            }

            var product = _productRepository.GetProducts().Where(p => p.Id != id).Take(4);

            foreach (var item in product)
            {
                Products.Add(new ProductListViewModel()
                {
                    Id        = item.Id,
                    ImagePath = Url.Content(_uploadRepository.GetProductThumbnail(item.Id).Path),
                    IsOnSale  = (bool)item.IsOnSale,
                    SalePrice = _productRepository.GetSalePrice(item.Id) != null ? (decimal)_productRepository.GetSalePrice(item.Id).Price1 : 0.00M,
                    Price     = (decimal)_productRepository.GetCurrentPrice(item.Id).Price1,
                    Title     = item.Name,
                    Url       = "/Producti/" + item.Id
                });
            }

            if (!String.IsNullOrEmpty(toastr) && !error)
            {
                ViewData["Success"] = toastr;
            }

            if (!String.IsNullOrEmpty(toastr) && error)
            {
                ViewData["Error"] = toastr;
            }

            return(Page());
        }