public async Task <IActionResult> Delete(int productId) { Product product = _productsService.Products.FirstOrDefault(p => p.Id == productId); string category = null; if (product.Category != null) { category = product.Category.Name != null ? product.Category.Name : null; } Product mainProduct = _productsService.Products.FirstOrDefault(p => p.Products.Contains(product)); Product deletedProduct = await _productsService.DeleteProductAsync(productId); if (deletedProduct != null) { TempData["message"] = $"{deletedProduct.Name} was deleted"; } if (mainProduct != null) { var viewModel = CreateAdminViewModel(mainProduct); return(View("Edit", viewModel)); } if (category != null) { return(RedirectToAction("Admin/List", category)); } return(RedirectToAction("Index")); }
public async Task <IActionResult> Delete(int productId) { Product deletedProduct = await _productsService.DeleteProductAsync(productId); if (deletedProduct != null) { TempData["message"] = $"{deletedProduct.Name} was deleted"; } return(RedirectToAction("Index")); }
public async Task <IActionResult> DeleteProductAsync(Guid id) { var deleted = await ProductsService.DeleteProductAsync(id); if (deleted) { return(Ok()); } return(NotFound()); }
public async Task DeleteProductAsync_GivenAValidScenario_ShouldNotThrowAnException() { IUnitOfWork <IBoltDbContext> unitOfWorkMock = new Mock <IUnitOfWork <IBoltDbContext> >().Object; const int productId = 2; var service = new ProductsService(unitOfWorkMock); Action result = async() => await service.DeleteProductAsync(productId); result.Should().NotThrow(); }
public async Task <ActionResult> DeleteProductAsync(ProductInfo product) { await ProductsService.DeleteProductAsync(product.Id, product.CategoryName); return(RedirectToAction("Index")); }