public async Task <IActionResult> DeleteImage(int productId, int id)
        {
            var product = await _repo.GetProductById(productId);

            if (!product.Images.Any(p => p.Id == id))
            {
                return(BadRequest("Image does not exist"));
            }

            var image = await _repo.GetImageById(id);

            var deleteParams = new DeletionParams(image.PublicId);

            var result = _cloudinary.Destroy(deleteParams);

            if (result.Result == "ok")
            {
                _repo.Delete(image);
            }

            if (await _repo.SaveAll())
            {
                return(Ok());
            }
            return(BadRequest("Failed to delete image"));
        }
Example #2
0
        public async Task <IActionResult> DeleteImage(int brandId, int id)
        {
            var brand = await _repo.GetBrandById(brandId);

            if (brand.Image.Id == id)
            {
                var image = await _repo.GetImageById(id);

                var deleteParams = new DeletionParams(image.PublicId);

                var result = _cloudinary.Destroy(deleteParams);

                if (result.Result == "ok")
                {
                    _repo.Delete(image);
                }

                if (await _repo.SaveAll())
                {
                    return(Ok());
                }

                return(BadRequest("Failed to delete image"));
            }

            return(BadRequest("Image does not exist"));
        }
Example #3
0
        public async Task <IActionResult> DeleteBanner(int id)
        {
            var banner = await _repo.GetImageById(id);

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

            var deleteParams = new DeletionParams(banner.PublicId);

            var result = _cloudinary.Destroy(deleteParams);

            if (result.Result == "ok")
            {
                _repo.Delete(banner);
            }

            if (await _repo.SaveAll())
            {
                return(Ok());
            }

            return(BadRequest("Failed to delete banner"));
        }
Example #4
0
        public bool DeleteLaptop(int LaptopId)
        {
            Laptop Laptop = _laptopRepository.FindById(LaptopId);

            if (Laptop == null)
            {
                return(false);
            }

            _laptopRepository.Delete(Laptop);
            _laptopRepository.SaveChanges();

            return(true);
        }
Example #5
0
        public async Task <IActionResult> DeleteBrand(int id)
        {
            var brand = await _repo.GetBrandById(id);

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

            _repo.Delete(brand);
            if (await _repo.SaveAll())
            {
                return(Ok());
            }
            throw new Exception($"Deleting brand {id} failed on save");
        }
Example #6
0
        public async Task <IActionResult> DeleteOrder(int id)
        {
            var order = await _repo.GetOrderById(id);

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

            _repo.Delete(order);

            if (await _repo.SaveAll())
            {
                return(Ok());
            }

            throw new Exception($"Deleting order {id} failed on save");
        }
Example #7
0
        public async Task <IActionResult> DeleteProductById(int id)
        {
            var product = await _repo.GetProductById(id);

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

            _repo.Delete <Product>(product);

            if (await _repo.SaveAll())
            {
                return(Ok());
            }

            throw new Exception($"Deleting product {id} failed on save");
        }