public FileUploadResponse(FileUploadRequest request, FileStatusCode status, FileUploadRecordModel fileUploadRecord, string message) { Request = request; Status = status; FileUploadRecord = fileUploadRecord; Message = message; }
private FileUploadResponse Upload(FileUploadRequest request, FileUploadSessionModel session) { if (request.Bytes.IsEmptyOrNull()) { return(new FileUploadResponse(request, FileStatusCode.Invalid, null, "Invalid upload request")); } if (!IsSupportedExtension(request.Extension)) { return(new FileUploadResponse(request, FileStatusCode.Unsupported, null, "Extension not supportted")); } var fileStatusCode = _fileUploadValidationFactory.Validate(request.Extension, request.Bytes); if (fileStatusCode != FileStatusCode.Valid) { return(new FileUploadResponse(request, fileStatusCode, null, "failed to validate")); } _logger.Information("Start uploading file to server. File name {0}".AsFormat(request.FileName)); var fur = new FileUploadRecordModel { FileName = request.FileName, Bytes = request.Bytes, UploadId = Guid.NewGuid(), UploadSession = session, UploadSessionId = session.Id }; _fileUploadRecordRepository.Create(fur); if (fur.Id == default(long)) { _logger.Information( "Failed to upload file to server. File name {0}, RecordId: {1}, UploadSession: {2}".AsFormat(request.FileName, fur, session)); return(new FileUploadResponse(request, FileStatusCode.FailedToUpload, fur, "File failed to upload")); } _logger.Information( "Finish uploading file to server. File name {0}, RecordId: {1}, UploadSession: {2}".AsFormat(request.FileName, fur, session)); _eventPublisher.PublishToAllDomainModelCreatedEvent(fur); return(new FileUploadResponse(request, FileStatusCode.Uploaded, fur, "File uploaded successfully")); }