コード例 #1
0
        public ActionResult Create(string id)
        {
            Session[Config.DesignImage]   = new List <ProductMultiUpload>();
            Session[Config.MaterialImage] = new List <ProductMultiUpload>();

            if (!string.IsNullOrWhiteSpace(id))
            {
                shProductService _product = new shProductService();
                shProduct        product  = _product.FindByKey(id);

                if (product != null)
                {
                    shCategoryService _category = new shCategoryService();

                    ViewBag.citySel     = _category.CategoryName(product.CategoryGuid);
                    ViewBag.ProductGuid = product.ProductGuid;

                    #region Image
                    shProductImageService        _productImage   = new shProductImageService();
                    IEnumerable <shProductImage> DsDesignImage   = _productImage.DanhSachProductImage_ByCategory(product.ProductGuid, Config.ProductImageCategory_Design);
                    IEnumerable <shProductImage> DsMaterialImage = _productImage.DanhSachProductImage_ByCategory(product.ProductGuid, Config.ProductImageCategory_Material);
                    ViewBag.DsDesignImage   = DsDesignImage;
                    ViewBag.DsMaterialImage = DsMaterialImage;
                    #endregion

                    return(View(product));
                }
                else
                {
                    return(View(new shProduct()));
                }
            }

            if (TempData["ERROR"] != null)
            {
                ModelState.AddModelError("", TempData["ERROR"].ToString());

                shCategoryService _category = new shCategoryService();

                if (TempData["CategoryGuid"] != null)
                {
                    ViewBag.citySel = _category.CategoryName(TempData["CategoryGuid"].ToString());
                }

                ViewBag.CategoryGuid = TempData["CategoryGuid"];
                ViewBag.ProductGuid  = TempData["ProductGuid"];
                ViewBag.ProductName  = TempData["ProductName"];
                ViewBag.Description  = TempData["Description"];
                ViewBag.Details      = TempData["Details"];

                TempData["ERROR"] = null;
            }

            return(View(new shProduct()));
        }
コード例 #2
0
ファイル: ProductHelper.cs プロジェクト: Nghinv00/ShopOnLine
        public static string ProductImage(this HtmlHelper helper, string ProductGuid)
        {
            shProductImageService _productImage = new shProductImageService();

            IEnumerable <shProductImage> dsImage = _productImage.FindList().Where(x => x.ProductGuid == ProductGuid);

            string image = string.Empty;

            if (dsImage.Count() > 0)
            {
                image = dsImage.LastOrDefault().FileName;
            }
            return(image);
        }
コード例 #3
0
        public ActionResult Details(int?id)
        {
            shProductService _product = new shProductService();

            shProduct product = _product.FindList().Where(x => x.ProductId == id).FirstOrDefault();

            shProductImageService        _productImage = new shProductImageService();
            IEnumerable <shProductImage> dsImage       = _productImage.DanhSachProductImage_ByProductGuid(product.ProductGuid);

            ViewBag.dsImageMauMa    = dsImage.Where(x => x.ProductImageCategory == Config.ProductImageCategory_Design);
            ViewBag.dsImageChatLieu = dsImage.Where(x => x.ProductImageCategory == Config.ProductImageCategory_Material);


            shSectionService           _section  = new shSectionService();
            IEnumerable <shProductSet> dsSection = _section.DanhSachSection_TheoProductGuid_ParentNull(product.ProductGuid);


            shProductSet section = new shProductSet();

            if (dsSection != null && dsSection.Count() > 0)
            {
                section = dsSection.FirstOrDefault();
            }

            shSizeService           _size  = new shSizeService();
            IEnumerable <shSetSize> dsSize = _size.DanhSachSize_BySectionGuid(section.SectionGuid, product.ProductGuid, null);


            ViewBag.ProductSize = section.SectionName + " --- " +
                                  CommonHelper.TinhToanKichThuocMaxMin(dsSize.FirstOrDefault(), dsSize.LastOrDefault());
            ViewBag.ProductPrice = CommonHelper.TinhToanGiaTienMaxMin(dsSize.FirstOrDefault(), dsSize.LastOrDefault());

            // Tính toán số tiền sau khuyến mại
            string productSale = CommonHelper.TinhToanGiaTienSauKhiGiam(dsSize.FirstOrDefault(), dsSize.LastOrDefault());

            if (!string.IsNullOrEmpty(productSale) && !string.IsNullOrWhiteSpace(productSale))
            {
                ViewBag.ProductSale = Format.FormatDecimalToString(Convert.ToDecimal(productSale));
            }


            ViewBag.ListSection = dsSection;

            return(View(product));
        }
コード例 #4
0
        public ActionResult DialogHighLight(string ProductGuid, string ImageCarousel)
        {
            using (var context = new ShopOnlineDb())
            {
                using (var dbContextTransaction = context.Database.BeginTransaction())
                {
                    try
                    {
                        // 1. cập nhật ảnh đại diện sản phẩm
                        shProductService _product = new shProductService();
                        _product.UploadImageProduct(ProductGuid, ImageCarousel);

                        // 2. Upload file sản phẩm nổi bật
                        shProductImageService _productImage = new shProductImageService();
                        shProductImage        productImage  = new shProductImage();
                        productImage = _productImage.Insert_UpdateProductImage(
                            null,
                            null,
                            ProductGuid,
                            ImageCarousel,
                            null,
                            User.Identity.GetUserLogin().Userid,
                            true,
                            DateTime.Now,
                            Config.ProductImageCategory_Design,
                            Config.Product_Image_HighLight
                            );

                        dbContextTransaction.Commit();
                    }
                    catch (Exception ex)
                    {
                        dbContextTransaction.Rollback();
                    }
                }
            }

            if (Request.IsAjaxRequest())
            {
                return(Json("OK", JsonRequestBehavior.AllowGet));
            }
            return(RedirectToAction("Index"));
        }
コード例 #5
0
        public ActionResult Preview(string ProductGuid)
        {
            shProductService _product = new shProductService();
            shProduct        product  = _product.FindByKey(ProductGuid);

            if (product != null)
            {
                #region Image
                shProductImageService        _productImage   = new shProductImageService();
                IEnumerable <shProductImage> DsDesignImage   = _productImage.DanhSachProductImage_ByCategory(product.ProductGuid, Config.ProductImageCategory_Design);
                IEnumerable <shProductImage> DsMaterialImage = _productImage.DanhSachProductImage_ByCategory(product.ProductGuid, Config.ProductImageCategory_Material);
                ViewBag.DsDesignImage   = DsDesignImage;
                ViewBag.DsMaterialImage = DsMaterialImage;
                #endregion

                shSectionService           _section  = new shSectionService();
                IEnumerable <shProductSet> dsSection = _section.DanhSachSection_TheoProductGuid_ParentNull(product.ProductGuid);
                ViewBag.Section = dsSection;

                return(PartialView("Preview", product));
            }

            return(PartialView("Preview", new shProduct()));
        }
コード例 #6
0
ファイル: ProductHelper.cs プロジェクト: Nghinv00/ShopOnLine
        public static string ProductHighLightImage(this HtmlHelper helper, string ProductGuid)
        {
            shProductImageService _productImage = new shProductImageService();

            IEnumerable <shProductImage> dsImage = _productImage.FindList()
                                                   .Where(x => x.ProductGuid == ProductGuid);

            string image = string.Empty;

            if (dsImage.Count() > 0)
            {
                shProductImage productDefault = dsImage.LastOrDefault();

                shProductImage productImage = dsImage.Where(x => x.Image == Config.Product_Image_HighLight).FirstOrDefault();

                if (!string.IsNullOrWhiteSpace(productImage.Image) || !string.IsNullOrEmpty(productImage.Image))
                {
                    return(productImage.FileName);
                }

                return(productDefault.FileName);
            }
            return(image);
        }
コード例 #7
0
        public ActionResult Create(string ProductGuid, string CategoryGuid, int?ProductId, string ProductName, string CompleteSetInclude, string Details, int?Number, int?SortOrder, string UserManual, bool?Status, string Description,
                                   string DeleteImage)
        {
            List <ProductMultiUpload> dsDesignImage   = (List <ProductMultiUpload>)Session[Config.DesignImage];
            List <ProductMultiUpload> dsMaterialImage = (List <ProductMultiUpload>)Session[Config.MaterialImage];

            shProductService _product = new shProductService();

            string Image = "";

            if (dsDesignImage.Count() > 0)
            {
                var obj = dsDesignImage.FirstOrDefault();
                if (obj != null)
                {
                    Image = obj.value;
                }
            }
            shProduct product = new shProduct();

            using (var context = new ShopOnlineDb())
            {
                using (var dbContextTransaction = context.Database.BeginTransaction())
                {
                    try
                    {
                        // 1. Inser , Upload Product
                        product = _product.Inser_UpdateProduct(
                            ProductGuid,
                            ProductId.Value,
                            CategoryGuid,
                            ProductName,
                            null,
                            CompleteSetInclude,
                            Details,
                            UserManual,
                            null,
                            null,
                            Number,
                            Image,
                            null,
                            null,
                            SortOrder,
                            null,
                            null,
                            Status,
                            DateTime.Now,
                            Description);


                        if (!(product.ProductId > 0))
                        {
                            TempData["ERROR"]        = "Cập nhật dữ liệu bản ghi không thành công. Xin vui lòng thao tác lại";
                            TempData["ProductGuid"]  = ProductGuid;
                            TempData["CategoryGuid"] = CategoryGuid;
                            TempData["ProductName"]  = ProductName;
                            TempData["Description"]  = Description;
                            TempData["Details"]      = Details;

                            return(RedirectToAction("Create", new { id = ProductGuid }));
                        }
                        // 2. nếu người dùng có upload file lưu lại lịch sử trong bảng ProductImage
                        shProductImageService _productImage = new shProductImageService();
                        _productImage.InsertAllImageProduct(product.ProductGuid, User.Identity.GetUserLogin().Userid, dsDesignImage, dsMaterialImage, null, null, true, DateTime.Now);

                        // 3. Delete Image
                        _productImage.DeleteAllImageProduct(DeleteImage);
                        dbContextTransaction.Commit();
                    }
                    catch (Exception ex)
                    {
                        dbContextTransaction.Rollback();
                    }
                }
            }

            int?page = CommonHelper.FindPageProduct(product.ProductGuid, product.ProductId, Config.PAGE_SIZE_20);

            return(RedirectToAction("Index", new { page }));
        }