protected override async Task Handle(AddCategoryCommand request, CancellationToken cancellationToken) { var category = CategoryMapper.FromAddCategoryToCategory(request); category.Image = await imageUploadService.UploadImage(request.Cover); dbContext.Categories.Add(category); await dbContext.SaveChangesAsync(); }
protected override async Task Handle(AddAuctionCommand request, CancellationToken cancellationToken) { var imageId = await imageUploadService.UploadImage(request.Cover); var auction = AuctionMapper.FromAuctionCommandToAuction(request, null); auction.Image = imageId; dbContext.Auctions.Add(auction); await dbContext.SaveChangesAsync(); }
public async Task <IActionResult> Post(List <IFormFile> files) { var size = files.Sum(f => f.Length); // full path to file in temp location var filePath = Path.GetTempFileName(); foreach (var formFile in files) { if (formFile.Length > 0) { await _imageUploadService.UploadImage(formFile.FileName, formFile.OpenReadStream()); } } // process uploaded files // Don't rely on or trust the FileName property without validation. return(Ok(new { count = files.Count, size, filePath })); }
private async Task <ActionResult <ImageInfo> > UploadImage(Stream imageStream, string partitionKey) { var uploadImageResult = await _imageUploadService.UploadImage(imageStream, partitionKey); //Once the image file and metadata object are saved, there is time to send a new message to the event bus topic //If the program fails at this stage, this message is not sent and therefore thumbnails are not generated for the image. //Such cases are handled when requesting an image metadata object later by resending this event again. await _eventBus.Publish(_topicsConfiguration.Value.UploadedImagesTopicName, new OriginalImageUploadedIntegrationEvent { ImageId = uploadImageResult.Id, PartitionKey = partitionKey }); return(Ok(_mapper.Map <ImageInfo>(uploadImageResult))); }
public async Task <IActionResult> Upload(IFormFile formImage) { var imageName = formImage.FileName; var stream = formImage.OpenReadStream(); var uri = await imageUploadService.UploadImage(imageName, stream); var image = new Image { FileName = imageName, Size = formImage.Length, Url = uri.ToString() }; await imageService.SaveImage(image); await messageQueueService.EnqueueMessage(image); return(RedirectToAction(nameof(Index))); }
protected override async Task Handle(UpdateCategoryCommand request, CancellationToken cancellationToken) { var categoryToUpdate = dbContext.Categories .FirstOrDefault(a => a.Id == request.Id); if (categoryToUpdate == null) { throw new BusinessLogicException($"Category {request.Id} doesn't exist"); } categoryToUpdate.Name = request.Name; if (request.Cover != null) { categoryToUpdate.Image = await imageUploadService.UploadImage(request.Cover); } await dbContext.SaveChangesAsync(); }
protected override async Task Handle(UpdateAuctionCommand request, CancellationToken cancellationToken) { var auctionToUpdate = dbContext.Auctions .Include(x => x.Categories) .FirstOrDefault(a => a.Id == request.Id); if (auctionToUpdate == null) { throw new BusinessLogicException($"Auction {request.Id} doesn't exist"); } auctionToUpdate = AuctionMapper.FromAuctionCommandToAuction(request, auctionToUpdate); if (request.Cover != null) { auctionToUpdate.Image = await imageUploadService.UploadImage(request.Cover); } auctionToUpdate.Title = request.Title; auctionToUpdate.ShortDescription = request.ShortDescription; auctionToUpdate.Description = request.Description; auctionToUpdate.Dotpay = request.Dotpay; auctionToUpdate.SiepomagaLink = request.SiepomagaLink == "null" ? null : request.SiepomagaLink; auctionToUpdate.Paypall = request.Paypall; auctionToUpdate.Categories = request.Categories?.Select(x => new AuctionCategory() { CategoryId = x }).ToList(); auctionToUpdate.Account = request.Account; auctionToUpdate.DateFrom = request.DateFrom ?? DateTime.Now; auctionToUpdate.DateTo = request.DateTo ?? DateTime.Now.AddYears(100); auctionToUpdate.AddressFrom = request.AddressTo; auctionToUpdate.ContactNumber = request.ContactNumber; await dbContext.SaveChangesAsync(); }
public async Task <string> Post([FromForm(Name = "file")] IFormFile file) { return(await _uploadService.UploadImage(file)); }