コード例 #1
0
        public async Task Delete_Existing_RemovesFromDatabase()
        {
            var opt = new DbContextOptionsBuilder <ProductContext>()
                      .UseInMemoryDatabase(nameof(Delete_Existing_RemovesFromDatabase))
                      .Options;
            var     request = new ProductRequest("Coconut", 0.5f);
            Product createdProduct;

            await using (var ctx = new ProductContext(opt))
            {
                var service = new ProductsRepository(ctx);
                createdProduct = await service.Create(request);
            }

            await using (var ctx = new ProductContext(opt))
            {
                var service = new ProductsRepository(ctx);
                await service.Delete(createdProduct.Id);
            }

            await using (var ctx = new ProductContext(opt))
            {
                Assert.AreEqual(0, ctx.Products.Count());
            }
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: gpdoud/Ef2Sql-DNBC7
        void TestProductsRepository()
        {
            var newproduct = new Products()
            {
                PartNbr  = "ZZZ", Name = "ZZZ",
                Price    = 10.99M, Unit = "Each", PhotoPath = null,
                VendorId = VendorsRepository.GetByPk(3).Id
            };

            if (!ProductsRepository.Insert(newproduct))
            {
                throw new Exception("Product insert failed!");
            }
            DisplayAllProducts();
            newproduct.Name = "YYY";
            if (!ProductsRepository.Update(newproduct))
            {
                throw new Exception("Product update failed!");
            }
            DisplayAllProducts();
            if (!ProductsRepository.Delete(newproduct))
            {
                throw new Exception("Product delete failed!");
            }
            DisplayAllProducts();
        }
コード例 #3
0
        internal string Delete(int id)
        {
            var data = GetById(id);

            _repo.Delete(id);
            return("delorted");
        }
コード例 #4
0
        public HttpResponseMessage Delete(long id)
        {
            var repo    = new ProductsRepository();
            var results = repo.Delete(id);

            return(results == 1 ? Request.CreateResponse(HttpStatusCode.OK) : Request.CreateErrorResponse(HttpStatusCode.InternalServerError, "A product with that id already exists"));
        }
コード例 #5
0
        //DELORT
        internal Product Delete(string id)
        {
            Product original = GetById(id);

            _repo.Delete(id);
            return(original);;
        }
コード例 #6
0
ファイル: ProductsController.cs プロジェクト: Yceali/MVC_P1
 public ActionResult DeleteUrun(int id)
 {
     if (ModelState.IsValid)
     {
         productsRepository.Delete(productsRepository.Get(id));
     }
     return(RedirectToAction("Index"));
 }
コード例 #7
0
        public IActionResult Delete(int id)
        {
            var repository = new ProductsRepository();

            repository.Delete(id);

            return(NoContent());
        }
コード例 #8
0
        public ActionResult Delete(int id)
        {
            ProductsRepository repo = new ProductsRepository();
            Product            item = repo.GetById(id);

            repo.Delete(item);

            return(RedirectToAction("Index", "Products"));
        }
コード例 #9
0
        public async Task <IActionResult> Delete(int id)
        {
            bool result = await _productHelper.Delete(id);

            if (result)
            {
                return(Ok(new { Message = "Silme işlemi başarılı :)" }));
            }

            return(BadRequest(new { Message = "Silme işlemi başarısız :(" }));
        }
コード例 #10
0
        public IHttpActionResult Delete(int id)
        {
            var res = productsRepo.GetById(id);

            if (res == null)
            {
                return(NotFound());
            }
            productsRepo.Delete(id);
            return(StatusCode(HttpStatusCode.NoContent));
        }
コード例 #11
0
        public async Task Delete_NotExisting_ThrowsProductNotFoundException()
        {
            var opt = new DbContextOptionsBuilder <ProductContext>()
                      .UseInMemoryDatabase(nameof(Delete_NotExisting_ThrowsProductNotFoundException))
                      .Options;

            await using var ctx = new ProductContext(opt);
            var service = new ProductsRepository(ctx);

            Assert.ThrowsAsync <ProductNotFoundException>(() => service.Delete(12));
        }
コード例 #12
0
        internal string Delete(int id, string userId)
        {
            var original = GetById(id);

            if (original.CreatorId != userId)
            {
                throw new Exception("Invalid Delete Permissions");
            }
            _repo.Delete(id);
            return("delorted");
        }
コード例 #13
0
        internal string Delete(int id, string userId)
        {
            var data = GetById(id);

            if (data.CreatorId != userId)
            {
                throw new Exception("Invalid Edit Permissions");
            }
            _repo.Delete(id);
            return("delorted");
        }
コード例 #14
0
 public ActionResult Delete(Product product)
 {
     try
     {
         _repository.Delete(product.Id);
         return(RedirectToAction(nameof(Index)));
     }
     catch (ProductNotFoundException)
     {
         return(HttpNotFound());
     }
 }
コード例 #15
0
 public ActionResult Delete(int id, FormCollection collection)
 {
     try
     {
         _productRepository.Delete(id);
         return(RedirectToAction("Index"));
     }
     catch
     {
         return(View());
     }
 }
コード例 #16
0
        public void DeleteTest()
        {
            Products model = new Products()
            {
                ProductID = 3
            };
            ProductsRepository products = new ProductsRepository();

            products.Delete(model);
            var list = products.FindByID(3);

            Assert.IsTrue(list == null);
        }
コード例 #17
0
        public void DeleteTest()
        {
            var productRepository = new ProductsRepository(new FakeContextFactory());
            var product           = productRepository.Get().FirstOrDefault();

            Assert.NotNull(product);

            productRepository.Delete(product.Id);

            var found = productRepository.GetById(product.Id);

            Assert.Null(found);
        }
コード例 #18
0
        public void ProductsRepositoryTests_Delete()
        {
            ProductsRepository repository = new ProductsRepository();
            var model = new Products
            {
                Product_ID = 5
            };

            repository.Delete(5);
            var result = repository.GetByProduct_ID(5);

            Assert.IsTrue(result == null);
        }
コード例 #19
0
        public async Task <IActionResult> DeleteProducts(int id)
        {
            var products = await _productsRepository.FindIdAsync(id);

            if (products == null)
            {
                return(NotFound());
            }

            _productsRepository.Delete(products);
            await Task.Run(() => _productsRepository.Save());

            return(NoContent());
        }
コード例 #20
0
        public ActionResult DeletingProduct(MallOfElectronics.Models.DataBase.Product product)
        {
            ProductsRepository productRepository = new ProductsRepository();

            if (productRepository.Delete(product.Id))
            {
                ViewBag.message = "This Product Has Been Deleted";
            }
            else
            {
                ViewBag.ErrorMessage = "This Product Not Has Been Deleted";
            }
            return(View());
        }
コード例 #21
0
        internal string Delete(int id, string userId)
        {
            Product original = _repo.GetSingleProduct(id);

            if (original == null || original.CreatorId != userId)
            {
                throw new Exception("Invalid Request!");
            }
            if (_repo.Delete(id))
            {
                return("Successfully Deleted Item.");
            }
            return("Unsucessful in Deleting Item.");
        }
コード例 #22
0
        public HttpResponseMessage Delete(int Id)
        {
            var product = ProductRepository.GetProduct(Id.ToString());

            if (product == null)
            {
                throw new HttpResponseException(HttpStatusCode.NotFound);
            }

            ProductRepository.Delete(Id);
            var response = Request.CreateResponse(HttpStatusCode.OK);

            return(response);
        }
コード例 #23
0
        /// <summary>
        /// WriteTest
        /// </summary>
        /// <param name="repeatTime"></param>
        /// <returns></returns>
        public long WriteTest(int repeatTime)
        {
            return(Utility.PerformanceWatchWithTimes(() =>
            {
                //Insert customer
                var customer = new Customers
                {
                    CompanyName = "Newcvompanyname",
                    ContactName = "ccc",
                    Address = "asdcadsdws",
                    ContactTitle = "adsdf",
                    City = "ku2na",
                    Country = "chi2na",
                    Phone = "231",
                    PostalCode = "234",
                    Region = "ASIA",
                    CustomerID = new RNGCryptoServiceProvider().GetNextInt32(51323).ToString()
                };

                _customersRepository.Insert(customer);

                //insert category
                var cat = new Categories {
                    CategoryName = "Widgetdss234"
                    , Description = "Widgetss are 43the ……", Picture = new byte[] { 1, 3 }
                };
                cat.CategoryID = Convert.ToInt32(_categoriesRepository.Insert(cat));

                //update Category
                cat.CategoryName = "Namehaschange";
                _categoriesRepository.Update(cat);

                //insert product
                var newProduct = new Products {
                    ProductName = "Blue Widget234", UnitPrice = 35.56M, CategoryID = cat.CategoryID
                };
                newProduct.ProductID = Convert.ToInt32(_productRepository.Insert(newProduct));

                //update product
                newProduct.ProductName = "productchange1";
                _productRepository.Update(newProduct);

                //Delete them
                _productRepository.Delete(newProduct);
                _categoriesRepository.Delete(cat);
            }, repeatTime));
        }
コード例 #24
0
        //DELETE: api/Products/5
        public IHttpActionResult Delete([FromUri] int id)
        {
            try
            {
                var productsRepository = new ProductsRepository();
                var deleteProduct      = productsRepository.Delete(id);

                if (deleteProduct == null)
                {
                    return(NotFound());
                }

                return(StatusCode(HttpStatusCode.NoContent));
            }
            catch (Exception ex)
            {
                return(InternalServerError(ex));
            }
        }
コード例 #25
0
        public ActionResult Delete(int productId)
        {
            ProductsRepository.Delete(productId);

            if (Session["cart"] != null)
            {
                List <Product> cart = (List <Product>)Session["cart"];
                foreach (var product in cart)
                {
                    if (product.Id == productId)
                    {
                        cart.Remove(product);
                        break;
                    }
                }
                Session["cart"] = cart;
            }
            return(RedirectToAction("Cart"));
        }
コード例 #26
0
ファイル: MainForm.cs プロジェクト: hotabsc/ShopWinForms
        private void DeleteProduct_Click(object sender, EventArgs e)
        {
            Product product = (Product)ProductsDataGrid.CurrentRow.DataBoundItem;

            if (!product.Id.HasValue)
            {
                throw new ApplicationException("Delete event: Product id not defined!");
            }

            var confirmResult = MessageBox.Show($"Are you sure to delete product {product.Name}?",
                                                "Delete confirm",
                                                MessageBoxButtons.YesNo);

            if (confirmResult == DialogResult.Yes)
            {
                _productsRepository.Delete(product.Id.Value);
                FillGrids();
            }
        }
コード例 #27
0
 public async Task <ActionResult> DeleteByID(int id)
 {
     try
     {
         var prodRepository = new ProductsRepository(_context, _environment);
         if (await prodRepository.Delete(id))
         {
             return(Ok(new { status = true, message = "Removido com sucesso !" }));
         }
         else
         {
             return(BadRequest("Não foi possível remover objeto"));
         }
     }
     catch (Exception e)
     {
         return(BadRequest(e.Message));
     }
 }
コード例 #28
0
        public ActionResult DeleteConfirmed(int id)
        {
            var product = _repo.Get(id);

            #region Deleting Product Features
            var productMainFeatures = _repo.GetProductMainFeatures(product.Id);
            foreach (var mainFeature in productMainFeatures)
            {
                _mainFeatureRepo.Delete(mainFeature.Id);
            }

            var productFeatures = _repo.GetProductFeatures(product.Id);
            foreach (var feature in productFeatures)
            {
                _featureRepo.Delete(feature.Id);
            }
            #endregion
            _repo.Delete(id);
            return(RedirectToAction("Index"));
        }
コード例 #29
0
 public IActionResult Delete(int id)
 {
     _productsRepository.Delete(id);
     return(NoContent());
 }
コード例 #30
0
ファイル: ProductService.cs プロジェクト: hakanozcn/Projeler
 public void Delete(int id)
 {
     Product.Delete(id);
 }