public async Task DownloadFile() { EntityDownload.DateDownloaded = DateTime.Now; EntityDownload.Status = EnumFileDownloader.DownloadStatus.Downloading; if (EntityDownload.Id == 0) { _serviceExternalDownload.Add(EntityDownload); } else { _serviceExternalDownload.Update(EntityDownload); } _destinationDir = Path.Combine(ServiceSetting.GetSettingValue(SettingStrings.StoragePath), "software_uploads", EntityDownload.ModuleGuid); var dirResult = CreateDirectory(); if (dirResult != null) { EntityDownload.Status = EnumFileDownloader.DownloadStatus.Error; EntityDownload.ErrorMessage = dirResult; _serviceExternalDownload.Update(EntityDownload); return; } using (_webClient = new WebClient()) { _webClient.DownloadProgressChanged += wc_DownloadProgressChanged; _webClient.DownloadFileCompleted += wc_DownloadFileCompleted; await _webClient.DownloadFileTaskAsync(new Uri(EntityDownload.Url), Path.Combine(_destinationDir, EntityDownload.FileName)); } }
public DtoActionResult Put(int id, EntityExternalDownload download) { download.Id = id; var result = _downloadService.Update(download); if (result == null) { throw new HttpResponseException(Request.CreateResponse(HttpStatusCode.NotFound)); } return(result); }