Example #1
0
 public virtual ActionResult DeleteFile(long id)
 {
     try
     {
         using (var scope = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled))
         {
             var mypatfile = new AddressUrlFile(Path.Combine("~\\"));
             var attach    = _attachmentService.Find(id);
             if (attach == null)
             {
                 return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
             }
             string fullPath = Request.MapPath(mypatfile.UploadFiles + attach.File + attach.Extention);
             if (System.IO.File.Exists(fullPath))
             {
                 System.IO.File.Delete(fullPath);
             }
             _attachmentService.Delete(id);
             scope.Complete();
             return(Json(new { isError = false, Message = "حذف انجام شد" }));
         }
     }
     catch (Exception exception)
     {
         Elmah.ErrorSignal.FromCurrentContext().Raise(exception);
         return(Json(new { isError = true, Message = "خطا در حذف پیوست" }));
     }
 }
        public async Task <IActionResult> DeletePhoto(string photoId)
        {
            if (photoId == String.Empty)
            {
                throw new Exception("No photo Id");
            }
            var photos = await _attachmentService.Delete(new Guid(photoId));

            return(PartialView("~/Views/Admin/Partials/_BrandPhotos.cshtml", photos));
        }
        public Result <int> Delete(Guid ID)
        {
            var attachment = _attachmentService.List(ID);

            _tagsService.Delete(ID);
            if (attachment.Data.Count > 0)
            {
                foreach (var item in attachment.Data)
                {
                    string path = $"{Enum.GetName(typeof(PathType), item.PathType)}/{item.FileName}";
                    _attachmentService.Delete(item.ID);
                    FileHelper.DeleteFile(path);
                }
            }
            return(_dataSource.Delete(ID));
        }
Example #4
0
        public IActionResult Delete([FromBody] DeleteFileVM deleteFileVM)
        {
            try
            {
                var curUser = accountUtil.GetCurrentUser(User);

                var model = AttachmentService.GetActiveByID(deleteFileVM.file_id);
                if (model == null)
                {
                    throw new Exception("Файл не найден");
                }

                string error = "";

                if (deleteFileVM.model_id.HasValue && deleteFileVM.model_id > 0 &&
                    !string.IsNullOrWhiteSpace(deleteFileVM.file_type))
                {
                    error = DetachFromObj(model, deleteFileVM.model_id.Value, deleteFileVM.file_type, curUser.ID);
                    if (string.IsNullOrWhiteSpace(error))
                    {
                        AttachmentService.Delete(model, curUser.ID);
                    }
                }
                else
                {
                    error = "Некоторые входящие данные неверные";
                }

                if (!string.IsNullOrWhiteSpace(error))
                {
                    throw new Exception(error);
                }

                return(Ok());
            }
            catch (Exception ex)
            {
                return(CustomBadRequest(ex));
            }
        }
Example #5
0
        public IActionResult Delete(int fileID, int?objID, string fileType)
        {
            try
            {
                var curUser = accountUtil.GetCurrentUser(User);

                var model = AttachmentService.GetActiveByID(fileID);
                if (model == null)
                {
                    return(NotFound());
                }

                string error = "";

                if (objID.HasValue && objID > 0 &&
                    !string.IsNullOrWhiteSpace(fileType))
                {
                    error = DetachFromObj(model, objID.Value, fileType, curUser.ID);
                    if (string.IsNullOrWhiteSpace(error))
                    {
                        AttachmentService.Delete(model, curUser.ID);
                    }
                }
                else
                {
                    error = "Некоторые входящие данные неверные";
                }

                if (!string.IsNullOrWhiteSpace(error))
                {
                    throw new Exception(error);
                }

                return(Ok());
            }
            catch (Exception ex)
            {
                return(CustomBadRequest(ex));
            }
        }
 public virtual ActionResult DeleteFile(long id)
 {
     try
     {
         var mypatfile = new AddressUrlFile(Path.Combine("~\\"));
         var attach    = _attachmentService.Find(id);
         if (attach == null)
         {
             return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
         }
         string fullPath = Request.MapPath(mypatfile.UploadFiles + attach.File + attach.Extention);
         if (System.IO.File.Exists(fullPath))
         {
             System.IO.File.Delete(fullPath);
         }
         _attachmentService.Delete(id);
         return(Json(new { isError = false, Message = "حذف انجام شد" }));
     }
     catch (Exception)
     {
         return(Json(new { isError = true, Message = "خطا در حذف پیوست" }));
     }
 }
Example #7
0
        public async Task <ActionResult <bool> > Delete(Guid id)
        {
            var res = await _service.Delete(id);

            return(res);
        }
Example #8
0
        public IActionResult Delete(int id)
        {
            attachmentService.Delete(id);

            return(new NoContentResult());
        }
 public Task <IResultModel> Delete([BindRequired] string id)
 {
     return(_service.Delete(id));
 }