Beispiel #1
0
        public ActionResult OnEdit(ProductManufacturerModels manufacturer)
        {
            if (ModelState.IsValid)
            {
                manufacturer.ImageUrl = manufacturer.Image != null?
                                        manufacturer.Image.Upload() :
                                            manufacturer.ImageUrl.ToImageOriginalPath();

                var result = ProductManufacturerService.Update(
                    manufacturer.Id, manufacturer.Name,
                    manufacturer.ImageUrl, manufacturer.Detail,
                    manufacturer.Status, manufacturer.Order,
                    manufacturer.CreatedDate);
                if (result == Result.NotExists)
                {
                    ModelState.AddModelError("", "Nhà sản xuất tồn tại trên hệ thống.");
                    return(View("Edit", manufacturer));
                }
                SetFlashMessage(string.Format("Cập nhật nhà sản xuất '{0}' thành công.", manufacturer.Name));
                if (manufacturer.SaveList)
                {
                    return(RedirectToAction("Index"));
                }
                return(View("Edit", manufacturer));
            }
            return(View("Edit", manufacturer));
        }
Beispiel #2
0
        public ActionResult OnCreate(ProductManufacturerModels manufacturer)
        {
            if (ModelState.IsValid)
            {
                manufacturer.ImageUrl = manufacturer.Image != null?
                                        manufacturer.Image.Upload() :
                                            manufacturer.ImageUrl;

                var result = ProductManufacturerService.Insert
                             (
                    manufacturer.Name, manufacturer.ImageUrl,
                    manufacturer.Detail, manufacturer.Status,
                    manufacturer.Order, manufacturer.CreatedDate
                             );
                if (result == Result.Exists)
                {
                    ModelState.AddModelError("", string.Format("Tên Nhà sản xuất '{manufacturer.Name}' đã tồn tại trên hệ thống."));
                    return(View("Create", manufacturer));
                }
                SetFlashMessage(string.Format("Thêm Nhà sản xuất '{manufacturer.Name}' thành công."));
                if (manufacturer.SaveList)
                {
                    return(RedirectToAction("Index"));
                }
                ModelState.Clear();
                return(View("Create", manufacturer.ResetValue()));
            }
            return(View("Create", manufacturer));
        }
Beispiel #3
0
        public ActionResult OnDelete(int id)
        {
            var result = ProductManufacturerService.Delete(id);

            SetFlashMessage(result == Result.Ok ?
                            "Xóa nhà sản xuất thành công." :
                            "Nhà sản xuất không tồn tại trên hệ thống.");
            return(RedirectToAction("Index"));
        }
Beispiel #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()));
 }
Beispiel #5
0
        public ActionResult Index(
            string keyword = "", int categoryId = 0,
            int quantity   = 0, int state       = 0, int brand = 0,
            int manufact   = 0, int provider    = 0,
            int page       = 1, int pageSize    = 25)
        {
            int totalRecords = 0;
            int totalPages   = 0;
            var data         = ProductService.GetList(out totalRecords,
                                                      categoryId, quantity, state,
                                                      brand, manufact, provider,
                                                      keyword, page, pageSize);

            if (totalRecords > 0)
            {
                totalPages = totalRecords / pageSize;
                if (totalRecords % pageSize > 0)
                {
                    totalPages += 1;
                }
            }
            var model = new ProductViewModels
            {
                Keyword      = keyword,
                State        = state,
                CategoryId   = categoryId,
                Quantity     = quantity,
                Data         = data,
                Page         = page,
                PageSize     = pageSize,
                TotalPages   = totalPages,
                TotalRecords = totalRecords,
                Brand        = brand,
                Manufact     = manufact,
                Provider     = provider
            };

            ViewBag.ListStateFilter    = DataHelper.ListEnumType <StateFilterEnum>();
            ViewBag.ListQuantityFilter = DataHelper.ListEnumType <QuantityFilterEnum>();
            ViewBag.ListBrand          = ProductBrandService.GetAll();
            ViewBag.ListManufacturer   = ProductManufacturerService.GetAll();
            ViewBag.ListProvider       = AccountService.GetListAdminByType((byte)AccountType.Provider);
            ViewBag.ListCategory       = BuildListCategory();
            return(View("Index", model));
        }
Beispiel #6
0
        public ActionResult Edit(int id)
        {
            var manufacturer = ProductManufacturerService.Find(id);

            if (manufacturer == null)
            {
                return(RedirectToAction("Index"));
            }

            var data = new ProductManufacturerModels
            {
                Id       = manufacturer.ID,
                Name     = manufacturer.Name,
                ImageUrl = manufacturer.Image,
                Detail   = manufacturer.Detail,
                Status   = manufacturer.Status ?? false,
                Order    = manufacturer.Number ?? 0
            };

            return(View("Edit", data));
        }
Beispiel #7
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));
        }
Beispiel #8
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));
        }
Beispiel #9
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));
        }
Beispiel #10
0
        public ActionResult Index()
        {
            var data = ProductManufacturerService.GetAll();

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