public async Task <ActionResult> CreateItemAsync(IFormFile file, CancellationToken cancellationToken) { var fileExt = Path.GetExtension(file.FileName); var fileName = DateTime.Now.ToString("yyyyMMdd_hhmmss_") + Guid.NewGuid().ToString() + fileExt; var destinationFile = _uriComposer.ComposeUploadPath(fileName); using (var stream = System.IO.File.Create(destinationFile)) { await file.CopyToAsync(stream, cancellationToken); } var newItem = new Attachment(fileName, fileName, fileExt, file.Length); newItem = await _attachmentService.AddAsync(newItem, cancellationToken); if (newItem == null) { AssignToModelState(_attachmentService.Errors); return(ValidationProblem()); } var dto = _mapper.Map <AttachmentDTO>(newItem); return(Ok(dto)); }
private async Task ProcessAddingQueue() { try { messenger.Send( this, new SwitchLoadingIndicatorMessage { Switcher = true }); while (attachmentsQueue.Count != 0) { await attachmentService.AddAsync(SelectedAccount, attachmentsQueue.Peek()).ConfigureAwait(false); attachmentsQueue.Dequeue(); } messenger.Send( this, new SwitchLoadingIndicatorMessage { Switcher = false }); ProcessingFinished?.Invoke(); } catch (AttachmentExistsException) { dialogId = Guid.NewGuid(); messenger.Send( this, new SwitchLoadingIndicatorMessage { Switcher = false }); messenger.Send( this, new ConfirmDialogRequestMessage { DialogMode = DialogModes.OkCancel, Title = Titles.Replace, Message = string.Format(Templates.ReplaceMessage, Path.GetFileName(attachmentsQueue.Peek())), DialogId = dialogId, OnResponseReceived = ReplaceResponseReceivedHandler }); } catch (UnauthorizedAccessException) { NotifyUnauthorizedAccess(); } }
public async Task <IActionResult> AddAttachmentAsync([FromBody] AddAttachmentRequest request) { Attachment attachment = new(); attachment.Filename = request.Filename; attachment.Message = await messageService.GetByIdAsync(request.MessageId); attachment.Url = "-"; await attachmentService.AddAsync(attachment); return(Ok()); }