Ejemplo n.º 1
0
        public async Task DeleteAsync(Guid id, string username)
        {
            var order = await _orderRepository.GetOrFailAsync(id);

            var files = order.Files;

            foreach (var file in files)
            {
                if (file.Path != string.Empty)
                {
                    await _fileRepository.RemoveAsync(file.Path);
                }
            }
            await _fileRepository.RemoveDirectoryIfExists(order.GetPathToFolder());

            await _orderRepository.RemoveAsync(order);

            await _logService.AddLogAsync($"Usunięto zlecenie.", order, username);
        }
Ejemplo n.º 2
0
        public async Task DeleteFileAsync(Guid id, string fileType, string role, string username)
        {
            var order = await _orderRepository.GetOrFailAsync(id);

            await _handler
            .Validate(async() =>
            {
                await _orderService.ValidatePermissionsToOrder(username, role, order.Id);
                await _permissionService.Validate(fileType, role);
            })
            .Run(async() =>
            {
                var file = order.Files.SingleOrDefault(x => x.FileType == fileType);
                await _realFileRepository.RemoveAsync(file.Path);
                await _logService.AddLogAsync($"Usunięto plik: {Path.GetFileName(file.Path)}", order, username);
                order.UnlinkFile(file.FileType);
                await _orderRepository.UpdateAsync(order);
            })
            .OnCustomError(x => throw new ServiceException(x.Code), true)
            .ExecuteAsync();
        }