Example #1
0
        public ActionResult OnCreate(ProductTypeModels productType)
        {
            if (ModelState.IsValid)
            {
                productType.ImageUrl = productType.Image != null?
                                       productType.Image.Upload() :
                                           productType.ImageUrl;

                productType.ImageBannerUrl = productType.ImageBanner != null?
                                             productType.ImageBanner.Upload() :
                                                 productType.ImageBannerUrl;

                var result = ProductTypeService.Insert(
                    productType.Name,
                    productType.ParentId,
                    productType.Icon,
                    productType.Description,
                    productType.ImageUrl,
                    productType.ImageBannerUrl,
                    productType.Number,
                    productType.CreatedDate,
                    productType.Status,
                    productType.IsHome
                    );
                if (result == Result.Exists)
                {
                    ModelState.AddModelError("", string.Format("Loại sản phẩm '{productType.Name}' đã tồn tại trên hệ thống."));
                    ViewBag.ListCategory = BuildListCategory();
                    return(View("Create", productType));
                }
                SetFlashMessage(string.Format("Thêm loại sản phẩm '{productType.Name}' thành công."));
                if (productType.SaveList)
                {
                    return(RedirectToAction("Index"));
                }
                ViewBag.ListCategory = BuildListCategory();
                ModelState.Clear();
                return(View("Create", productType.ResetValue()));
            }
            ViewBag.ListCategory = BuildListCategory();
            return(View("Create", productType));
        }
Example #2
0
        public ActionResult OnEdit(ProductTypeModels productType)
        {
            if (ModelState.IsValid)
            {
                productType.ImageUrl = productType.Image != null?
                                       productType.Image.Upload() :
                                           productType.ImageUrl.ToImageOriginalPath();

                productType.ImageBannerUrl = productType.ImageBanner != null?
                                             productType.ImageBanner.Upload() :
                                                 productType.ImageBannerUrl.ToImageOriginalPath();

                var result = ProductTypeService.Update(
                    productType.Id,
                    productType.Name,
                    productType.ParentId,
                    productType.Icon,
                    productType.Description,
                    productType.ImageUrl,
                    productType.ImageBannerUrl,
                    productType.Number,
                    productType.CreatedDate,
                    productType.Status,
                    productType.IsHome
                    );
                if (result == Result.NotExists)
                {
                    ModelState.AddModelError("", "Loại sản phẩm không tồn tại trên hệ thống.");
                    ViewBag.ListCategory = BuildListCategory();
                    return(View("Edit", productType));
                }
                SetFlashMessage(string.Format("Cập nhật loại sản phẩm '{productType.Name}' thành công."));
                if (productType.SaveList)
                {
                    return(RedirectToAction("Index"));
                }
                ViewBag.ListCategory = BuildListCategory();
                return(View("Edit", productType));
            }
            ViewBag.ListCategory = BuildListCategory();
            return(View("Edit", productType));
        }
Example #3
0
        public ActionResult Edit(int id)
        {
            var productTypeItem = ProductTypeService.Find(id);

            if (productTypeItem == null)
            {
                return(RedirectToAction("Index"));
            }
            ViewBag.ListCategory = BuildListCategory();
            var productTypeModel = new ProductTypeModels
            {
                Id             = productTypeItem.ID,
                Name           = productTypeItem.Name,
                ParentId       = productTypeItem.Parent ?? 0,
                Number         = productTypeItem.Number ?? 0,
                Status         = productTypeItem.Status.HasValue && productTypeItem.Status.Value,
                ImageUrl       = productTypeItem.Image,
                ImageBannerUrl = productTypeItem.ImageBanner,
                Icon           = productTypeItem.Icon,
                Description    = productTypeItem.Description
            };

            return(View("Edit", productTypeModel));
        }