コード例 #1
0
        public ServiceActionResult AddProductCategory(ProductCategoryDto productCategory)
        {
            if (productCategory == null)
            {
                return(new ServiceActionResult(ActionStatus.NotSuccessfull, "Product category cannot be null"));
            }
            if (productCategory.CategoryName.IsNullOrEmpty())
            {
                return(new ServiceActionResult(ActionStatus.NotSuccessfull, "Category name cannot be null or empty"));
            }
            if (productCategory.ShopGuid.IsEmptyGuid())
            {
                return(new ServiceActionResult(ActionStatus.NotSuccessfull, "Shop guid cannot be empty"));
            }

            Shop shop = _shopRepository.GetShopById(productCategory.ShopGuid);

            if (shop == null)
            {
                return(new ServiceActionResult(ActionStatus.NotSuccessfull, "Provided shop doesn't exist"));
            }
            ProductCategory category = _productCategoryRepository.GetProductCategoryByName(productCategory.ShopGuid, productCategory.CategoryName);

            if (category != null)
            {
                return(new ServiceActionResult(ActionStatus.NotSuccessfull, "Product category already exist"));
            }

            ProductCategory entity = productCategory.Map();

            entity.ProductCategoryShop = shop;
            _productCategoryRepository.AddToDatabase(entity);

            return(ServiceActionResult.Successfull);
        }
コード例 #2
0
        public ActionResult EditCategory(Guid productCategoryGuid)
        {
            ProductCategoryDto productCategory = _productCategoryRepository.GetProductCategory(productCategoryGuid);

            if (productCategory == null)
            {
                RedirectToMainView();
            }
            return(View(productCategory.Map()));
        }