protected void upd_doc(object sender, EventArgs e) { document_ = new Document(); document_.Id = Int32.Parse(Session["Id_doc"].ToString()); ReadDocumentCommand cmd_ = new ReadDocumentCommand(document_); cmd_.Execute(); document_ = cmd_.Document; topic = new Topic(); topic.Id = Int32.Parse(list_topic.SelectedValue); document = new Document(); document.Id = Int32.Parse(Session["Id_doc"].ToString()); document.File = name.Value; document.Topic = topic; document.Bytea = document_.Bytea; document.Type = document_.Type; document.Visibility = document_.Visibility; UpdateDocumentCommand cmd = new UpdateDocumentCommand(document); cmd.Execute(); if (document.Code == 201) { ClientScript.RegisterClientScriptBlock(this.GetType(), "random", "alertme_succ()", true); } else { ClientScript.RegisterClientScriptBlock(this.GetType(), "random", "alertme()", true); } }
/// <summary> /// Handles an update request on a Document record. /// </summary> /// <param name="request">The request</param> /// <param name="cancellationToken">Cancellation token</param> /// <returns>Response from the request</returns> /// <exception cref="System.ArgumentNullException">document</exception> /// <exception cref="System.ArgumentException"> /// You cannot convert a file to a folder nor a folder to a file! /// </exception> public async Task <Guid> Handle(UpdateDocumentCommand request, CancellationToken cancellationToken) { try { Document document = await this._repository.GetDocumentAsync(request.Id); if (document is null) { throw new ArgumentNullException(nameof(document)); } if (document.IsFolder && !request.IsFolder || !document.IsFolder && request.IsFolder) { throw new ArgumentException("You cannot convert a file to a folder nor a folder to a file!"); } document.Rename(request.Name, request.Extension); document.MoveTo(request.ParentId); if (!request.IsFolder) { request.File.SafeName = document.Id.ToString(); await this._storageManager.UploadAsync(request.File, true); } await this._repository.UpdateDocumentAsync(document); return(document.Id); } catch (Exception exception) { this._logger.LogError(exception, exception.Message, request); return(Guid.Empty); } }
private Task <string> UploadDocuments(UpdateDocumentCommand command) { string folderPath = GetFolderPath(command.Code); command.FolderName = folderPath.Replace(UploadFolderPath, string.Empty); List <string> files = new List <string>(); if (command.Files != null && command.Files.Any()) { foreach (HttpFile file in command.Files) { string filePath = $"{folderPath}/{file.FileName}"; command.FolderName = folderPath.Replace(UploadFolderPath, string.Empty); command.LinkFile = $"/downloadfile/viewfile?sourcedoc={folderPath.Replace(UploadFolderPath, string.Empty)}/{file.FileName}"; files.Add(file.FileName); SaveAs(filePath, file); } } if (command.AppendiceFiles != null && command.AppendiceFiles.Any()) { foreach (HttpFile file in command.AppendiceFiles) { string filePath = $"{folderPath}/{file.FileName}"; SaveAs(filePath, file); Application.Documents.Commands.AppendiceDto appendice = command.Appendices?.FirstOrDefault(a => a.FileName == file.FileName); if (appendice != null) { appendice.LinkFile = $"/downloadfile/viewfile?sourcedoc={folderPath.Replace(UploadFolderPath, string.Empty)}/{file.FileName}"; } } } return(Task.FromResult(string.Join(";", files))); }
public async Task <IActionResult> Documents(UpdateDocumentCommand command) { try { await Mediator.Send(command); return(RedirectToAction("Documents")); } catch (ValidationException exception) { foreach (var(key, value) in exception.Errors) { ModelState.AddModelError(key, value[0]); } var model = await Mediator.Send(new GetDocumentQuery { UserId = CurrentUserService.UserId }); if (model == null) { return(View()); } model.NationalCode = command.NationalCode; model.BirthDate = command.BirthDate; return(View(model)); } }
public async Task <int> Update([FromBody] UpdateDocumentCommand updateDocumentCommand) { updateDocumentCommand.ModifiedBy = User.Identity.GetUserName(); updateDocumentCommand.ModifiedOn = DateTime.Now; updateDocumentCommand.Deleted = false; updateDocumentCommand.FileName = await UploadDocuments(updateDocumentCommand); return(await Mediator.Send(updateDocumentCommand)); }
public static async Task UpdateDocumentAsync(this HttpClient httpClient, Uri documentUri, UpdateDocumentCommand command) { var content = GetStringContent(command); var updateDocumentResponse = await httpClient.PutAsync(documentUri, content); updateDocumentResponse.EnsureSuccessStatusCode(); }
public Document CreateFromCommand(UpdateDocumentCommand command) { return(new Document(command.Id) { Name = command.Name, DocumentName = command.File.FileName, DocumentStatus = DocumentStatusFactory.Create(command.DocumentStatusId), Content = command.File.FileContent, ContentType = command.File.FileContentType, Updated = new AuditTrack(_userId, _dateTime) }); }
public async Task <UpdateDocumentCommand> CreateUpdateDocumentCommand(Document document, IMessageDataRepository messageDataRepository) { var messageData = await messageDataRepository.PutBytes(document.Content, TimeSpan.FromMinutes(10)); var updateDocumentCommand = new UpdateDocumentCommand( document.Id, document.Name, (int)document.DocumentStatus.Id, document.DocumentName, document.ContentType, document.Updated.On, document.Updated.UserId, document.Updated.On, document.Updated.UserId, messageData); return(updateDocumentCommand); }
public async Task <IActionResult> UpdateDocument(Guid id, [FromBody] UpdateDocumentCommand command) { //More than three from clauses does not work, that's why two of them are combined to local helper function Task <Validation <Error, (UpdateDocumentCommand Command, Document Document)> > ValidateCommandAndGetDocument() => from cmd in ValidateUpdateCommand(command) from doc in GetDocumentFromEvents(id) select(cmd, doc); var outcome = from result in ValidateCommandAndGetDocument() from u in ValidateDocumentUser(result.Document.UserId.Value) from docEvent in result.Document.Update(result.Command.Number, result.Command.Description).AsTask() from _ in SaveAndPublishEventAsync(docEvent.Event) select docEvent.Document; return(await outcome.Map(val => val.ToActionResult(_ => NoContent()))); }
public async Task <bool> Handle(UpdateDocumentCommand request, CancellationToken cancellationToken) { var document = await _documentRepository.GetDocument(request.Id); if (document == null) { throw new Exception($"Document with id {request.Id} does not exist"); } document.Update(request.Name, request.Description); document.Comments.Clear(); foreach (var item in request.Items) { document.AddComment(item.Description, item.Content); } return(await _documentRepository.Update(document)); }
public async Task TestUpdateDocumentNoContentResult() { //Arrange var documentCreatedDto = new DocumentCreatedEventDto(Guid.Empty, DateTime.UtcNow, Guid.Empty, "1234", string.Empty); var readEventsFunc = TestHelper.ValidReadEventsFunc(documentCreatedDto.ToEvent()); var command = new UpdateDocumentCommand("1234", "test"); _documentsController = new DocumentsController(readEventsFunc, TestHelper.SaveAndPublish, DocumentExistsByNumber, TestHelper.GetDocumentById(), TestHelper.GetCurrentUserId()); //Act var result = await _documentsController.UpdateDocument(Guid.Empty, command); //Assert var noContentResult = result as NoContentResult; Assert.NotNull(noContentResult); }
public async Task UpdateDocumentTest() { // Arrange var createDocumentCommand = new CreateDocumentCommand(DateTime.UtcNow.Ticks.ToString(), "Test document"); var updateDocumentCommand = new UpdateDocumentCommand($"{createDocumentCommand.Number}-update", $"{createDocumentCommand.Description}-update"); // Act var documentUri = await _client.CreateDocumentAsync(createDocumentCommand); await _client.UpdateDocumentAsync(documentUri, updateDocumentCommand); var document = await _client.GetAsync <Document>(documentUri); // Assert Assert.NotNull(document); Assert.Equal(updateDocumentCommand.Number, document.Number); Assert.Equal(updateDocumentCommand.Description, document.Description); Assert.Equal(DocumentStatus.Draft.ToString(), document.Status); }
public async Task <int> UpdateAndRelease([FromBody] UpdateDocumentCommand updateDocumentCommand) { updateDocumentCommand.ModifiedBy = User.Identity.GetUserName(); updateDocumentCommand.ModifiedOn = DateTime.Now; updateDocumentCommand.Deleted = false; updateDocumentCommand.FileName = await UploadDocuments(updateDocumentCommand); int id = await Mediator.Send(updateDocumentCommand); if (id > 0) { GetDocumentByIdDto document = await Mediator.Send(new GetDocumentByIdQuery { Id = id }); if (document != null && document.Id > 0) { await SendMailUpdateAndReleaseDocument(document); } } return(id); }
public async Task <IActionResult> UpdateAsync([FromBody] UpdateDocumentCommand command) { var response = await _mediator.Send(command); return(JsonResult(response)); }
public async Task <ActionResult> update([FromBody] UpdateDocumentCommand updateDocumentCommand) { await _mediator.Send(updateDocumentCommand); return(NoContent()); }