public async Task UploadFilesAsync(UploadFilesCommand command)
        {
            // Check file metadata against upload session information
            Guid          sessionId = new Guid(command.UploadSessionId);
            UploadSession session   = await this.UploadSessionRepository.GetByIdAsync(sessionId);

            if (session == null)
            {
                //TODO: Throw exception: the specified upload session does not exist.
                throw new UploadSessionNotStartedException("No upload session has been started. Please, make sure to first start the upload session before uploading files.");
            }

            if (!session.IsStarted)
            {
                throw new UploadSessionNotStartedException("The specified upload session is not in the started state so no files can be uploaded. Please, start a new session for uploading.");
            }

            // Check that id's specified in the command are valid
            if (!session.AreFilesRegistered(command.Files.Select(f => new Guid(f.FileId)).AsEnumerable()))
            {
                throw new UploadSessionFileNotRegisteredException("Some of the files specified were not previously registered for upload. Please, make sure that all files are first registered for upload at session start.");
            }

            // Upload files (first store file content, second update session information)
            foreach (var file in command.Files)
            {
                Guid fileId = new Guid(file.FileId);
                FileUploadDescription uploadDescription = session.GetFileUploadDescription(fileId);

                // Upload file
                ResourceUri sourceStoreFileUri = await this.UploadFileWithoutCommitingDomainChangesAsync(fileId, session.OwnerId, uploadDescription.FileName,
                                                                                                         uploadDescription.ContentType, uploadDescription.ContentLength, file.Content, session.UploadAsPublic);

                // Update session (mark file as uploaded and assign access uri)
                ResourceUri fileAccessUri = RoutingService.BuildUriForFile(uploadDescription, sourceStoreFileUri, session.UploadAsPublic);
                session.MarkFileAsUploaded(fileId);
                session.AssignUriToFileDescription(fileId, fileAccessUri);
            }

            // Save changes
            await this.unitOfWork.CommitChangesAsync();
        }
        public async Task MarkFilesAsUsedAsync(MarkFilesAsUsedCommand command)
        {
            // VALIDATION
            AssertionHelper.AssertNotNull(command, "command");
            //TODO: Validate that file id's specified are valid guid's.
            if (command.FileIds == null || command.FileIds.Count() < 1)
            {
                //TODO: Throw exception
            }

            // Load session based on the identifier of the first file.
            UploadSession session = await this.UploadSessionRepository.GetByFileIdAsync(new Guid(command.FileIds.ElementAt(0)));

            if (session == null)
            {
                //TODO: Localize message
                throw new UploadSessionNotStartedException(string.Format("No upload session containing some of the specified files has been previously started. Please, make sure that the file identifiers have been properly uploaded correctly."));
            }

            // Mark file description in upload session as used
            session.MarkFilesAsUsed(Mapper.Map <IEnumerable <Guid> >(command.FileIds));

            // Index file information
            foreach (var id in command.FileIds)
            {
                FileUploadDescription fileDescription = session.GetFileUploadDescription(new Guid(id));
                FileInformationIndex  index           = FileInformationIndex.Create(fileDescription.Id, session.OwnerId, fileDescription.FileName, fileDescription.ContentType,
                                                                                    fileDescription.ContentLength, fileDescription.AssignedUri, session.UploadAsPublic);

                // Save index
                this.FileInformationIndexRepository.Add(index);
            }

            // Commit changes
            await this.UnitOfWork.CommitChangesAsync();
        }