Esempio n. 1
0
 public IActionResult Delete(int id, DeleteBikeViewModel model)
 {
     if (ModelState.IsValid)
     {
         _productsRepo.DeleteProduct(model.ProductId);
         return(RedirectToAction("Index", "Home"));
     }
     return(View(model));
 }
Esempio n. 2
0
        public async Task <IActionResult> Delete(string barcode)
        {
            if (barcode.Length != 13)
            {
                return(BadRequest("Barkod 13 simvol olmalıdır."));
            }

            var result = await _repo.DeleteProduct(barcode);

            if (result.IsSucces)
            {
                return(Ok(result.Content));
            }

            return(StatusCode(520, result.Message));
        }
        public ActionResult DeleteProduct(int id)
        {
            try
            {
                var productFromRepo = _repository.GetProductById(id);
                if (productFromRepo == null)
                {
                    return(NotFound());
                }
                _repository.DeleteProduct(productFromRepo);
                if (_repository.SaveChanges())
                {
                    return(NoContent());
                }
            }
            catch (System.Exception)
            {
                return(StatusCode(StatusCodes.Status500InternalServerError, "Database Failure"));
            }

            return(BadRequest("Failed to delete the product"));
        }