public int deleteProduct(DeleteProductDTO data)
 {
     try
     {
         try
         {
             List <string> imagesUrls = data.images;
             if (imagesUrls != null)
             {
                 string oldProp = string.Empty;
                 foreach (var item in imagesUrls)
                 {
                     var url = new Uri(item);
                     oldProp = '~' + url.LocalPath;
                     oldProp = HttpContext.Current.Server.MapPath(oldProp);
                     if (File.Exists(oldProp))
                     {
                         File.Delete(oldProp);
                     }
                 }
             }
         }
         catch (Exception ex)
         {
             ErrorLogger.LogDebug(ex.Message);
         }
         this.iUnitOfWork.ProductRepository.Delete(data.productID);
         this.iUnitOfWork.Save();
         return(0);
     }
     catch (Exception ex)
     {
         return(-1);
     }
 }
Beispiel #2
0
        public IEnumerable <ProductDTO> DeleteProduct([FromBody] DeleteProductDTO model)
        {
            var product = context.Products.FirstOrDefault(x => x.Id.Equals(model.Id));

            context.Products.Remove(product);

            context.SaveChanges();

            return(GetProducts());
        }
Beispiel #3
0
 public IHttpActionResult deleteProduct(DeleteProductDTO item)
 {
     try
     {
         return(Ok(this.iProductBL.deleteProduct(item)));
     }
     catch (Exception exp)
     {
         ErrorLogger.LogDebug(exp.Message);
         return(null);
     }
 }
Beispiel #4
0
        public DeleteProductDTO DeleteProductById(long id)
        {
            var responseJson = new DeleteProductDTO();

            if (_productService.Delete(new ProductDeleteRequest {
                Id = id
            }).HasDeleted)
            {
                responseJson.status = Status.Success;
            }
            else
            {
                responseJson.status = Status.Failed;
            }

            return(responseJson);
        }