Beispiel #1
0
        /// <summary>
        /// Детальная страница товара
        /// </summary>
        /// <returns></returns>
        public ActionResult Detail(string productKeyUrl)
        {
            var product = _productService.GetProductByKeyUrl(productKeyUrl);

            if (!product.IsSuccess)
            {
                return(RedirectToAction("Index", "Home"));
            }
            var user = new WebUser();
            var possibilityReview = false;

            if (user.IsAuthorized)
            {
                possibilityReview = _productService.ValidationReview(user.UserId, product.Value.Id).IsSuccess;
            }
            var model = new ProductDetailsView()
            {
                Product           = product.Value,
                PossibilityReview = possibilityReview,
                SimilarProduct    = _productService.GetSimilarProducts(product.Value.Id)
            };

            SetSitePageSettings(model.Product.Name, model.Product.SeoKeywords, model.Product.SeoDescription);
            return(View("~/Views/Product/Details.cshtml", model));
        }
        private void DetailsMethod(object param)
        {
            ProductDetailsView productDetailsView = new ProductDetailsView();

            App.Current.MainWindow.Close();
            App.Current.MainWindow = productDetailsView;
            productDetailsView.Show();
        }
    protected void ProductDetailsViewSqlDataSource_Inserted(object sender, SqlDataSourceStatusEventArgs e)
    {
        System.Data.Common.DbCommand command = e.Command;

        ProductDetailsViewSqlDataSource.SelectParameters["ProductID"].DefaultValue = command.Parameters["@ProductID"].Value.ToString();

        ProductGridView.DataBind();
        ProductDetailsView.DataBind();
    }
        void ReleaseDesignerOutlets()
        {
            if (ButtonsView != null)
            {
                ButtonsView.Dispose();
                ButtonsView = null;
            }

            if (DateLabel != null)
            {
                DateLabel.Dispose();
                DateLabel = null;
            }

            if (DeleteButton != null)
            {
                DeleteButton.Dispose();
                DeleteButton = null;
            }

            if (EditButton != null)
            {
                EditButton.Dispose();
                EditButton = null;
            }

            if (ProductDetailsView != null)
            {
                ProductDetailsView.Dispose();
                ProductDetailsView = null;
            }

            if (ProductImageView != null)
            {
                ProductImageView.Dispose();
                ProductImageView = null;
            }

            if (ProductTitleLabel != null)
            {
                ProductTitleLabel.Dispose();
                ProductTitleLabel = null;
            }

            if (ScoreContainerView != null)
            {
                ScoreContainerView.Dispose();
                ScoreContainerView = null;
            }

            if (TextLabel != null)
            {
                TextLabel.Dispose();
                TextLabel = null;
            }
        }
        /// <summary>
        /// Get details product
        /// </summary>
        /// <param name="id">id of product</param>
        /// <returns>Product details object</returns>
        public ProductDetailsView GetProductDetails(int id)
        {
            ecom_Products product = db.GetProductById(id);

            if (product == null)
            {
                return(null);
            }
            else
            {
                ProductDetailsView productViewModel = new ProductDetailsView()
                {
                    Id                = product.Id,
                    ProductCode       = product.ProductCode,
                    Name              = product.Name,
                    Price             = String.Format(System.Globalization.CultureInfo.GetCultureInfo("vi-VN"), "{0:C0}", product.Price),
                    BrandName         = product.ecom_Brands != null ? product.ecom_Brands.Name : "",
                    Description       = product.Description,
                    Description2      = product.Description2,
                    Tags              = product.Tags,
                    IsNewProduct      = product.IsNewProduct,
                    IsBestSellProduct = product.IsBestSellProduct,
                    Quantity          = product.Quantity,
                };

                ImageInfor coverImage;
                if (product.CoverImage != null)
                {
                    coverImage = new ImageInfor()
                    {
                        smallImagePath = product.CoverImage.ImagePath,
                        largeImagePath = GetLargeProductImagePathFromSmallImage(product.CoverImage.ImageName)
                    };
                }
                else
                {
                    coverImage = new ImageInfor()
                    {
                        smallImagePath = "/Content/Images/no-image.png",
                        largeImagePath = "/Content/Images/no-image.png"
                    };
                }


                List <ImageInfor> productImages = product.share_Images.Select(i => new ImageInfor()
                {
                    smallImagePath = i.ImagePath,
                    largeImagePath = GetLargeProductImagePathFromSmallImage(i.ImageName)
                }).ToList();

                productViewModel.CoverImageUrl = coverImage;
                productViewModel.share_Images  = productImages;

                return(productViewModel);
            }
        }
Beispiel #6
0
        public async Task <decimal> ApplyPromoCode(ProductDetailsView model)
        {
            if (model.PromoModel == null)
            {
                int promoId = int.Parse(TempData["Promo"].ToString());
                model.PromoModel = await _context.Promos.FirstOrDefaultAsync(x => x.Id == promoId);
            }

            var promo = model.PromoModel;
            var part  = model.ProductModel;
            var price = part.Price;

            // Valid Promo Check
            if (promo != null && promo.Enabled)
            {
                // Usage Limit Check
                if (promo.UsageLimit == null || promo.TimesUsed <= promo.UsageLimit)
                {
                    // Expiration Check
                    if (promo.ExpirationDate == null || promo.ExpirationDate > DateTime.UtcNow)
                    {
                        // Applicable Part Check
                        if (promo.ApplicableParts == null || promo.ApplicableParts.Count() == 0 || promo.ApplicableParts.FirstOrDefault(x => x.PartId == part.PartId) != null)
                        {
                            // Valid Discount Amount
                            if (promo.DiscountAmount != null)
                            {
                                price = Math.Round((price - (decimal)promo.DiscountAmount), 2);
                            }
                            else
                            {
                                var percent  = ((decimal)promo.DiscountPercentage / 100);
                                var discount = Math.Round((price * percent), 2);

                                price = (price - discount);
                            }

                            TempData["Message"] = "The promo code has been successfully applied.";
                            return(price);
                        }
                        TempData["Message"] = $"The promo has already reached its limit of {promo.UsageLimit}";
                        return(price);
                    }
                    TempData["Message"] = "This promo code has expired.";
                    return(price);
                }
            }
            TempData["Message"] = "This promo code is invalid.";
            return(price);
        }
        /// <summary>
        /// Get details of selected product
        /// </summary>
        /// <param name="id">id of product</param>
        /// <returns></returns>
        public ActionResult ProductDetails(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            ProductDetailsView product = service.GetProductDetails((int)id);

            PopulateNewProductList();
            PopulateCategoryList();
            PopulateTopCategoryList();

            return(View("ProductDetails", product));
        }
    protected void ProductDetailsView_ItemInserting(object sender, DetailsViewInsertEventArgs e)
    {
        VirtualImgFile = (FileUpload)ProductDetailsView.FindControl("ProductDetailsViewInsertImgFileUpload");
        if (VirtualImgFile.HasFile)
        {
            //判断文件类型是否符合要求
            bool fileValid = TestFile();

            if (fileValid)
            {
                //文件类型符合要求则调用SaveAs方法上传
                VirtualImgFile.SaveAs(Server.MapPath(PathStr) + VirtualImgFile.FileName);
                e.Values["ProductImgUrl"] = PathStr + VirtualImgFile.FileName;
            }
        }
    }
Beispiel #9
0
        /// <summary>
        /// Детальная страница товара
        /// </summary>
        /// <returns></returns>
        public ActionResult Details(int id)
        {
            var product           = _productService.GetProduct(id);
            var user              = new WebUser();
            var possibilityReview = false;

            if (user.IsAuthorized)
            {
                possibilityReview = _productService.ValidationReview(user.UserId, id).IsSuccess;
            }
            var model = new ProductDetailsView()
            {
                Product           = product,
                PossibilityReview = possibilityReview,
                SimilarProduct    = _productService.GetSimilarProducts(id)
            };

            SetSitePageSettings(model.Product.Name, model.Product.SeoKeywords, model.Product.SeoDescription);
            return(View(model));
        }
Beispiel #10
0
        public async Task <IActionResult> ApplyStoreCredit(ProductDetailsView model)
        {
            var amount = model.UserReferral.Earnings;

            var user = await _userManager.GetUserAsync(HttpContext.User);

            if (user != null)
            {
                var userRef = await _context.UserReferral.FirstOrDefaultAsync(x => x.Id == model.UserReferral.Id && x.UserId == user.Id);

                if (userRef != null && userRef.Enabled)
                {
                    if (amount > userRef.Earnings)
                    {
                        amount = userRef.Earnings;
                    }
                    TempData["StoreCredit"] = amount.ToString();
                }
            }
            return(RedirectToAction("Details", new { id = model.ProductModel.PartId }));
        }
Beispiel #11
0
        //==============================================================================


        public ProductDetailsViewModel(
            AppRepository <KfsContext> aAppDbRepository, TDStransactionControl aTDStransactionControl)
            : base(aAppDbRepository, aTDStransactionControl)
        {
            _myView             = new ProductDetailsView();
            _myView.DataContext = this;


            Command_NavigatBack = new RelayCommand(NavigateBack);
            Command_ToMainMenu  = new RelayCommand(NavigateToMainMenu);

            Command_AddNewProduct = new RelayCommand(NavigateToNewEmployee);

            Command_UpdateDBitemButtonInDatagridClick = new RelayCommand(UpdateDBitemButtonInDatagridClick);

            ItemsFromDB = _appDbRespository.Product.GetAllForOverview();
            foreach (var item in ItemsFromDB)
            {
                item.Supplier_Product_Prices = item.Supplier_Product_Prices.DistinctBy(p => p.Id_Supplier).ToList();
            }
            //_ProductsForStockManagement.ProductForStockDTO.DistinctBy(p => p.EAN).Select(x => x).ToList();


            //.Include(nameof(Product.Supplier_Product_Prices))
            //.Include(nameof(Product.Supplier_Product_Prices) + "." + nameof(Supplier_Product_Price.Supplier))
            ////.Include(nameof(Employee.EmpContract) + "." + nameof(EmpContract.EmpContractStatuutType))
            ////.Include(nameof(Employee.EmpContract) + "." + nameof(EmpContract.EmpContractType))
            ////.Include(nameof(Employee.EmpAppAccount))
            //.ToList();



            //EAN
            //ProductTitle
            //SellingPriceRecommended
            //BTWpercentage
            //WareHouseLocation
        }
Beispiel #12
0
        public async Task <IActionResult> PromoCode(ProductDetailsView model)
        {
            var user = await _userManager.GetUserAsync(HttpContext.User);

            var userRef = await _context.UserReferral.FirstOrDefaultAsync(x => x.UserId == user.Id);

            if (!string.IsNullOrEmpty(model.PromoModel.Code))
            {
                var promo = await _context.Promos.FirstOrDefaultAsync(x => x.Code.ToUpper() == model.PromoModel.Code.ToUpper().Replace(" ", "") &&
                                                                      x.Code.ToUpper() != userRef.ReferralCode);

                if (promo != null)
                {
                    TempData["Promo"] = promo.Id;
                }
                else
                {
                    TempData["Message"] = "Invalid promo code.";
                }
            }

            return(RedirectToAction("Details", new { id = model.ProductModel.PartId }));
        }
Beispiel #13
0
        public async Task <IActionResult> Details(int id)
        {
            var user = await _userManager.GetUserAsync(HttpContext.User);

            var viewModel = new ProductDetailsView();

            viewModel.ProductModel = await _context.Products.Include(x => x.Images).Include(x => x.Brand).Include(x => x.CarProducts).ThenInclude(x => x.Car).FirstOrDefaultAsync(x => x.PartId == id);

            viewModel.Images = viewModel.ProductModel.Images;

            if (user != null)
            {
                viewModel.UserReferral = await _context.UserReferral.FirstOrDefaultAsync(x => x.UserId == user.Id);
            }

            // Refferal Check
            if (HttpContext.Request.Cookies["Referral"] != null)
            {
                var referralCookie = await Task.Factory.StartNew(() => JsonConvert.DeserializeObject <UserReferral>(HttpContext.Request.Cookies["Referral"]));

                if (referralCookie != null && (user != null && referralCookie.UserId != user.Id) || user == null)
                {
                    viewModel.PromoModel = await _common.GetPromoAsync(referralCookie);
                }
            }

            // Promo
            if (viewModel.PromoModel != null)
            {
                var promoPrice = await ApplyPromoCode(viewModel);

                if (viewModel.ProductModel.Price != promoPrice)
                {
                    viewModel.NewPrice = promoPrice;
                }
            }

            // Store Credit
            if (TempData["StoreCredit"] != null)
            {
                var refAmount = decimal.Parse(TempData["StoreCredit"].ToString());

                viewModel.NewPrice = ((viewModel.ProductModel.Price - refAmount) <= 0 ? 0.01m : (viewModel.ProductModel.Price - refAmount));
            }

            // Sale
            if (viewModel.ProductModel.OnSale)
            {
                if (viewModel.ProductModel.SaleExpiration == null || viewModel.ProductModel.SaleExpiration >= DateTime.UtcNow)
                {
                    if (viewModel.ProductModel.SaleAmount != null)
                    {
                        viewModel.NewPrice = viewModel.ProductModel.Price - (decimal)viewModel.ProductModel.SaleAmount;
                    }
                    else
                    {
                        var discount = viewModel.ProductModel.Price * (decimal)(viewModel.ProductModel.SalePercent / 100m);
                        viewModel.NewPrice = viewModel.ProductModel.Price - discount;
                    }
                }
                else
                {
                    var product = viewModel.ProductModel;
                    product.OnSale = false;

                    _context.Products.Update(product);
                    await _context.SaveChangesAsync();
                }
            }

            return(View(viewModel));
        }
Beispiel #14
0
        public async Task <IActionResult> BuyNow(ProductDetailsView model, decimal?refAmount)
        {
            var user = await _userManager.GetUserAsync(HttpContext.User);

            model.ProductModel = await _context.Products.Include(x => x.Brand).FirstOrDefaultAsync(x => x.PartId == model.ProductModel.PartId);

            if (model.PromoModel != null)
            {
                model.PromoModel = await _context.Promos.Include(x => x.ApplicableParts).FirstOrDefaultAsync(x => x.Id == model.PromoModel.Id);

                var promo     = model.PromoModel;
                var timesUsed = promo.TimesUsed;
                model.ProductModel.Price = await ApplyPromoCode(model);

                timesUsed++;
                await _context.SaveChangesAsync();
            }

            if (user != null)
            {
                var userRef = await _context.UserReferral.FirstOrDefaultAsync(x => x.Id == model.UserReferral.Id && x.UserId == user.Id);

                if (refAmount != null && userRef != null)
                {
                    if (refAmount > userRef.Earnings)
                    {
                        refAmount = userRef.Earnings;
                    }

                    decimal price = ((model.ProductModel.Price - (decimal)refAmount) <= 0 ? 0.01m : (model.ProductModel.Price - (decimal)refAmount));
                    model.ProductModel.Price = Math.Round(price, 2);
                }
            }

            if (model.ProductModel != null)
            {
                var url = (HttpContext.Request.Host.Host.ToUpper().Contains("LOCALHOST")) ?
                          "https://www.sandbox.paypal.com/us/cgi-bin/webscr" : "https://www.paypal.com/us/cgi-bin/webscr";
                var paypalBusiness = _settings.PaypalBusiness;

                var builder = new StringBuilder();
                builder.Append(url);

                builder.Append($"?cmd=_xclick&business={UrlEncoder.Default.Encode(paypalBusiness)}");
                builder.Append($"&lc=US&no_note=0&currency_code=USD&tax_rate=9");
                builder.Append($"&custom={UrlEncoder.Default.Encode(model.ProductModel.PartNumber)}");
                builder.Append($"&item_name={UrlEncoder.Default.Encode($"{model.ProductModel.Brand.Name} - {model.ProductModel.Name}: #{model.ProductModel.PartNumber}")}");
                builder.Append($"&amount={UrlEncoder.Default.Encode(model.ProductModel.SalePrice.ToString())}");
                builder.Append($"&return={UrlEncoder.Default.Encode($"https://{HttpContext.Request.Host.Value}/Home/ThankYou?id={model.ProductModel.PartId}")}");
                builder.Append($"&cancel_return={UrlEncoder.Default.Encode($"https://{HttpContext.Request.Host.Value}/Parts/Details?id={model.ProductModel.PartId}")}");
                builder.Append($"&quantity={UrlEncoder.Default.Encode(model.Quantity.ToString())}");
                builder.Append($"&shipping={UrlEncoder.Default.Encode(Math.Round((decimal)model.Quantity * model.ProductModel.Shipping, 2).ToString())}");
                builder.Append($"&item_number={UrlEncoder.Default.Encode(model.ProductModel.PartNumber)}");

                TempData["ThankYouValidation"] = true;
                TempData["RefAmount"]          = refAmount.ToString();
                return(Redirect(builder.ToString()));
            }

            return(RedirectToAction("Details", model.ProductModel.PartId));
        }
        public ActionResult Details(int?id)
        {
            Cart         productCart       = new Cart();
            int?         remainingQuantity = null;
            ShoppingCart shoppingCart      = ShoppingCart.GetCart(this);
            List <Cart>  carts             = shoppingCart.GetCartProducts();
            Product      product           = new Product();
            bool         inCart            = false;

            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            try
            {
                product = ModelLists.Products.Where(prod => prod.ProductID == id).Single();
            }
            catch (Exception)
            {
                return(HttpNotFound());
            }
            if (carts.Count > 0)
            {
                productCart = carts.Where(x => x.ProductID == id).SingleOrDefault();
                if (productCart != null)
                {
                    inCart = true;
                    if (product.LimitOne)
                    {
                        remainingQuantity = 0;
                    }
                    else
                    {
                        remainingQuantity = productCart.Product.Quantity - productCart.Quantity;
                    }
                }
                else
                {
                    remainingQuantity = product.Quantity;
                }
            }
            else
            {
                remainingQuantity = product.Quantity;
            }

            if (product.InactiveProduct)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            if (product == null)
            {
                return(HttpNotFound());
            }

            ProductDetailsView bp = new ProductDetailsView
            {
                Product  = product,
                Quantity = remainingQuantity,
                InCart   = inCart
            };

            return(View(bp));
        }
Beispiel #16
0
 protected void Page_PreRender(object sender, EventArgs e)
 {
     ProductDetailsView.DataBind();
     ProductListView.DataBind();
 }