public async Task <IActionResult> DeleteProduct(int productId, int id)
        {
            var productFromRepo = await _repo.GetProduct(productId);

            if (!productFromRepo.PhotoForProducts.Any(p => p.PhotoId == id))
            {
                return(Unauthorized());
            }
            var Photo = await _repo.GetPhotoForProduct(id);

            if (Photo.IsMain)
            {
                return(BadRequest("لايمكن حذف الصورة الأساسية"));
            }
            if (Photo.PublicId != null)
            {
                var deleteParams = new DeletionParams(Photo.PublicId);
                var result       = this._cloudinary.Destroy(deleteParams);
                if (result.Result == "ok")
                {
                    _repo.Delete(Photo);
                }
            }
            if (Photo.PublicId == null)
            {
                _repo.Delete(Photo);
            }

            if (await _repo.SaveAll())
            {
                return(Ok());
            }
            return(BadRequest("فشل حذف الصورة"));
        }
        public async Task <IActionResult> DeleteShipper(int id)
        {
            var shipperFromRepo = await _repo.GetShipper(id);

            _repo.Delete(shipperFromRepo);
            if (await _repo.SaveAll())
            {
                return(Ok());
            }
            return(BadRequest("فشل في حذف"));
        }
        public async Task <IActionResult> DeleteVendor(int id)
        {
            var vendorFromRepo = await _repo.GetVendor(id);

            _repo.Delete(vendorFromRepo);
            if (await _repo.SaveAll())
            {
                return(Ok());
            }
            return(BadRequest("لم يتم حذف Vendor"));
        }
        public async Task <IActionResult> DeleteSubCategory(int id)
        {
            var subCategoryFroRepo = await _repo.GetSubCategory(id);

            _repo.Delete(subCategoryFroRepo);
            if (await _repo.SaveAll())
            {
                return(Ok());
            }
            return(BadRequest("لم يتم حذف الفئة"));
        }
Esempio n. 5
0
        [HttpDelete("{id}", Name = "DeleteProduct")]  //why id for user => //for check if the user Authorize or not before write asp role
        public async Task <IActionResult> DeleteProduct(int id)
        {
            var categoryFroRepo = await _repo.GetProduct(id);

            _repo.Delete(categoryFroRepo);
            if (await _repo.SaveAll())
            {
                return(Ok());
            }
            return(BadRequest("لم يتم حذف Product"));
        }
        public async Task <IActionResult> DeleteDiscount(int id)
        {
            var discountFroRepo = await _repo.GetDiscount(id);

            _repo.Delete(discountFroRepo);
            if (await _repo.SaveAll())
            {
                return(Ok());
            }
            return(BadRequest("لم يتم حذف يرومو كود"));
        }
Esempio n. 7
0
        public async Task <IActionResult> DeleteCoupan(int id)
        {
            var coupanFromRepo = await _repo.GetCoupan(id);

            _repo.Delete(coupanFromRepo);
            if (await _repo.SaveAll())
            {
                return(Ok());
            }
            return(BadRequest("لم يتم حذف يرومو كود"));
        }
        public async Task <IActionResult> DeleteSupplier(int supplierId, int id)
        {
            if (supplierId != int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value))
            {
                return(Unauthorized());
            }
            var supplierFromRepo = await _repo.GetSupplier(supplierId);

            if (!supplierFromRepo.PhotoForSuppliers.Any(p => p.PhotoId == id))
            {
                return(Unauthorized());
            }
            var Photo = await _repo.GetPhotoForSupplier(id);

            if (Photo.IsMain)
            {
                return(BadRequest("لايمكن حذف الصورة الأساسية"));
            }
            if (Photo.PublicId != null)
            {
                var deleteParams = new DeletionParams(Photo.PublicId);
                var result       = this._cloudinary.Destroy(deleteParams);
                if (result.Result == "ok")
                {
                    _repo.Delete(Photo);
                }
            }
            if (Photo.PublicId == null)
            {
                _repo.Delete(Photo);
            }

            if (await _repo.SaveAll())
            {
                return(Ok());
            }
            return(BadRequest("فشل حذف الصورة"));
        }
        public async Task <IActionResult> DeleteProduct(int customerId, int id)
        {
            if (customerId != int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value))
            {
                return(Unauthorized());
            }
            var categoryFroRepo = await _repo.GetProduct(id);

            _repo.Delete(categoryFroRepo);
            if (await _repo.SaveAll())
            {
                return(Ok());
            }
            return(BadRequest("لم يتم حذف الصورة"));
        }