Beispiel #1
0
        public async Task DeleteAsync(ProductDeleteServiceModel procuct)
        {
            var productForDelete = this.db.Products.Where(a => a.Id == procuct.Id).First();

            this.db.Products.Remove(productForDelete);

            await this.db.SaveChangesAsync();
        }
Beispiel #2
0
        public IActionResult DeleteConfirmed(ProductDeleteServiceModel product)
        {
            if (!ModelState.IsValid)
            {
                return(RedirectToAction(nameof(ProductController.Delete), new { id = product.Id }));
            }

            this.productService.DeleteAsync(product);

            TempData[WebConstants.TempDataSuccessMessageKey] = ($"Product {product.Title} successfuly deleted.");
            return(RedirectToAction(nameof(ProductController.Index), new { page = 1 }));
        }
Beispiel #3
0
        public async Task <IActionResult> Delete(int id)
        {
            var product = await this.productService.ByIdAsync(id);

            if (product == null)
            {
                return(BadRequest());
            }

            var productForDelete = new ProductDeleteServiceModel
            {
                Id    = id,
                Title = product.Title
            };

            return(View(productForDelete));
        }