public static long UploadFile(HttpPostedFileBase uploadedFile, UploadedFileCategory category) { var result = FileHelper.Upload(uploadedFile, category); if (!result.Success) { return(0); } var uploadedFileService = ServiceLocator.Resolve <IUploadedFileService>(); var existingFile = uploadedFileService.GetByPhysicalPath(result.ActualPath); var dtoToSave = new UploadedFileDto { PhysicalPath = result.ActualPath, Category = category, UploadedBy = SmsCache.UserContext.UserName, UploadedDateTime = DateTime.Now }; if (existingFile.Success && existingFile.Data != null) { dtoToSave.UploadedFileID = existingFile.Data.UploadedFileID; } var saveResult = uploadedFileService.Save(dtoToSave); if (!saveResult.Success || saveResult.Data == null) { return(0); } return(saveResult.Data.UploadedFileID); }
public async Task <bool> Handle(RegisterUserRequest request, IOutputPort <RegisterUserResponse> outputPort) { if (_userRepository.FindByEmail(request.Email) != null) { outputPort.Handle(new RegisterUserResponse(new[] { new Error(422, "user with this email is already exists") })); return(false); } var userInfo = new UserDto() { Name = request.Name, Email = request.Email, BirthDay = request.BirthDay, PasswordHash = request.PasswordHash, }; UserDto createdUser = _userRepository.Create(userInfo); if (request.Picture != null) { var uploadedPicture = await _uploadService.UploadFile(request.Picture, request.WebRootPath); UploadedFileDto uploadedFile = _uploadedFileRepository.Create(uploadedPicture); uploadedPicture.Id = uploadedFile.Id; ImageDto createdPicture = _imageRepository.Create(new ImageDto() { UserId = createdUser.Id }, request.WebRootPath, uploadedPicture); createdUser = _userRepository.SetUserProfilePicture(createdPicture.Id, createdUser.Id); } outputPort.Handle(new RegisterUserResponse(createdUser)); return(true); }
public async Task <int> AddFileDetailsAsync(UploadedFileDto uploadedFileDto) { try { var file = new UploadedFile { Name = uploadedFileDto.Name, Description = uploadedFileDto.Description, Size = uploadedFileDto.Size, ImportedOn = DateTime.Now, ProcessedLineCount = 0 }; Create <UploadedFile>(file); await SaveAsync(); return(file.FileId); } catch (Exception ex) { _logger.LogException(ex, null); return(-1); } }
public static ImageInfo ToImageInfo(this UploadedFileDto uploadedFileDto) { if (uploadedFileDto == null) { return(null); } return(new ImageInfo(uploadedFileDto.Filename, uploadedFileDto.ContainerName, uploadedFileDto.Uri)); }
public UploadedFileDto Create(UploadedFileDto uploadedFileInfo) { var file = _mapper.Map <UploadedFile>(uploadedFileInfo); _database.UploadedFiles.Add(file); _database.SaveChanges(); return(_mapper.Map <UploadedFileDto>(file)); }
public ImageDto Create(ImageDto pictureInfo, string webRootPath, UploadedFileDto uploadedImage) { pictureInfo.UploadedFileId = uploadedImage.Id; pictureInfo.EncodedImage = FileEncoder.EncodeFile(uploadedImage.RelativePath, webRootPath); pictureInfo.ContentType = uploadedImage.ContentType; Image picture = _mapper.Map <Image>(pictureInfo); _database.Images.Add(picture); _database.SaveChanges(); return(_mapper.Map <ImageDto>(picture)); }
public List <ReturnUploadedFileDto> ExtractCsv(UploadedFileDto uploadedFile) { List <ReturnUploadedFileDto> records; using (var reader = new StreamReader(uploadedFile.file.OpenReadStream())){ using (var csv = new CsvReader(reader, CultureInfo.InvariantCulture)) { csv.Configuration.MissingFieldFound = null; csv.Configuration.HeaderValidated = null; records = csv.GetRecords <ReturnUploadedFileDto>().ToList(); } } return(records); }
public ActionResult Get([FromQuery] int imageId) { UploadedFileDto image = _uploadedFileRepository.Get(imageId); if (image == null) { _basicPresenter.Handle(new Error(404, "image not found")); } string filePath = GetPhysicalPathFromRelativeUrl(image.RelativePath); _imagePresenter.Handle(Convert.ToBase64String(System.IO.File.ReadAllBytes(filePath))); return(_imagePresenter.ContentResult); /*FileStream imageFile = System.IO.File.OpenRead(filePath); * var file = File(imageFile, $"image/{Path.GetExtension(filePath).Substring(1)}", "image.jpg"); * return new { file = file };*/ }
public async Task <string> UploadFileAsync(UploadedFileDto fileDto, CancellationToken cancellationToken) { var mediaLink = string.Empty; using (var ms = new MemoryStream(fileDto.FileBytes)) { var storageObject = await _storageClient.UploadObjectAsync( _googleClientSettings.BucketName, fileDto.FileName, fileDto.FileType, ms, cancellationToken : cancellationToken); mediaLink = storageObject.MediaLink; } return(mediaLink); }
public async Task <bool> Handle(NewVideoRequest request, IOutputPort <NewVideoResponse> outputPort) { if (_userRepository.FindById(request.UserId) == null) { outputPort.Handle(new NewVideoResponse(new[] { new Error(404, "user not found") })); return(false); } if (_channelRepository.FindByUserId(request.UserId) == null) { outputPort.Handle(new NewVideoResponse(new[] { new Error(404, "you must have to create channel") })); return(false); } UploadedFileDto videoInfo = await _uploadService.UploadFile(request.VideoFile, request.WebRootPath); UploadedFileDto previewInfo = await _uploadService.UploadFile(request.VideoPreview, request.WebRootPath); UploadedFileDto uploadedVideo = _uploadedFileRepository.Create(videoInfo); UploadedFileDto uploadedPreview = _uploadedFileRepository.Create(previewInfo); previewInfo.Id = uploadedPreview.Id; ImageDto videoPreview = _imageRepository.Create(new ImageDto() { UserId = request.UserId }, request.WebRootPath, previewInfo); var video = new VideoDto() { Description = request.Description, Name = request.Name, Views = 0, Likes = 0, Dislikes = 0, PreviewImageId = videoPreview.Id, UserId = request.UserId, UploadedFileId = uploadedVideo.Id, }; VideoDto createdVideo = _videoRepository.Create(video); outputPort.Handle(new NewVideoResponse(createdVideo)); return(true); }
public IActionResult UploadCSV([FromForm] UploadedFileDto uploadedFile) { if (uploadedFile != null) { var extractList = _csvReaderRepo.ExtractCsv(uploadedFile); // map default values to mandatory properties var mappedRecord = _autoMapper.Map <List <ReturnUploadedFileDto>, List <ReturnUploadedFileDto> > (extractList); // filter out records with duplicate user id var proceesedRecords = mappedRecord.GroupBy(x => x.UserId).Select(y => y.First()).Where(r => r.Name != ""); // filter record if it does not have name var rejectedRecords = mappedRecord.Where(r => r.Name == ""); var objectToReturn = new MappedFiledAttribute { lstProcessedRecords = proceesedRecords, lstRejectedRecords = rejectedRecords }; return(Ok(objectToReturn)); } return(BadRequest("Problem in Uploading File")); }
private async Task <int> AddFileDetailsAsync(string name, string description, long size) { try { var fileRecord = new UploadedFileDto { Name = name, Description = description, Size = size }; var fileId = await _baseRepo.AddFileDetailsAsync(fileRecord); return(fileId); } catch (Exception ex) { _logger.LogException(ex, null); return(-1); } }
public UploadImageCommand(UploadedFileDto image) { Image = image; }