Пример #1
0
        public ActionResult DeleteConfirmed(int id)
        {
            Product product = productRepo.Get(id);

            productRepo.Delete(product);
            return(RedirectToAction("Index"));
        }
Пример #2
0
        public ActionResult Delete(int id, ProductModel model)
        {
            if (Session["Login"] == null)
            {
                return(RedirectToAction("login", "Admin"));
            }

            try
            {
                if (id < 0)
                {
                    return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
                }
                var product = _prodRepo.Get(id);
                if (product == null)
                {
                    return(HttpNotFound());
                }
                _prodRepo.Delete(id);
                return(RedirectToAction("Index"));
            }
            catch
            {
                // TODO log error
                ModelState.AddModelError("", "Something went wrong, please try again");
                return(View(model));
            }
        }
        public IActionResult Delete(Product pro)
        {
            Product proToDelete = productRepo.GetProductByID(pro.Id);

            productRepo.Delete(proToDelete);
            return(RedirectToAction("ManageProducts"));
        }
Пример #4
0
        // GET: ProductController/Delete/5
        public ActionResult Delete(int id)
        {
            var product = _repo.FindById(id);

            if (product == null)
            {
                return(NotFound());
            }
            var isSuccess = _repo.Delete(product);

            if (!isSuccess)
            {
                return(BadRequest());
            }
            return(RedirectToAction(nameof(Index)));
        }
Пример #5
0
        public void ShouldDeleteAProduct()
        {
            var item = _productRepo.Find(1);

            _productRepo.Context.Entry(item).State = EntityState.Detached;
            _productRepo.Delete(item);
            var product = _productRepo.Find(Context.ProductId);

            Assert.Null(product);
        }
Пример #6
0
 public IActionResult Delete(Guid id)
 {
     if (id != null)
     {
         _repo.Delete(id);
         if (_repo.SaveChanges() > 0)
         {
             return(Ok("deleted"));
         }
     }
     return(NotFound());
 }
Пример #7
0
        public async Task <JsonResult> DeleteProduct(int id)
        {
            try
            {
                await productRepo.Delete(id);
            }
            catch (Exception e)
            {
                return(Json(400));
            }

            return(Json(200));
        }
Пример #8
0
        public async Task <IActionResult> DeleteProduct([FromRoute] int id, [FromRoute] string timestamp)
        {
            if (!timestamp.StartsWith("\""))
            {
                timestamp = $"\"{timestamp}\"";
            }

            var ts = JsonConvert.DeserializeObject <byte[]>(timestamp);

            _repo.Delete(id, ts);

            return(Ok());
        }
 public ActionResult Delete_Confirmed(int id)
 {
     if (Session["vid"].ToString() == "103")
     {
         Product pp = prepo.Get(id);
         prepo.Delete(pp.adid);
         return(RedirectToAction("Index", new { id = Session["regid"] }));
     }
     else
     {
         return(RedirectToAction("Index", "Index"));
     }
 }
 public ActionResult Delete_Confirmed(int id)
 {
     if (Session["vid"].ToString() == "101")
     {
         Product ppp = context.Products.SingleOrDefault(i => i.adid == id);
         Product pp  = arepo.Get(id);
         prepo.Delete(pp.adid);
         return(RedirectToAction("Details", new { id = ppp.pregid }));
     }
     else
     {
         return(RedirectToAction("Index", "Index"));
     }
 }
Пример #11
0
        public async Task <ActionResult> DeleteProduct(int id)
        {
            var productFromRepo = repository.GetById(x => x.Id == id, y => y.Category).Result;

            if (productFromRepo == null)
            {
                return(NotFound());
            }
            if (productFromRepo.Image != null)
            {
                await fileStorage.DeleteFile(productFromRepo.Image, containerName);
            }
            repository.Delete(productFromRepo);
            repository.SaveChangesAsync();
            return(NoContent());
        }
Пример #12
0
        public async Task <IResponse <bool> > DeleteAsync(string baseDomain, string root, int id)
        {
            var product = await _productRepo.FindAsync(id);

            var urls = _appUow.ProductAssetRepo.Get(x => new { x.FileUrl, x.CdnFileUrl }, x => x.ProductId == id, o => o.OrderBy(x => x.ProductId)).Select(x => (x.FileUrl, x.CdnFileUrl));

            _productRepo.Delete(product);
            var delete = await _appUow.ElkSaveChangesAsync();

            if (delete.IsSuccessful)
            {
                _productAssetService.DeleteFiles(baseDomain, urls);
            }
            return(new Response <bool>
            {
                Message = delete.Message,
                Result = delete.IsSuccessful,
                IsSuccessful = delete.IsSuccessful,
            });
        }
Пример #13
0
        public IActionResult DeleteProduct(int id)
        {
            try
            {
                var product = _productRepo.Get(id);
                if (product == null)
                {
                    return(NotFound());
                }
                _productRepo.Delete(id);

                if (System.IO.File.Exists(product.Image))
                {
                    System.IO.File.Delete(product.Image);
                }
                return(NoContent());
            }
            catch (Exception)
            {
                throw;
            }
        }
        public async Task <ActionResult> DeleteProduct(string id)
        {
            try
            {
                var productToDelete = await repo.GetById(id);

                if (productToDelete == null)
                {
                    return(NotFound($"Product with Id = {id} not found"));
                }
                var result = await repo.Delete(id);

                if (result)
                {
                    return(Ok());
                }
                return(BadRequest());
            }
            catch (Exception e)
            {
                return(StatusCode(StatusCodes.Status500InternalServerError,
                                  $"Error Deleting data. Error message:{e.Message}"));
            }
        }
 public IActionResult Delete(Product pro)
 {
     productRepo.Delete(pro);
     return(RedirectToAction("ManageProducts"));
 }
Пример #16
0
 public async Task <IActionResult> DeleteProductById(string id)
 {
     return(Ok(await _productRepo.Delete(id)));
 }
Пример #17
0
 public ActionResult Delete(int id)
 {
     _repo.Delete(id);
     return(RedirectToAction("Index"));
 }
Пример #18
0
 public void DeleteProduct(long id)
 {
     _repo.Delete(new Product {
         Id = id
     });
 }
Пример #19
0
 public void Delete(Guid id) => repo.Delete(id);
Пример #20
0
 public async Task <ActionResult> DeleteProduct(string id)
 {
     return(Ok(await _repo.Delete(id)));
 }
Пример #21
0
 public int DeleteProduct(int productId)
 {
     return(proRepo.Delete(productId));
 }