public ActionResult DeleteAll(int[] ids)
        {
            //1. requirement when opening a transaction: connection has to be opened

            ProductsRepository pr = new ProductsRepository();

            pr.MyConnection.Open();

            pr.MyTransaction = pr.MyConnection.BeginTransaction(); //from this point all code executed against the db will remail pending

            try
            {
                foreach (int id in ids)
                {
                    pr.DeleteProduct(id);
                }

                pr.MyTransaction.Commit(); //Commit: you are confirming the changes in the db
            }
            catch (Exception ex)
            {
                //log the exeption on the cloud
                new LogsRepository().LogError(ex);
                pr.MyTransaction.Rollback(); // Rollback: it will reverse all the changes done within the try-clause in the db
            }

            pr.MyConnection.Close();

            return(RedirectToAction("Index"));
        }
        public IActionResult Delete(int productId, int shoppingId)
        {
            var repo = new ProductsRepository(_connectionString);

            repo.DeleteProduct(productId, shoppingId);
            return(RedirectToAction("ViewCart"));
        }
Esempio n. 3
0
        public ActionResult DeleteProduct(int id)
        {
            var repo = new ProductsRepository();

            repo.DeleteProduct(id);
            return(Redirect("/Products/Index"));
        }
Esempio n. 4
0
 [HttpPost] //т.к. удаление статьи изменяет состояние приложения, нельзя использовать метод GET
 public IActionResult ProductDelete(int id)
 {
     productRepository.DeleteProduct(new Product()
     {
         Id = id
     });
     return(RedirectToAction("Index"));
 }
Esempio n. 5
0
 public ActionResult Delete(int id)
 {
     if (ModelState.IsValid)
     {
         _repo.DeleteProduct(id);
         return(RedirectToAction("Index"));
     }
     return(View());
 }
Esempio n. 6
0
        public void DeleteProductNotFound()
        {
            var options = EfInMemory.CreateOptions <ProductsContext>();

            using (var context = new ProductsContext(options))
            {
                var logger     = new Mock <ILogger <ProductsRepository> >();
                var repository = new ProductsRepository(context, logger.Object);
                Assert.Throws <KeyNotFoundException>(() => repository.DeleteProduct(ProductMocks.NewProductiPhoneXS));
            }
        }
Esempio n. 7
0
        public void DeleteProductSuccess()
        {
            var options = EfInMemory.CreateOptions <ProductsContext>();

            using (var context = new ProductsContext(options))
            {
                context.FeedDataContext(ProductMocks.ProductsBaseDataset);
                var logger     = new Mock <ILogger <ProductsRepository> >();
                var repository = new ProductsRepository(context, logger.Object);
                repository.DeleteProduct(ProductMocks.ProductSamsungGalaxyS7).ShouldBeTrue();
            }
        }
Esempio n. 8
0
        public ActionResult Delete(int id, FormCollection collection)
        {
            try
            {
                productRepository.DeleteProduct(id);

                return(RedirectToAction("Index"));
            }
            catch
            {
                return(View("DeleteProduct"));
            }
        }
 public ActionResult Delete(int id)
 {
     try
     {
         ProductsRepository pr = new ProductsRepository();
         pr.DeleteProduct(id);
     }
     catch (Exception ex)
     {
         new LogsRepository().LogError(ex);
     }
     return(RedirectToAction("Index"));
 }
Esempio n. 10
0
        //we did string isb in the parameters sos htat the user must input only the isbn not all the book details
        public void DeleteProduct(int productId)
        {
            ProductsRepository pr = new ProductsRepository();

            if (pr.GetProduct(productId) != null)
            {
                pr.DeleteProduct(pr.GetProduct(productId));
            }
            else
            {
                throw new Exception("Product does not exist");
            }
        }
        public void DeleteProduct_ShouldDelete_VerifyProductNotExists()
        {
            // Arrange
            var repository = new ProductsRepository();

            // Act
            var deleted = repository.DeleteProduct(1);
            var product = repository.GetProduct(1);


            // Assert
            Assert.IsTrue(deleted);
            Assert.IsNull(product);
        }
Esempio n. 12
0
 public ActionResult Delete(Products products)
 {
     try
     {
         ProductsRepository proRepo = new ProductsRepository();
         ModelState.Clear();
         int deleted = proRepo.DeleteProduct(products.Id);
         return(RedirectToAction("GetAllProDetails", "Products"));
     }
     catch (Exception ex)
     {
         LogError.Error(ex, System.Reflection.MethodBase.GetCurrentMethod().Name);
         return(RedirectToAction("ErrorPage", "Home"));
     }
 }
Esempio n. 13
0
 private void removeProduct()
 {
     if (Product == null)
     {
         MessageBox.Show("You have to select element on the list first.", "Warning");
         return;
     }
     try
     {
         _productsRepository.DeleteProduct(Product);
         updateData();
     }
     catch (Exception e)
     {
         MessageBox.Show("Problem occured while removing product", "Error");
     }
 }
        public RedirectToPageResult OnPostDelete(int productId)
        {
            bool deleted = ProductsRepository.DeleteProduct(productId);

            if (deleted)
            {
                TempData["ProductMessage"] = $"Product met productId {productId} is verwijderd";
            }
            else
            {
                //zou in principe niet moeten gebeuren!
                TempData["ProductMessage"] = $"Product met productId {productId} is niet verwijderd";
            }


            return(RedirectToPage("Index"));
        }
Esempio n. 15
0
        public BaseResponse DeleteProduct(int productId)
        {
            BaseResponse productResponse = new BaseResponse();

            try
            {
                repository.DeleteProduct(productId);
                productResponse.Success = true;
            }
            catch (Exception ex)
            {
                productResponse.Success    = false;
                productResponse.Message    = ex.Message;
                productResponse.StackTrace = ex.StackTrace;
            }

            return(productResponse);
        }
Esempio n. 16
0
        public ActionResult DeleteProduct(int id)
        {
            _productRepository.DeleteProduct(id);

            return(Ok("Your Parting Pets Product Has Been Deleted. ;) Wink Wink."));
        }
 [ValidateAntiForgeryToken] // Μην ξεχάσεις @Ηtml.ValidateAntiForgeryToken() στο view
 public ActionResult DeleteProductSubmit(Product product)
 {
     productsRepository.DeleteProduct(product);
     return(RedirectToAction("Product", "Product"));
 }
Esempio n. 18
0
 public IActionResult Product_Delete(string id = "")
 {
     productsFactory.DeleteProduct(id);
     ViewBag.User_one = ecommFactory.CurrentUser((int)HttpContext.Session.GetInt32("current_id"));
     return(RedirectToAction("YourProducts"));
 }
Esempio n. 19
0
 public void OnPostDelete(int productId)
 {
     Products = _productRepository.DeleteProduct(productId);
 }