private async Task UpdateFileRoots(IEnumerable <Core.Domain.File> files, int number, Order order) { var filePaths = files.Select(x => x.Path).Where(x => x != string.Empty).ToList(); List <string> newFilesPath = new List <string>(); foreach (var file in filePaths) { var path = file; if (path == string.Empty) { continue; } var fileName = Path.GetFileNameWithoutExtension(path); Regex re = new Regex(@"([a-zA-Z]+)(\d+)"); Match result = re.Match(fileName); string alphaPart = result.Groups[1].Value; string numberPart = result.Groups[2].Value; if (!(alphaPart == "fvk")) { numberPart = OrderFolderNameGenerator.AddLeadingZeros(number); } newFilesPath.Add($"{order.GetPathToFolder()}{alphaPart}{numberPart}.pdf"); } await _fileRepository.UpdateFileNames(filePaths, newFilesPath); }
private async Task GoThroughOrderAsync(string path) { var order = OrderFolderNameGenerator.NameToOrder(path); order.CreationDate = await GenerateOrderCreationDateAsync(order, path); var secondOwner = path.Substring(path.Length - 4); order = await AddFilesAsync(order, path, secondOwner); order = SetNotAddedFilesAsNotRequired(order); await _orderRepository.AddAsync(order); await _logService.AddLogAsync($"Dodano nowe zlecenie.", order, order.Owner1Name, order.CreationDate); await AddOwnersAsync(order, secondOwner); }
public async Task EditOrderAsync(Guid id, int number, string clientCountry, string clientIdentificationNumber, string brokerCountry, string brokerIdentificationNumber, string username) { var order = await _orderRepository.GetOrFailAsync(id); var oldFolderName = order.GetPathToFolder(); var oldOrder = OrderFolderNameGenerator.NameToOrder(oldFolderName); IEnumerable <Core.Domain.File> files = order.Files.Clone(); await _handler .Run(async() => { order.SetNumber(number); order.SetClientCountry(clientCountry); order.SetClientIdentificationNumber(clientIdentificationNumber); order.SetBrokerCountry(brokerCountry); order.SetBrokerIdentificationNumber(brokerIdentificationNumber); await _orderRepository.UpdateAsync(order); }) .PropagateException() .Next() .Run(async() => { await UpdateFileRoots(files, number, order); }) .OnSuccess(async() => { await _logService.AddLogAsync("Edytowano dane zlecenia.", order, username); }) .OnError(async x => { order.SetNumber(oldOrder.Number); order.SetClientCountry(oldOrder.ClientCountry); order.SetClientIdentificationNumber(oldOrder.ClientIdentificationNumber); order.SetBrokerCountry(oldOrder.BrokerCountry); order.SetBrokerIdentificationNumber(oldOrder.BrokerIdentificationNumber); await _orderRepository.UpdateAsync(order); }, true) .Next() .ExecuteAllAsync(); }