Пример #1
0
 public ActionResult OnEdit(ProductStoreModels store)
 {
     if (ModelState.IsValid)
     {
         var result = ProductStoreService.Update(
             store.Id, store.Name, store.Phone,
             store.Manager, store.Address, store.CreatedAt,
             store.UpdatedAt, store.State);
         if (result == Result.NotExists)
         {
             ModelState.AddModelError("", "Kho hàng không tồn tại trên hệ thống.");
             ViewBag.ListState = DataHelper.ListEnumType <StateEnum>();
             return(View("Edit", store));
         }
         SetFlashMessage($"Cập nhật kho hàng '{store.Name}' thành công.");
         if (store.SaveList)
         {
             return(RedirectToAction("Index"));
         }
         ViewBag.ListState = DataHelper.ListEnumType <StateEnum>();
         return(View("Edit", store));
     }
     ViewBag.ListState = DataHelper.ListEnumType <StateEnum>();
     return(View("Edit", store));
 }
Пример #2
0
 public ActionResult OnCreate(ProductStoreModels store)
 {
     if (ModelState.IsValid)
     {
         var result = ProductStoreService.Insert
                      (
             store.Name,
             store.Phone,
             store.Manager,
             store.Address,
             store.CreatedAt,
             store.UpdatedAt,
             store.State
                      );
         if (result == Result.Exists)
         {
             ModelState.AddModelError("", $"Kho hàng '{store.Name}' đã tồn tại trên hệ thống.");
             ViewBag.ListState = DataHelper.ListEnumType <StateEnum>();
             return(View("Create", store));
         }
         SetFlashMessage($"Thêm kho hàng '{store.Name}' thành công.");
         if (store.SaveList)
         {
             return(RedirectToAction("Index"));
         }
         ViewBag.ListState = DataHelper.ListEnumType <StateEnum>();
         ModelState.Clear();
         return(View("Create", store.ResetValue()));
     }
     ViewBag.ListState = DataHelper.ListEnumType <StateEnum>();
     return(View("Create", store));
 }
Пример #3
0
        public ActionResult OnDelete(int id)
        {
            var result = ProductStoreService.Delete(id);

            SetFlashMessage(result == Result.Ok ?
                            "Xóa kho hàng thành công." :
                            "Kho hàng không tồn tại trên hệ thống.");
            return(RedirectToAction("Index"));
        }
Пример #4
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()));
 }
Пример #5
0
        public ActionResult Edit(int id)
        {
            var store = ProductStoreService.Find(id);

            if (store == null)
            {
                return(RedirectToAction("Index"));
            }
            ViewBag.ListState = DataHelper.ListEnumType <StateEnum>();
            var data = new ProductStoreModels
            {
                Id      = store.Id,
                Name    = store.Name,
                Phone   = store.Phone,
                Manager = store.Manager,
                Address = store.Address,
                State   = store.State
            };

            return(View("Edit", data));
        }
Пример #6
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));
        }
Пример #7
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));
        }
Пример #8
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));
        }
Пример #9
0
        public ActionResult Index()
        {
            var data = ProductStoreService.GetAll();

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