public async Task <IActionResult> EditPost(int?id) { var download = await _downloadRepository.Get(id ?? 0); if (download == null) { return(NotFound()); } await TryUpdateModelAsync(download, string.Empty, d => d.Title, d => d.Description, d => d.File, d => d.TagIds); if (download.File != null && download.File.Length < 1) { ModelState.AddModelError(nameof(download.File), "Filesize too small"); } if (!ModelState.IsValid) { return(View(download)); } if (download.File != null) { if (download.LinkPath != null) { await _uploadService.Delete(download.LinkPath); } download.LinkPath = await _uploadService.Upload(download.File, "/files", Path.GetFileNameWithoutExtension(download.File.FileName)); } download.DownloadTags.RemoveAll(dt => !(download.TagIds?.Contains(dt.TagId) ?? false)); download.DownloadTags.AddRange( download.TagIds?.Except(download.DownloadTags.Select(dt => dt.TagId)) .Select(tagId => new DownloadTag { Download = download, TagId = tagId }) ?? new List <DownloadTag>()); try { download.LastModified = DateTime.UtcNow; await _downloadRepository.Update(download); } catch (DbUpdateConcurrencyException) { if (!await DownloadExists(download.Id)) { return(NotFound()); } throw; } return(RedirectToAction(nameof(Index))); }
/// <summary> /// Updates the download /// </summary> /// <param name="download">Download</param> public virtual void UpdateDownload(Download download) { if (download == null) { throw new ArgumentNullException("download"); } _downloadRepository.Update(download); //_eventPubisher.EntityUpdated(download); }
public void SaveDownload(Download download) { try { _downloadRepository.Update(download); _unitOfWork.SaveChanges(); } catch (Exception e) { LogError(e); } }
public async void FreeSlot(FreeSlot freeslot) { Console.WriteLine("[Downloadanager] FreeSlot"); int downloading = _repo.CountByState(State.Downloading); if (downloading >= _maxdownload) { await _bus.SendAsync <QueueFull> (new QueueFull { Downloading = downloading, MaxDownload = _maxdownload }); return; } Download waiting; bool dequeued = _repo.FirstByState(State.Waiting, out waiting); if (!dequeued) { await _bus.SendAsync <QueueEmpty> (new QueueEmpty()); return; } bool resumed = waiting.TryResume(); if (!resumed) { await _bus.SendAsync <DownloadError> (new DownloadError { Id = waiting.Id, State = waiting.State, Error = ErrorEnum.FreeSlot_InvalidState }); return; } _repo.Update(waiting); var queuedownload = new QueueDownload { Download = waiting }; await _bus.SendAsync <QueueDownload> (queuedownload); }