Example #1
0
        public async Task DeleteProductCategory_InvokreRepositoryAndClearCache()
        {
            //var collectonMock = new Mock<IMongoCollection<Product>>();
            //_productRepositoryMock.Setup(p => p.Collection).Returns(collectonMock.Object);
            await _productCategoryService.DeleteProductCategory(new ProductCategory(), "1");

            //TODO
            //collectonMock.Verify(c => c.UpdateOneAsync(It.IsAny<FilterDefinition<Product>>(), It.IsAny<UpdateDefinition<Product>>(), null, default(CancellationToken)), Times.Once);
            _mediatorMock.Verify(c => c.Publish(It.IsAny <EntityDeleted <ProductCategory> >(), default(CancellationToken)), Times.Once);
            //clear product cache and ProductCategory
            _casheManagerMock.Verify(c => c.RemoveByPrefix(It.IsAny <string>(), true), Times.Exactly(2));
        }
        public ActionResult Delete(int CATEGORY_ID = 0)
        {
            if (Request.IsAjaxRequest())
            {
                if (ModelState.IsValid && CATEGORY_ID > 0)
                {
                    using (var service = new ProductCategoryService())
                    {
                        var deleteResult = service.DeleteProductCategory(CATEGORY_ID);

                        JsonResult result = Json(new
                        {
                            statusCode = deleteResult ? Constant.SUCCESSFUL : Constant.INTERNAL_SERVER_ERROR
                        }, JsonRequestBehavior.AllowGet);

                        return(result);
                    }
                }
                else
                {
                    var errors = ModelState.Where(x => x.Value.Errors.Count > 0).Select(x => new { x.Key, x.Value.Errors }).ToArray();
                }
            }

            return(new EmptyResult());
        }
        public string DeleteProductCategory(int ID)
        {
            string result = "Fail";

            // Just update isDelete in Product Category not delete
            if (_productCategoryService.DeleteProductCategory(ID))
            {
                result = "Success";
            }

            return(result);
        }
Example #4
0
        public ActionResult Delete(int id, ProductCategoryViewModel model)
        {
            try
            {
                bool result = _productCategoryService.DeleteProductCategory(id);

                if (result)
                {
                    return(RedirectToAction(nameof(Index)));
                }
                throw new Exception();
            }
            catch
            {
                ModelState.AddModelError(string.Empty, "Ooops! Something went wrong!");
                return(View());
            }
        }