Exemple #1
0
 public ActionResult Create()
 {
     ViewBag.ListCategory     = BuildListCategory();
     ViewBag.ListBrand        = ProductBrandService.GetAll();
     ViewBag.ListCountry      = CountryService.GetAll();
     ViewBag.ListStore        = ProductStoreService.GetAll();
     ViewBag.ListManufacturer = ProductManufacturerService.GetAll();
     ViewBag.ListUnit         = UnitService.GetAll();
     ViewBag.ListColor        = BuildListColor();
     ViewBag.ListSize         = BuildListSize();
     ViewBag.ListHour         = DataHelper.ListHour;
     return(View("Create", new ProductModels()));
 }
Exemple #2
0
        public ActionResult OnEdit(ProductModels product)
        {
            var productUpdate = ProductService.Find(product.Id);

            if (productUpdate != null)
            {
                if (string.IsNullOrWhiteSpace(product.Code))
                {
                    product.Code = $"MP-{DateTime.Now.Ticks.GetHashCode()}";
                }
                product.ImageUrl = product.Image != null?
                                   product.Image.Upload() :
                                       product.ImageUrl.ToImageOriginalPath();

                productUpdate.Name         = product.Name;
                productUpdate.Type         = product.CategoryId;
                productUpdate.Summary      = product.Summary;
                productUpdate.Code         = product.Code;
                productUpdate.Image        = product.ImageUrl;
                productUpdate.BrandId      = product.BrandId;
                productUpdate.Country      = product.Country;
                productUpdate.Store        = product.Store;
                productUpdate.Manufacturer = product.ManufacturerId;
                productUpdate.AccountId    = product.AccountId;
                productUpdate.Number       = product.Number;
                productUpdate.Unit1        = product.Unit;
                productUpdate.Weight       = product.Weight;
                productUpdate.Quantity     = product.Quantity;
                productUpdate.Npp          = Convert.ToDouble(product.Npp);
                productUpdate.Width        = product.Width;
                productUpdate.Height       = product.Height;
                productUpdate.Depth        = product.Depth;
                productUpdate.Detail       = product.Detail;
                productUpdate.WarrantyTime = product.WarrantyTime;
                productUpdate.ExpireDate   = product.ExpireDate;
                productUpdate.Title        = product.MetaTitle;
                productUpdate.Keyword      = product.MetaKeyword;
                productUpdate.Description  = product.MetaDescription;
                productUpdate.Price        = product.Price;
                productUpdate.Transport1   = product.Transport1;
                productUpdate.Transport2   = product.Transport2;
                var result = ProductService.Update(productUpdate);
                //Tao cac anh san pham
                if (product.ProductImages != null && product.ProductImages.Length > 0)
                {
                    ProductImageService.Insert(productUpdate.ID, product.Name, product.ProductImages);
                }
                //Tao cac gia tri thuoc tinh
                if (product.AttrLabel != null && product.AttrLabel.Length > 0)
                {
                    ProductAttributeService.Insert(productUpdate.ID, product.AttrLabel, product.AttrDesc);
                }
                //Tao saleOff
                if (!string.IsNullOrWhiteSpace(product.Percent))
                {
                    ProductSaleOffService.Insert(new ProductSaleOff
                    {
                        ProductID = productUpdate.ID,
                        Percent   = Convert.ToDouble(product.Percent),
                        StartTime = Convert.ToDateTime(product.StartDate),
                        EndTime   = Convert.ToDateTime(product.EndDate)
                    });
                }
                //Tao kich co
                if (product.Size != null && product.Size.Length > 0)
                {
                    ProductSizeService.Insert(productUpdate.ID, product.Size);
                }
                //Tao mau sac
                if (product.Color != null && product.Color.Length > 0)
                {
                    ProductColorService.Insert(productUpdate.ID, product.Color);
                }

                SetFlashMessage(result == Result.Ok?
                                $"Cập nhật sản phẩm '{product.Name}' thành công.":
                                "Lỗi khi cập nhật sản phẩm '{product.Name}'"
                                );
                if (product.SaveList)
                {
                    return(RedirectToAction("Index"));
                }
                ViewBag.ListCategory     = BuildListCategory();
                ViewBag.ListBrand        = ProductBrandService.GetAll();
                ViewBag.ListCountry      = CountryService.GetAll();
                ViewBag.ListStore        = ProductStoreService.GetAll();
                ViewBag.ListManufacturer = ProductManufacturerService.GetAll();
                ViewBag.ListUnit         = UnitService.GetAll();
                ViewBag.ListColor        = BuildListColor(product.Color);
                ViewBag.ListSize         = BuildListSize(product.Size);
                ViewBag.ListHour         = DataHelper.ListHour;
                return(View("Edit", product));
            }
            ViewBag.ListBrand        = ProductBrandService.GetAll();
            ViewBag.ListCountry      = CountryService.GetAll();
            ViewBag.ListStore        = ProductStoreService.GetAll();
            ViewBag.ListManufacturer = ProductManufacturerService.GetAll();
            ViewBag.ListUnit         = UnitService.GetAll();
            ViewBag.ListColor        = BuildListColor(product.Color);
            ViewBag.ListSize         = BuildListSize(product.Size);
            ViewBag.ListHour         = DataHelper.ListHour;
            return(View("Edit", product));
        }
Exemple #3
0
        public ActionResult Edit(int id)
        {
            var product = ProductService.FindToModify(id);

            if (product == null)
            {
                return(RedirectToAction("Index"));
            }
            var modelEdit = new ProductModels
            {
                Id                   = product.ID,
                Name                 = product.Name,
                ImageUrl             = product.Image,
                CategoryId           = product.Type ?? 0,
                Code                 = product.Code,
                BrandId              = product.BrandId,
                Store                = product.Store,
                Country              = product.Country,
                ManufacturerId       = product.Manufacturer,
                AccountId            = product.AccountId,
                Number               = product.Number ?? 0,
                Unit                 = product.Unit1,
                Quantity             = product.Quantity,
                Weight               = product.Weight,
                Npp                  = product.Npp?.ToString() ?? "",
                Width                = product.Width,
                Height               = product.Height,
                Depth                = product.Depth,
                Summary              = product.Summary,
                Detail               = product.Detail,
                WarrantyTime         = product.WarrantyTime,
                ExpireDate           = product.ExpireDate,
                Transport1           = product.Transport1 ?? 0,
                Transport2           = product.Transport2 ?? 0,
                MetaTitle            = product.Title,
                MetaDescription      = product.Description,
                MetaKeyword          = product.Keyword,
                Price                = (int)(product.Price ?? 0),
                ListProductImages    = product.ProductImages?.ToList() ?? new List <ProductImage>(),
                ListProductAttribute = product.ProductAttribute?.ToList() ?? new List <ProductAttribute>(),
            };

            if (product.ProductSaleOff != null && product.ProductSaleOff.Count > 0)
            {
                var saleOffItem = product.ProductSaleOff.FirstOrDefault();
                modelEdit.Percent   = saleOffItem.Percent?.ToString() ?? "";
                modelEdit.StartDate = saleOffItem.StartTime?.ToString() ?? "";
                modelEdit.EndDate   = saleOffItem.EndTime?.ToString() ?? "";
            }

            ViewBag.ListCategory     = BuildListCategory();
            ViewBag.ListBrand        = ProductBrandService.GetAll();
            ViewBag.ListCountry      = CountryService.GetAll();
            ViewBag.ListStore        = ProductStoreService.GetAll();
            ViewBag.ListManufacturer = ProductManufacturerService.GetAll();
            ViewBag.ListUnit         = UnitService.GetAll();
            ViewBag.ListColor        = BuildListColor(
                product.ProductColor?.Select(item => item.ColorCode).ToArray());
            ViewBag.ListSize =
                BuildListSize(product.ProductSize?.Select(item => item.Size).ToArray());
            ViewBag.ListHour = DataHelper.ListHour;

            return(View("Edit", modelEdit));
        }
Exemple #4
0
        public ActionResult OnCreate(ProductModels product)
        {
            if (ModelState.IsValid)
            {
                if (string.IsNullOrWhiteSpace(product.Code))
                {
                    product.Code = string.Format("{0}-{1}", ConfigHelper.ProductCode, DateTime.Now.Ticks.GetHashCode());
                }
                product.ImageUrl = product.Image != null?
                                   product.Image.Upload() :
                                       product.ImageUrl;

                var newProduct = new Product
                {
                    Name         = product.Name,
                    Type         = product.CategoryId,
                    Summary      = product.Summary,
                    Code         = product.Code,
                    Image        = product.ImageUrl,
                    BrandId      = product.BrandId,
                    Country      = product.Country,
                    Store        = product.Store,
                    Manufacturer = product.ManufacturerId,
                    AccountId    = 0,
                    Number       = product.Number,
                    Unit1        = product.Unit,
                    Weight       = product.Weight,
                    Quantity     = product.Quantity,
                    Npp          = Convert.ToDouble(product.Npp),
                    Width        = product.Width,
                    Height       = product.Height,
                    Depth        = product.Depth,
                    Detail       = product.Detail,
                    WarrantyTime = product.WarrantyTime,
                    ExpireDate   = product.ExpireDate,
                    Title        = product.MetaTitle,
                    Keyword      = product.MetaKeyword,
                    Description  = product.MetaDescription,
                    Price        = product.Price,
                    Transport1   = product.Transport1,
                    Transport2   = product.Transport2,
                    Status       = false
                };
                var result = ProductService.Insert(newProduct);

                //Tao cac anh Slide va properties
                if (product.ProductImages != null && product.ProductImages.Length > 0)
                {
                    ProductImageService.Insert(newProduct.ID, product.Name, product.ProductImages);
                }
                //Tao cac gia tri thuoc tinh
                if (product.AttrLabel != null && product.AttrLabel.Length > 0)
                {
                    ProductAttributeService.Insert(newProduct.ID, product.AttrLabel, product.AttrDesc);
                }
                //Tao saleOff
                if (!string.IsNullOrWhiteSpace(product.Percent))
                {
                    ProductSaleOffService.Insert(new ProductSaleOff
                    {
                        ProductID = newProduct.ID,
                        Percent   = Convert.ToDouble(product.Percent),
                        StartTime = Convert.ToDateTime(product.StartDate),
                        EndTime   = Convert.ToDateTime(product.EndDate)
                    });
                }
                //Tao kich co
                if (product.Size != null && product.Size.Length > 0)
                {
                    ProductSizeService.Insert(newProduct.ID, product.Size);
                }
                //Tao mau sac
                if (product.Color != null && product.Color.Length > 0)
                {
                    ProductColorService.Insert(newProduct.ID, product.Color);
                }
                SetFlashMessage(result == Result.Ok?
                                $"Thêm sản phẩm '{product.Name}' thành công.":
                                "Lỗi khi thêm mới sản phẩm");
                if (product.SaveList)
                {
                    return(RedirectToAction("Index"));
                }
                ViewBag.ListCategory     = BuildListCategory();
                ViewBag.ListBrand        = ProductBrandService.GetAll();
                ViewBag.ListCountry      = CountryService.GetAll();
                ViewBag.ListStore        = ProductStoreService.GetAll();
                ViewBag.ListManufacturer = ProductManufacturerService.GetAll();
                ViewBag.ListUnit         = UnitService.GetAll();
                ViewBag.ListColor        = BuildListColor(product.Color);
                ViewBag.ListSize         = BuildListSize(product.Size);
                ViewBag.ListHour         = DataHelper.ListHour;
                ModelState.Clear();
                return(View("Create", product.ResetValue()));
            }
            ViewBag.ListCategory     = BuildListCategory();
            ViewBag.ListBrand        = ProductBrandService.GetAll();
            ViewBag.ListCountry      = CountryService.GetAll();
            ViewBag.ListStore        = ProductStoreService.GetAll();
            ViewBag.ListManufacturer = ProductManufacturerService.GetAll();
            ViewBag.ListUnit         = UnitService.GetAll();
            ViewBag.ListColor        = BuildListColor(product.Color);
            ViewBag.ListSize         = BuildListSize(product.Size);
            ViewBag.ListHour         = DataHelper.ListHour;

            return(View("Create", product));
        }
Exemple #5
0
        public ActionResult Index()
        {
            var data = ProductStoreService.GetAll();

            return(View("Index", data));
        }