public IActionResult Delete(UploadEditViewModel model) { Upload upload = _uploadRepository.GetUpload(model.Id); if (upload != null) { _uploadRepository.Delete(upload.Id); if (upload.UploadPath != null) { string filePath = Path.Combine(hostingEnvironment.WebRootPath, "projects", upload.UploadPath); System.IO.File.Delete(filePath); } } return(RedirectToAction("index")); }
public DataModel.Response.BaseResponse DeleteUpload(string id) { try { IUploadRepository uploadRepository = RepositoryClassFactory.GetInstance().GetUploadRepository(); uploadRepository.Delete(id); return(new BaseResponse { ErrorCode = (int)ErrorCode.None, Message = Resources.Resource.msg_delete_success }); } catch (Exception ex) { return(new BaseResponse { ErrorCode = (int)ErrorCode.Error, Message = ex.Message }); } }
/// <summary> /// Deletes an upload. /// </summary> /// <param name="teantId">Tenant identifier.</param> /// <param name="uploadId">Upload identifier.</param> /// <param name="storageHierarchy">Location of upload. E.g. { "Uploads" > "Users" }.</param> /// <param name="unitOfWork">Unit of work.</param> public void Delete(long tenantId, long uploadId, List <string> storageHierarchy, IUnitOfWork unitOfWork = null) { // If we don't have a unit of work in place, create one now so that we can rollback all changes in case of failure IUnitOfWork localUnitOfWork = unitOfWork == null?_unitOfWorkFactory.CreateUnitOfWork() : null; // Try to delete upload try { // Get main upload details from upload repository Upload upload = _uploadRepository.Read(tenantId, uploadId, unitOfWork ?? localUnitOfWork); // Delete record of upload _uploadRepository.Delete(tenantId, uploadId, unitOfWork ?? localUnitOfWork); // Delete upload in storage _storageService.Delete(upload, storageHierarchy, unitOfWork ?? localUnitOfWork); // Commit work if local unit of work in place if (localUnitOfWork != null) { localUnitOfWork.Commit(); } } catch { if (localUnitOfWork != null) { localUnitOfWork.Rollback(); } throw; } finally { if (localUnitOfWork != null) { localUnitOfWork.Dispose(); } } }
/// <summary> /// 删除临时文件 /// </summary> private void Close() { _repository.Delete(this.TempKey); }
public bool Delete(int id) { return(_uploadRepository.Delete(id)); }