Пример #1
0
        public async Task <IActionResult> NewProductCategory(SaveProductCategoryDto saveProductCategoryResource)
        {
            var productCategory = _mapper.Map <SaveProductCategoryDto, ProductCategory>(saveProductCategoryResource);
            await _productCategoryService.AddProductCategory(productCategory);

            return(RedirectToAction("ProductCategoryList"));
        }
Пример #2
0
        public ActionResult AddProductCategory(ProductCategoryViewModel productCategory)
        {
            if (!ModelState.IsValid)
            {
                return(AddProductCategory());
            }
            ProductCategoryDto productCategoryDto = productCategory.Map();

            Guid shopGuid;

            if (!Session.TryGetKey(SessionKeys.ShopAdminSelectedShopGuid, out shopGuid))
            {
                return(View("ShopNotFound"));
            }

            productCategoryDto.ShopGuid = shopGuid;

            ServiceActionResult result = _productCategoryService.AddProductCategory(productCategoryDto);

            if (result.Status != ServiceActionResult.Successfull.Status)
            {
                return(AddProductCategory());
            }

            return(RedirectToMainView());
        }
        public ActionResult Create([Bind(Exclude = "Id")] ProductCategoryViewModel viewModel)
        {
            if (!ModelState.IsValid)
            {
                viewModel.Heading = "Add category";

                return(View("CategoryForm", viewModel));
            }

            _productCategoryService.AddProductCategory(viewModel);

            return(RedirectToAction("Index", "ProductCategory"));
        }
        public JsonResult AddOrEditProductCategory(ProductCategoryViewModel model)
        {
            try
            {
                if (model.IsAdd)
                {
                    ProductCategory cate = new ProductCategory
                    {
                        FolderName          = model.FolderName,
                        ProductCategoryName = model.ProductCategoryName,
                        CreatedDate         = DateTime.Now
                    };

                    _prodCateService.AddProductCategory(cate);

                    ProductCategoryExtend cateEx = new ProductCategoryExtend
                    {
                        ProductCategoryId = cate.ProductCategoryId,
                        FileName          = model.FileUpload.FileName,
                        FileSize          = model.FileUpload.ContentLength,
                        FilePath          = Util.CreateProductCategoryImage(model.FileUpload, User.Identity.GetUserId())
                    };

                    _prodCateService.AddProductCategoryExtend(cateEx);

                    var category = new
                    {
                        ProductCategoryName = cate.ProductCategoryName,
                        FilePath            = cate.ProductCategoryExtend.FilePath,
                        ProductCategoryId   = cate.ProductCategoryId,
                        FolderName          = cate.FolderName
                    };

                    return(Json(new { success = true, category = category, IsAdd = true }));
                    //return Json(true);
                }
                else
                {
                    var cate = _prodCateService.GetProductCategoryById(model.ProductCategoryId);
                    if (model.FileUpload == null)
                    {
                        cate.ProductCategoryName = model.ProductCategoryName;
                        _prodCateService.Save();
                    }
                    else
                    {
                        Util.DeleteFileLocal(cate.ProductCategoryExtend.FilePath);
                        cate.ProductCategoryExtend.FilePath = Util.CreateProductCategoryImage(model.FileUpload, User.Identity.GetUserId());
                        cate.ProductCategoryExtend.FileName = model.FileUpload.FileName;
                        cate.ProductCategoryExtend.FileSize = model.FileUpload.ContentLength;
                        cate.ProductCategoryName            = model.ProductCategoryName;
                        _prodCateService.Save();
                    }
                    var category = new
                    {
                        ProductCategoryName = cate.ProductCategoryName,
                        FilePath            = cate.ProductCategoryExtend.FilePath,
                        ProductCategoryId   = cate.ProductCategoryId,
                        FolderName          = cate.FolderName
                    };

                    return(Json(new { success = true, category = category, IsAdd = false }));
                }
            }
            catch
            {
                return(Json(new { success = false }));
            }
        }
 public async Task <string> AddProductCategory([FromBody] ProductCategoryRequest request)
 {
     return(await _productCategoryService.AddProductCategory(request));
 }