Beispiel #1
0
            public async Task <ImportProjectResult> Handle(Command request, CancellationToken cancellationToken)
            {
                if (!(await _authorizationService.AuthorizeAsync(_user, null, new ContentDeveloperRequirement())).Succeeded)
                {
                    throw new ForbiddenException();
                }

                var project = await _db.Projects
                              .Include(e => e.Directories)
                              .ThenInclude(d => d.Workspaces)
                              .Include(e => e.Directories)
                              .ThenInclude(d => d.Files)
                              .SingleOrDefaultAsync(e => e.Id == request.Id, cancellationToken);

                if (project == null)
                {
                    throw new EntityNotFoundException <Project>();
                }

                Domain.Models.Project extractedProject;

                using (var memStream = new System.IO.MemoryStream())
                {
                    await request.Archive.CopyToAsync(memStream, cancellationToken);

                    memStream.Position = 0;
                    extractedProject   = _archiveService.ExtractProject(memStream, request.Archive.FileName);
                }

                var importResult = await _importService.ImportProject(project, extractedProject, request.PreserveIds);

                var entries = _db.GetUpdatedEntries();
                await _db.SaveChangesAsync(cancellationToken);

                await this.PublishEvents(entries);

                return(_mapper.Map <ImportProjectResult>(importResult));
            }